02-阶乘约数
19103315-王浩然
问题描述
定义阶乘 n! = 1 × 2 × 3 × ··· × n。
请问 100! (100 的阶乘)有多少个约数。
答案提交
这是一道结果填空的题,你只需要算出结果后提交即可。
本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。
思路:需要先知道https://www.acwing.com/solution/content/22884/约束个数的公式。100!= 1X2X3…X100,统计出2到100各用了多少次,利用公式即可求出。
public class code02_FactorialDivisor {
public static void main(String[] args) {
int[] arr = new int[101];
for(int i=2;i< arr.length;i++){
int temp = i;
for (int j=2;j<=temp/j;j++){
while(temp%j==0){
arr[j]++; //找出每个数的需要用几次
temp /= j;
}
}
arr[temp]++;//剩下的temp 使用一次
}
long res = 1;
for(int k = 2;k<arr.length;k++){
if(arr[k]!=0){
res *=(arr[k]+1);
}
}
System.out.println(res);
}
}
运行结果
39001250856960000