2020年第十一届蓝桥杯决赛JAVA B C题"阶乘约数"
问题描述
定义阶乘 n ! = 1 × 2 × 3 × ⋅ ⋅ ⋅ × n 。
请问 100 ! 100的阶乘)有多少个约数。
答案提交
这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。
解析:
数论知识:
这里只用到了第一,点,那么只需要求出n以内的所有质数再求它们的个数即可。这里采用线性筛的方法求质数。
筛质数的方法有许多,这里就不展开介绍了,不理解代码也没关系,记住模板就行。
public class C {
static int N = 100;
static int[] p = new int[101];
static int[] f = new int[101];
static long sum = 1;
static int cnt = 0;
public static void main(String[] args) {
for(int i=2;i<100;i++) {
if(f[i]==0) p[cnt++]=i;
for(int j=0;j<cnt&&p[j]*i<=100;j++) {
f[i*p[j]]=1;
if(i%p[j]==0) break;
}
}
for(int i=0;i<cnt;i++) {
long temp = 0;
long now = p[i];
for(int j=N;j>0;j/=now) temp+=j/now;
sum*=(temp+1);
}
System.out.println(sum);//39001250856960000
}
}