统计
  • 建站日期:2019-12-01
  • 文章总数:1668 篇
  • 评论总数:1796 条
  • 分类总数:20 个
  • 最后更新:4月23日
文章 未分类

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

程序员阿鑫
首页 未分类 正文
官方推荐


Java蓝桥杯国赛第十一届C组试题D:阶乘约数
-程序员阿鑫-带你一起秃头
-第1
张图片

#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 <stdio.h>
#include <string.h>

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:阶乘约数》的全部内容,

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

版权说明
文章采用: 《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权。
版权声明:未标注转载均为本站原创,转载时请以链接形式注明文章出处。如有侵权、不妥之处,请联系站长删除。敬请谅解!

-- 展开阅读全文 --
这篇文章最后更新于2020-12-28,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!
Java 蓝桥杯 国赛 第十一届 C组 试题E:本质上升序列
« 上一篇
Java 蓝桥杯 国赛 第十一届 C组 试题C: 扩散
下一篇 »

发表评论

已有 1 条评论

  1. 万事可乐 Lv.1

    说道:大佬,为什么最后还要res<<=1啊?

HI ! 请登录
注册会员,享受下载全站资源特权。
登陆
上号,带你一起秃头!

时间计时器

热门文章

1
卡QQ永久大会员方法
2
分享个最新免费Q绑查询接口
3
抖音无限礼物模拟小工具分享

最新文章

标签