33 lines
699 B
Java
33 lines
699 B
Java
package LanQiaoOJ;
|
||
|
||
import java.util.Scanner;
|
||
//算术基本定理,又称为正整数的唯一分解定理,即:
|
||
//每个大于1的自然数,若不是本身就是质数,就是可写为2个以上的质数的积
|
||
public class 质因数个数2 {
|
||
|
||
public static void main(String[] args) {
|
||
Scanner sc=new Scanner(System.in);
|
||
long n=sc.nextLong();
|
||
int count=0;
|
||
|
||
//不需要遍历到n,任何一个数的质因数的质因子大于根号n的要么没有,要么只有1个
|
||
for(long i=2;i<n/i;i++) {
|
||
if(n%i==0) {
|
||
count++;
|
||
int ans=0;
|
||
//用来求系数
|
||
while(n%i==0) {
|
||
ans++;
|
||
n/=i;
|
||
}
|
||
System.out.println(i+" "+ans);
|
||
}
|
||
}
|
||
if(n>1) {
|
||
System.out.println(n+" "+1);
|
||
count++;
|
||
}
|
||
System.out.println(count);
|
||
}
|
||
}
|