求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. 第二节:用PE安装Windows系统

    用PE安装Windows系统 认识PE系统 Windows Preinstallation Environment(Windows PE),Windows预安装环境,是带有有限服务的最小Win32子系 ...

  2. 使用Fiddler进行APP弱网测试

    一.安装Fiddler 网上说要先安装.NET Framwork4,应该是由于本机已装,所以在安装Fiddler时并没有相关提示. Fiddler安装包:https://www.telerik.com ...

  3. 15-RUN vs CMD vs ENTRYPOINT

    RUN.CMD 和 ENTRYPOINT 这三个 Dockerfile 指令看上去很类似,很容易混淆.本节将通过实践详细讨论它们的区别. 简单的说: RUN 执行命令并创建新的镜像层,RUN 经常用于 ...

  4. 执行caffe的draw_net.py出现“GraphViz's executable "dot" not found”的解决方法

    控制台输入如下指令画网络图: python ../../../python/draw_net.py train.prototxt train.png --rankdir=TB (Top-Bottom形 ...

  5. UGUI实现不规则区域点击响应

    UGUI实现不规则区域点击响应 前言 大家吼啊!最近工作上事情特别多,没怎么打理博客.今天无意打开cnblog才想起该写点东西了.今天给大家讲一个Unity中不规则区域点击响应的实现方法,使用UGUI ...

  6. d-ary heap实现一个快速的优先级队列(C#)

    d-ary heap简介: d-ary heap 是泛化版本的binary heap(d=2),d-ary heap每个非叶子节点最多有d个孩子结点. d-ary heap拥有如下属性: 类似comp ...

  7. Mysql行转列的简单应用

    最近在复习过程中愈发觉得,有些东西久了不用,真的会忘~——~. 将上面的表格转换为下面的表格 我拼sql拼了好久还是没弄出来,还是偶然看到我以前的笔记,才想起有行转列这样的操作(太久没有写过复杂点的s ...

  8. 电梯调度 结对项目开发(郭林林&胡潇丹)

    (一)需求分析: 上升,下降,开门,关门: 超过负载以后发出警报,下去乘客: 电梯出现故障后,电梯停止: 电梯楼层的输入框可以同时指定所要到的楼层,也是楼层的显示框: 电梯同时记录多个状态,即为到达多 ...

  9. 06-matplotlib-饼状图

    import numpy as np import matplotlib.pyplot as plt ''' 饼状图显示一个数据系列中各项总和的比例: 饼状图中的数据点显示为整个饼状图的百分比: 如: ...

  10. Qt tableWidget 空单元格 获取选中行行号

    bool focus = tableWidget->isItemSelected(tableWidget->currentItem()); // 判断是否选中一行 Int row1 = t ...