第十五届蓝桥杯Python大学B组国赛题解系列--第二题

第十五届蓝桥杯Python大学B组国赛题解系列–第二题

题目复现

在这里插入图片描述

解题思路

本题无法用暴力的方法求解。因为用暴力的方法的遍历范围是 [ 1 , ⌊ 2024 ! 61 ⌋ ] [1,\lfloor\sqrt[61]{2024!}\rfloor] [1,612024! ⌋],而 ⌊ 2024 ! 61 ⌋ ] \lfloor\sqrt[61]{2024!}\rfloor] 612024! ⌋]是一个 1 0 94 10^{94} 1094的数就算遍历到地球毁灭,也遍历不出来。那么我们只有用数论方法来求解了.

数论解法
根据唯一分解定理,我们可将 2024!分解为:
2 2017 × 3 1006 × 5 503 × 7 335 × ⋯ 2^{2017}\times3^{1006}\times5^{503}\times7^{335}\times\cdots 22017×31006×5503×7335×
同样的,我们可将 n n n分解为:
2 a × 3 b × 5 c × 7 d × ⋯ 2^a\times3^b\times5^c\times7^d\times\cdots 2a×3b×5c×7d×
如此, n 61 n^{61} n61即可表示为:
2 61 ⋅ a × 3 61 ⋅ b × 5 61 ⋅ c × 7 61 ⋅ d × ⋯ 2^{61\cdot a}\times3^{61\cdot b}\times5^{61\cdot c}\times7^{61\cdot d}\times\cdots 261a×361b×561c×761d×
由于 n 61 ∣ 2024 ! n^{61}\mid2024! n612024!,因此 n 61 n^{61} n61为 2024! 的因子,即:
61 ⋅ a ≤ 2017 61 ⋅ b ≤ 1006 61 ⋅ c ≤ 503 61 ⋅ d ≤ 335 ⋯ 61\cdot a\leq2017\\61\cdot b\leq1006\\61\cdot c\leq503\\61\cdot d\leq335\\\cdots 61a201761b100661c50361d335
依此可得: a a a的取值为 [ 0 , ⌊ 2017 61 ⌋ ] , b [0,\lfloor\frac{2017}{61}\rfloor],b [0,612017⌋],b的取值为 [ 0 , ⌊ 1006 61 ⌋ ] , … [0,\lfloor\frac{1006}{61}\rfloor],\ldots [0,611006⌋],
满足条件的 n n n的个数可表示为:
( ⌊ 2017 61 ⌋ + 1 ) × ( ⌊ 1006 61 ⌋ + 1 ) × ⋯ (\lfloor\frac{2017}{61}\rfloor+1)\times(\lfloor\frac{1006}{61}\rfloor+1)\times\cdots (⌊612017+1)×(⌊611006+1)×

题解

通过以上的数论方法分析,这个题就变的简单了,那么我们现在就用编程来求解吧。

# 质素筛[埃式筛法]函数
def zhishu_plus(n):
    vis=[0]*(n+1)
    prime=[]
    for i in range(2,n+1):
        if vis[i]==0:
            prime.append(i)
        for j in range(i+i,n+1,i):
            vis[j]=1
    return prime
    
# (1)用质数筛函数求2024以内的质数,存储到一个数组中
aa=zhishu_plus(2024)

# (2)计算2024!
ans=1
for i in range(1,2025):
    ans*=i

# (3)构建2024!的质因数数量数组
asum=[0]*len(aa)

# (4)计数质因数数量
ans1=ans
index=0
while index<=len(aa)-1:
    if ans1%aa[index]==0:
        asum[index]+=1
        ans1=ans1//aa[index]
    else:
        index+=1
# print(asum)

# (5)用本题对应排序组合公式计算n的个数
res=1
for i in range(len(asum)):
    res*=(int(asum[i]/61)+1)
print(res)

用这个代码跑出来的结果就是最终答案,放心使用,虽然代码是我自己编写的,但是答案已经通过蓝桥云课官方视频验证过了。

如果您觉得对您有帮助,就请给我点个赞吧!Thanks♪(・ω・)ノ

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值