1059 Prime Factors (25 分)
Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p1k1×p2k2×⋯×pmk**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 =
p1^
k1*
p2^
k2*
…*
p**m^
k**m, where p**i‘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 |
作者: HE, Qinming
单位: 浙江大学
时间限制: 200 ms
内存限制: 64 MB
代码长度限制: 16 KB
题目大意
将一个数分解成其质因数的乘积
分析
用map<int,int>
存放质数及出现的次数。首先计算根号n内的质数,初始化为0。然后当n不等于1且n不为质数时循环,找根号n内的质因数。找到后出现次数++,并让n除等于此数。最后遍历map输出即可。
代码
1 |
|