LightOJ 1090 Trailing Zeroes (II)
来源:互联网 发布:gif屏幕录像软件 编辑:程序博客网 时间:2024/06/16 05:18
题目分析
这道题的意思就是让你求
Crn∗pq 中末尾0的个数,那么很明显就是让你求算得的10的个数,而10能转化为2*5,那么我们就可以打表求106 范围内每个数可以表示成2和5分别的个数。
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 1e6+100;#define PII pair <int, int>#define LLL long longPII p[maxn], ans[maxn];void init(){ for(int i = 1; i < maxn; i++){ int temp = i; p[i].first = p[i].second = 0; while(temp%2 == 0){ temp /= 2; p[i].first++; } while(temp%5 == 0){ temp /= 5; p[i].second++; } } ans[1] = p[1]; for(int i = 2; i < maxn; i++){ ans[i].first = ans[i-1].first + p[i].first; ans[i].second = ans[i-1].second + p[i].second; }}int main(){ init(); int T, n, r, P, q; scanf("%d", &T); for(int kase = 1; kase <= T; kase++){ scanf("%d%d%d%d", &n, &r, &P, &q); int x = ans[n].first, y = ans[n].second; x -= ans[r].first; y -= ans[r].second; x -= ans[n-r].first; y -= ans[n-r].second; x += p[P].first*q; y += p[P].second*q; printf("Case %d: %d\n", kase, min(x, y)); } return 0;}
0 0
- lightoj 1090 - Trailing Zeroes (II)
- LightOJ 1090 Trailing Zeroes (II)
- LightOJ 1090Trailing Zeroes (II) [分解]【数论】
- lightoj Trailing Zeroes (III)
- LightOJ 1138 Trailing Zeroes
- Trailing Zeroes (III) LightOJ
- LightOJ 1090 - Trailing Zeroes (II) (求式子结果0的个数)
- Light OJ 1090 - Trailing Zeroes (II)
- light oj 1090 Trailing Zeroes (II)
- LightOJ 1028 Trailing Zeroes (I)
- lightOJ 1138 Trailing Zeroes (III)
- LightOJ 1138 Trailing Zeroes (III)
- LightOJ 1138Trailing Zeroes (III)
- LightOJ 1028 Trailing Zeroes (I)
- LightOJ 1138 Trailing Zeroes (III)
- LightOJ - 1138 Trailing Zeroes (III)
- lightoj-【1138 - Trailing Zeroes (III)】
- 【LightOJ 1138 Trailing Zeroes (III)】
- 深入理解Java之线程池
- jasperReport+struts2+jatoolsPrinter打印
- 负载均衡一致性hash算法
- c++之简单的推箱子游戏
- ubuntu ping不通网时的设置
- LightOJ 1090 Trailing Zeroes (II)
- SqlServer--bat批处理执行sql语句1-osql
- Design Patterns in Android:单例模式
- three
- frameMarker之TemplateDirectiveModel
- Java修饰符小结
- JZOJ 3808 【NOIP2014模拟8.25】道路值守
- Design Patterns in Android:模板方法模式
- Jsp乱码的解决方法