PAT1059. Prime Factors

题目

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×⋯×pmkm.

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**pm^km, where pi’s are prime factors of N in increasing order, and the exponent ki is the number of pi – hence when there is only one pi, ki is 1 and must NOT be printed out.

Sample Input:

Sample Output:

分析

• 对于因子查找的结论： 如果n存在[1,n]的因子，则在sqrt(n)的两边对称存在
• 对于质因数有一个结论：对一个正整数n来说，如果它存在[2,n]范围内的质因子，要么这些质因子全部小于等于sqrt(n)，要么只存在一个位于[sqrt(n),n]的质因子。