LanQiaoTestCodes/质因数个数2.java

33 lines
699 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}