您的位置:首页 > 其它

[洛谷P3927]一道中档题

2017-10-14 20:29 246 查看
题目←

洛谷月赛,qbxt考试的时候划水去做了T1

当时没看见多组数据悲惨的wa了

然而题目现在改了?翻提交记录时惊喜的发现当年的0分变成了70?

70分是被int坑了……答案是在longlong范围里的

思路:

k进制下末尾0的个数即为该数最大可整除的k的次方数

将k质因数分解,统计k的每个质因子在n!中最少被整除的次数

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define LL long long
using namespace std;
const int MAXN = 20000 + 50;
LL prime[MAXN],gs[MAXN];
int cnt = 0;
void solve1(LL x)
{
for(LL i = 2;i <= x;i ++)
{
if(x%i == 0)
{
prime[++ cnt] = i;
while(x%i == 0)
{
x /= i;
gs[cnt] ++;
}
}
}
}
LL ans;
void solve2(LL x)
{
for(int i = 1;i <= cnt;i ++)
{
LL tot = 0,temp = x;
while(temp)
{
tot += temp/prime[i];
temp /= prime[i];
}
if(!ans)ans = tot/gs[i];
else ans = min(ans,tot/gs[i]);
}
}
int main()
{
LL n,m;
scanf("%lld%lld",&n,&m);
solve1(m);
solve2(n);
printf("%lld",ans);
}


注意答案范围

一开始三个点就是因为把ans赋成了1061109567wa掉的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: