求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. jmeter—操作数据库

    添加JDBC Request,添加需要执行的sql语句 在这个界面需要配置Variabke Name,内容要与上表中的Name值相同:数据库的用户名.密码.URL.驱动这些基本信息要在这里配置:其他选 ...

  2. Java字符串连接操作的性能问题

    首先,看一段实验程序: package com.test; class StringTest { public static void main(String[] args) { long start ...

  3. ROS (Robot Operating System) 相关资料与文档

    本博文持续更新…… ROS学习与实践保护很多资料,最权威的当然是官网: www.ros.org 当然也有很多其他博文,尤其是中文文档有助于理解.2017推出一篇新博文,概况的资料较全. http:// ...

  4. ossec兼容的操作系统

    OSSEC兼容以下操作系统和日志格式 操作系统 以下操作系统可安装OSSEC代理 l  GNU/Linux (all distributions, including RHEL, Ubuntu, Sl ...

  5. 通过NPM快速发布你的NodeJS模块(组件包)

    1.更新 NPM - [ npm install -g npm | 该步骤可选:最好使用新版本] 楼主当前版本号 2.6.1 ,如果更新报错,可以尝试 国内淘宝镜像 $ npm -v 2.6.1 // ...

  6. 事后分析报告(Postmortem Report)要求

    在得到M1 团队成绩之后, 每个团队都需要编写一个事后分析报告,对于团队在M1阶段的工作做一个总结. 请根据下面的模板总结并发表博客: http://www.cnblogs.com/xinz/arch ...

  7. Scrum Meeting 9 -2014.11.15

    项目开发测试要进入尾声了.大家加把劲,这周末能整合完成就最好了. 服务器方面已经能运行我们的程序了.还需要研究如何与其他两小组整合. Member Today’s task Next task 林豪森 ...

  8. MathExam小学一二年级计算题生成器V1.0

    MathExam小学一二年级计算题生成器v1.0 一.预估与实际 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning ...

  9. web12 使用map型的request、session、application

    电影网站:www.aikan66.com 项目网站:www.aikan66.com 游戏网站:www.aikan66.com 图片网站:www.aikan66.com 书籍网站:www.aikan66 ...

  10. springmvc 映射重复

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springfr ...