整數因子分解問題 分治

2021-09-19 07:32:50 字數 1129 閱讀 5810

time limit: 1000 ms memory limit: 65536 kib

submit

statistic

problem description

大於1的正整數n可以分解為:n=x1*x2*…*xm。例如,當n=12 時,共有8 種不同的分解式: 

12=12; 

12=6*2; 

12=4*3; 

12=3*4; 

12=3*2*2; 

12=2*6; 

12=2*3*2; 

12=2*2*3。

對於給定的正整數n,計算n共有多少種不同的分解式。

input

輸入資料只有一行,有1個正整數n (1≤n≤2000000000)。

output

將計算出的不同的分解式數輸出。

sample input

12
sample output

8
解題思路:

如果需要分解的數字為1,那麼就只有一種分解方式;

如果需要分解的數字不等於1,需要考慮待分解數字的所有的因子,比如題目中的12,除了1之外,需要考慮2*x  3*x 4*x  6*x 12*x得到的因式的數量,將這些因式求和即可得到12的因子分解的數量,可以遞迴的去求解,但這種遞迴的方式可能超時,可以考慮下面的做法。

#include using namespace std;

int solve(int n)

return count;

}int main()

return 0;

}

另一種方法,利用動歸的思想,將一些計算值儲存下來,避免了重複計算 

#include #include #include using namespace std;

int a[10000], dp[10000], k = 0;

void ul(int num)

} if (i*i == num) }

void solve(int n)

} }}int main()

return 0;

}

整數因子分解問題

problem description 大於1的正整數n可以分解為 n x1 x2 xm。例如,當n 12 時,共有8 種不同的分解式 12 12 12 6 2 12 4 3 12 3 4 12 3 2 2 12 2 6 12 2 3 2 12 2 2 3。對於給定的正整數n,計算n共有多少種不同的...

整數因子分解問題

home contests experiments problems status ranklist logout 整數因子分解問題 time limit 1000 ms memory limit 65536 kib submit statistic problem description 大於1的...

整數因子分解問題

time limit 1000 ms memory limit 65536 kib submit statistic problem description 大於1的正整數n可以分解為 n x1 x2 xm。例如,當n 12 時,共有8 種不同的分解式 12 12 12 6 2 12 4 3 12 ...