sgu154

来源:互联网 发布:lol个人数据carry查询 编辑:程序博客网 时间:2024/06/05 04:11

链接:http://acm.sgu.ru/problem.php?contest=0&problem=154


/***************************************************************Author: LuckyQueentime: 2011.12.05    20:15Problem solution: 简单的找规律加二分。注意到阶乘后面的0只能由                  2*5得到,而2有很多,一次只要找出阶乘的结果能                  被5整除几次,不二分会超时 悲催的不会写二分,                  抄袭了K哥的代码***************************************************************/#include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>#include <cmath>using namespace std;int cal(int n){int num = 0;while (n){n /= 5;num += n;}return num;}int main(){int n, l, r, mid;bool flag;while (~scanf("%d", &n)){l = 1, r = 400000100;flag = false;while (l < r){mid = (l+r) / 2;int tp = cal(mid);if (tp > n)r = mid;else if (tp == n)r = mid, flag = true;else l = mid + 1;}if (flag)printf("%d\n", r);else puts("No solution");}return 0;}



LuckyQueen is the best!!!

原创粉丝点击