求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(预处理+前缀和)的更多相关文章

  1. Trailing Zeroes (III)(lightoj 二分好题)

    1138 - Trailing Zeroes (III)   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit:  ...

  2. LightOj 1090 - Trailing Zeroes (II)---求末尾0的个数

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1090 题意:给你四个数 n, r, p, q 求C(n, r) * p^q的结果中末尾 ...

  3. Lightoj 1090 - Trailing Zeroes (II)

    题目连接: http://www.lightoj.com/volume_showproblem.php?problem=1090 题目大意: 给出n,r,p,q四个数字1<=n,r,p,q< ...

  4. 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 ...

  5. 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! ...

  6. Trailing Zeroes (I) LightOJ - 1028

    题意就是给你一个数让你找它的正因子个数(包括自身,不包括1),这个地方用到一个公式,如果不用的话按正常思路来写会TL什么的反正就是不容易写对. 求任意一个大于1的整数的正因子个数 首先任意一个数n,n ...

  7. Trailing Zeroes (I) LightOJ - 1028(求因子个数)

    题意: 给出一个N 求N有多少个别的进制的数有后导零 解析: 对于一个别的进制的数要转化为10进制 (我们暂且只分析二进制就好啦) An * 2^(n-1) + An-1 * 2^(n-2) + `` ...

  8. Trailing Zeroes (III) LightOJ - 1138 不找规律-理智推断-二分

    其实有几个尾零代表10的几次方但是10=2*510^n=2^n*5^n2增长的远比5快,所以只用考虑N!中有几个5就行了 代码看别人的: https://blog.csdn.net/qq_422797 ...

  9. LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)

    http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS     M ...

随机推荐

  1. X5webview去掉分享功能和缓存功能

    x5webview比原生的webview适配更好,加载更快,对音视频的兼容性更好,具备独特的优势 1) 速度快:相比系统webview的网页打开速度有30+%的提升: 2) 省流量:使用云端优化技术使 ...

  2. Linux下的消息队列

    文章链接:https://blog.csdn.net/qq_38646470/article/details/80169406

  3. php_package v2.7发布了 宋正河作品

    php_package 是一个面向过程的底层开发框架 http://download.csdn.net/download/songzhengdong82/4974123 欢迎大家下载

  4. 《Postgre SQL 即学即用 (第三版)》 分享 pdf下载

    链接:https://pan.baidu.com/s/1akR33VqEkt99UqJUfiy2OA提取码:3p1k

  5. Unity2018 Shader Graph 实验室

    Unity2018 Shader Graph 实验室 Shader Shader Graph Unity  Tips: -- 在shader forge和amplyfy Shader节点图形化shad ...

  6. Netty源码分析第1章(Netty启动流程)---->第2节: NioServerSocketChannel的创建

    Netty源码分析第一章:  Server启动流程 第二节:NioServerSocketChannel的创建 我们如果熟悉Nio, 则对channel的概念则不会陌生, channel在相当于一个通 ...

  7. Windows ,获取硬盘物理序列号(VC++)

    #include <windows.h> BOOL GetHDID(PCHAR pIDBufer) {     HANDLE hDevice=NULL;    hDevice=::Crea ...

  8. python - 定时清理ES 索引

    只保留三天 #!/usr/bin/env python3 # -*- coding:utf-8 -*- import os import datetime # 时间转化为字符串 now_time = ...

  9. 机器学习之k-最近邻(kNN)算法

    一.kNN(k-nearest neighbor)算法原理 事物都遵循物以类聚的思想,即有相同特性的事物在特征空间分布上会靠得更近,所以kNN的思路是:一个样本在特征空间中k个靠的最近的样本中,大多数 ...

  10. IDEA 2018 最新激活码 License server

    IDEA 2018 最新激活码 License server 总会有一个属于适合你的!嘻嘻 http://hb5.s.osidea.cc:1017 http://idea.youbbs.org htt ...