Trailing Zeroes (II) LightOJ - 1090(预处理+前缀和)
求C(n,r)*p^q的后缀零
考虑一下 是不是就是求 10^k*m 的k的最大值
而10又是由2 和 5 组成 所以即是求 2^k1 * 5^k2 * m1 中k1和k2小的那一个数 短板效应嘛。。
预处理每个 1 - 1e6 的每个数字的对2分解,对5分解的次数 然后还要保存下前缀和 作为 n的阶乘中分别包含的次数
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = 1e6 + , INF = 0x7fffffff;
int sum1[maxn], sum2[maxn], a[maxn], b[maxn]; int count_(int a, int b)
{
int cnt = ;
while(a % b == )
{
cnt++;
a/=b;
}
return cnt;
} int main()
{
for(int i=; i<maxn; i++)
{
a[i] = count_(i, );
b[i] = count_(i, );
sum1[i] += sum1[i-] + a[i];
sum2[i] += sum2[i-] + b[i];
}
int n, r, p, q, T, kase = ;
cin>> T;
while(T--)
{
cin>> n >> r >> p >> q;
int c = sum1[n] - sum1[r] - sum1[n-r];
int d = sum2[n] - sum2[r] - sum2[n-r];
int e = a[p] * q;
int f = b[p] * q;
cout<< "Case "<< ++kase <<": " <<min(c+e, d+f) <<endl;
} return ;
}
Trailing Zeroes (II) LightOJ - 1090(预处理+前缀和)的更多相关文章
- Trailing Zeroes (III)(lightoj 二分好题)
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- LightOj 1090 - Trailing Zeroes (II)---求末尾0的个数
题目链接:http://lightoj.com/volume_showproblem.php?problem=1090 题意:给你四个数 n, r, p, q 求C(n, r) * p^q的结果中末尾 ...
- Lightoj 1090 - Trailing Zeroes (II)
题目连接: http://www.lightoj.com/volume_showproblem.php?problem=1090 题目大意: 给出n,r,p,q四个数字1<=n,r,p,q< ...
- Trailing Zeroes (III) LightOJ - 1138(二分)
You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in d ...
- Trailing Zeroes (III) LightOJ - 1138 二分+找规律
Time Limit: 2 second(s) Memory Limit: 32 MB You task is to find minimal natural number N, so that N! ...
- Trailing Zeroes (I) LightOJ - 1028
题意就是给你一个数让你找它的正因子个数(包括自身,不包括1),这个地方用到一个公式,如果不用的话按正常思路来写会TL什么的反正就是不容易写对. 求任意一个大于1的整数的正因子个数 首先任意一个数n,n ...
- Trailing Zeroes (I) LightOJ - 1028(求因子个数)
题意: 给出一个N 求N有多少个别的进制的数有后导零 解析: 对于一个别的进制的数要转化为10进制 (我们暂且只分析二进制就好啦) An * 2^(n-1) + An-1 * 2^(n-2) + `` ...
- Trailing Zeroes (III) LightOJ - 1138 不找规律-理智推断-二分
其实有几个尾零代表10的几次方但是10=2*510^n=2^n*5^n2增长的远比5快,所以只用考虑N!中有几个5就行了 代码看别人的: https://blog.csdn.net/qq_422797 ...
- LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)
http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS M ...
随机推荐
- python数据分析处理库-Pandas
1.读取数据 import pandas food_info = pandas.read_csv("food_info.csv") print(type(food_info)) # ...
- CAN总线波形中ACK位电平为什么会偏高?
摘要:如果CAN总线中有多个节点,在某一点测试CAN总线的波形(CANH和CANL之间)时,会发现在一帧数据的末尾ACK位的差分电平会偏高.网上有关于此问题的一些描述和解释,但孔丙火(微信公众号:孔丙 ...
- Allegro16.6结构文件dxf文件的输出与导入——凡亿PCB
在pcb设计中,结构文件的导入是不可或缺的一个步骤,使用allegro16.6软件操作如下. 一.结构文件的输出 1.在allegro16.6将pcb颜色显示设置成只剩需要导出的结构. 2.看到all ...
- 树莓派3b添加python时间同步脚本
树莓派没有电池,因此断电后系统时间会停止,直到你开机后又继续计时,所以会造成系统时间和实际时间有很大的误差. 因为项目需要用到本地时间,精度要求不高不想折腾(如果需要高精度,需要安装ntp),所以考虑 ...
- Loadrunner 性能指标
https://wenku.baidu.com/view/bf395a1db7360b4c2e3f64ca.html 希望能记住最好记住吧,这个很重要的. qq,979506750多交流
- Gitlab CI-3.遇到的问题
五.遇到的问题 1. cannot validate certificate for x.x.x.x because it doesn't contain any IP SANs 报错信息:ERROR ...
- Python字典 (dict)
作者博文地址:http://www.cnblogs.com/spiritman/ 字典是Python语言中唯一的映射类型.字典对象是可变的,它是一个容器类型,支持异构.任意嵌套. 创建字典 语法:{k ...
- 在Gulp中使用BrowserSync
博客已迁移至http://zlwis.me. 很早就听说过BrowserSync,也看过一些相关文章,可就是没用过.之前一直在用Gulp开发项目,每次编写完Sass后还要用按F5刷新页面看效果,想想也 ...
- 2018-2019-20172321 《Java软件结构与数据结构》第九周学习总结
2018-2019-20172321 <Java软件结构与数据结构>第九周学习总结 教材学习内容总结 第15章 图 无向图 图由顶点和边组成. 顶点由名字或标号来表示,如:A.B.C.D: ...
- java 1.7 1.8新特性
在JDK1.7的新特性方面主要有下面几方面的增强:1.jdk7语法上1.1二进制变量的表示,支持将整数类型用二进制来表示,用0b开头.1.2 Switch语句支持string类型1.3 Try-wit ...