阶乘 java 蓝桥,Java 蓝桥杯 国赛 第十一届 C组 试题D:阶乘约数

c16e9f5f92678b7ee89dd725a3c28a9f.png

#D 阶乘约数

本题总分:10 分

问题描述

定义阶乘 n ! = 1 × 2 × 3 × ⋅ ⋅ ⋅ × n n! = 1 × 2 × 3 × · · · × nn!=1×2×3×⋅⋅⋅×n。

请问 100 ! 100!100! (100 100100 的阶乘)有多少个约数。

答案提交

这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。39001250856960000

calcCode:import java.math.BigInteger;

public class Test {

public static void main(String[] args) {

BigInteger num = BigInteger.ONE;

for (int i = 1; i <= 100; i++)

num = num.multiply(new BigInteger(String.valueOf(i)));

long res = 1;

for (BigInteger i = new BigInteger("2"); i.multiply(i).compareTo(num) <= 0; i = i.add(BigInteger.ONE)) {

long cnt = 1;

while (num.mod(i).compareTo(BigInteger.ZERO) == 0) {

num = num.divide(i);

cnt++;

}

if (cnt > 1)

res *= cnt;

}

if (num.compareTo(BigInteger.ONE) > 0) res <<= 1;

System.out.println(res);

}

}

算术基本定理求约数个数

再给你们一个模板public class Test {

public static void main(String[] args) { System.out.println(factors(100)); }

static int factors(long n) {

int res = 1, now;

for (int i = 2; i * i <= n; i++) {

now = 1;

while (n % i == 0) {

n /= i;

now++;

}

if (now > 1)

res *= now;

}

return n > 1? res << 1 : res;

}

}

最近在学C,C的标准库中没大整形,所以就变换出了这种写法#include

#include

int main() {

int factor[100];

long long res = 1;

memset(factor, 0x00, sizeof(factor));

for (int i = 100, n = 100; i; n = --i)

for (int k = 2; k <= n; k++)

while (!(n % k)) {

factor[k]++;

n /= k;

}

for (int i = 0; i < 100; i++)

res *= factor[i] + 1;

printf("%lld", res);

}

以上是《Java 蓝桥杯 国赛 第十一届 C组 试题D:阶乘约数》的全部内容,

感谢您对程序员阿鑫博客的支持!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值