Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format $N = p_1^{k_1} times p_2^{k_2} times ⋯ times p_m^{k_m}$.
Input Specification:
Each input file contains one test case which gives a positive integer $N$ in the range of long int.
Output Specification:
Factor N in the format $N = p_1^{k_1} times p_2^{k_2} times ⋯ times p_m^{k_m}$, where pi’s are prime factors of $N$ in increasing order, and the exponent $k_i$ is the number of $p_i$ — hence when there is only one $p_i$, $k_i$ is $1$ and must NOT be printed out.
Sample Input:
1 |
97532468 |
Sample Output:
1 |
97532468=2^2*11*17*101*1291 |
题意:
对数$N$分解质因数
思路:
可以先将素数表打出来,然后逐个进行除并记录个数,直到数$N$为1。这样做虽然$AC$了,但是当$N$为一个很大的素数时,并不会包含在表内。这时候我想到的就是遍历对$N$除去它的因子,直到$N$为质数或1。
代码:
1 |
|
近期评论