[洛谷P3927]一道中档题
2017-10-14 20:29
246 查看
题目←
洛谷月赛,qbxt考试的时候划水去做了T1
当时没看见多组数据悲惨的wa了
然而题目现在改了?翻提交记录时惊喜的发现当年的0分变成了70?
70分是被int坑了……答案是在longlong范围里的
思路:
k进制下末尾0的个数即为该数最大可整除的k的次方数
将k质因数分解,统计k的每个质因子在n!中最少被整除的次数
注意答案范围
一开始三个点就是因为把ans赋成了1061109567wa掉的
洛谷月赛,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掉的
相关文章推荐
- 洛谷P3927 SAC E#1 - 一道中档题 Factorial
- UESTC 1692 这是一道比CCCC简单题更有想象力的中档题 完全背包
- UESTC 1692 这是一道比CCCC简单题更有想象力的中档题
- 洛谷10月月赛R1·浴谷八连测R1·提高组 SAC E#1 -T1 一道中档题 Factorial
- P3927 SAC E#1 - 一道中档题 Factorial
- 洛谷 P3927 SAC E#1 - 一道中档题 Factorial
- 洛谷10月月赛R1·浴谷八连测R1·提高组 SAC E#1 - 一道中档题 Factorial
- 洛谷10月月赛R1T1-SAC E#1 - 一道中档题 Factorial(pollard-rho质因数分解)
- 洛谷10月月赛R1-T1-一道中档题 Factorial
- noip模拟赛 SAC E#1 - 一道中档题 Factorial
- [luogu3927] SAC E#1 - 一道中档题 Factorial
- 【Luogu】P3927 SAC E#1 - 一道中档题 Factorial
- LuoguP3927 SAC E#1 - 一道中档题 Factorial
- 洛谷3927 一道中档题
- 【luogu10月月赛】一道中档题 Factorial(数论)
- LuoguP3927 SAC E#1 - 一道中档题 Factorial 解题报告【唯一分解定理】
- 【多重背包】CDOJ1691 这是一道比CCCC简单题经典的中档题
- SAC E#1 - 一道中档题 Factorial
- 洛谷10月月赛R1·浴谷八连测R1·提高组 一道中档题 Factorial
- 【动态规划】CDOJ1692 这是一道比CCCC简单题更有想象力的中档题