输入包括多组数据。
每组数据仅有一个整数n (2≤n≤100000)。
对应每个整数,输出其因子个数,每个结果占一行。
30<br/>26<br/>20
3<br/>2<br/>2
import java.util.Scanner; import java.util.TreeSet;public class Main { public static void main(String[] args) { Scanner str = new Scanner(System.in); while (str.hasNextInt()){ int n=str.nextInt(); System.out.println(soluation(n)); } } public static int soluation(int n) { TreeSet<Integer> tree = new TreeSet<>(); for (int i = 2; i <= n; i++) { if (n % i == 0) { n = n / i; tree.add(i); i=2; } } int size= tree.size(); return size; } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextInt()) { int n = in.nextInt(); int count = 0; for(int i = 2;i <= Math.sqrt(n);i++){ if(n % i == 0){ while(n % i == 0){ n /= i; } count++; } } if(n != 1){ count++; } System.out.println(count); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextInt()) { int a = in.nextInt(); int a3=0; int a2=0; int a5=0; int aa=0; while(a>1){ if(a%2==0){ a=a/2; a2=1; }else if(a%3==0){ a=a/3; a3=1; }else if(a%5==0){ a=a/5; a5=1; }else{ a=a/a; aa=1; } } int ret=a2+a3+a5+aa; System.out.println(ret); } } }
import java.util.*; public class Main{ public static void main(String[] args){ Scanner s = new Scanner(System.in); while(s.hasNext()){ int n = s.nextInt(); int ret = 0; // 从2到n的平方根开始遍历因子 for(int i = 2; i <= Math.sqrt(n); i++){ // 碰到能整除的因子 if(n % i == 0){ // 不断地除这个因子直到不能整除为止,因子数加一,进入下一次循环 while(n % i == 0){ n = n / i; } ret++; } } // 当循环结束n不为1,即没能整除,说明此时的n也是一个因子 if(n != 1) ret++; System.out.println(ret); } } }