题目链接:http://lightoj.com/volume_showproblem.php?problem=1090

题意:给你四个数 n, r, p, q 求C(n, r) * p^q的结果中末尾0的个数;(1<=n, r, p, q <= 10^6, r ≤ n)

要求末尾0的个数,一定和2和5有关,例如num1 * num2结果中末尾0的个数可以表示成min(num1中2的个数+num2中2的个数, num1中5的个数+num2中5的个数);

对于C(n, r)中0的2的个数可以写成f[n]-f[r]-f[n-r],其中f[i]表示i!中2的个数;打表求出 f 即可

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
typedef long long LL;
#define N 1000001
using namespace std;
const double eps = 1e-; int f[N], g[N]; ///f[i]表示i!中共有多少个2, g[i]表示i!有多少个5; void Init()
{
int x = , y = ;
for(int i=; i<N; i++)
{
int n = i;
while(n% == )
{
x ++;
n /= ;
}
n = i;
while(n% == )
{
y ++;
n /= ;
}
f[i] = x;
g[i] = y;
}
} int main()
{
Init(); int T, t = ;
scanf("%d", &T);
while(T --)
{
int p, q, n, r;
scanf("%d %d %d %d", &n, &r, &p, &q);
int ans1, ans2, ans;
ans1 = f[n]-f[r]-f[n-r] + q*(f[p]-f[p-]);
ans2 = g[n]-g[r]-g[n-r] + q*(g[p]-g[p-]);
ans = min(ans1, ans2);
printf("Case %d: %d\n", t++, ans);
}
return ;
}

LightOj 1090 - Trailing Zeroes (II)---求末尾0的个数的更多相关文章

  1. LightOj 1138 - Trailing Zeroes (III) 阶乘末尾0的个数 & 二分

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题意:给你一个数n,然后找个一个最小的数x,使得x!的末尾有n个0:如果没有输出 ...

  2. Lightoj 1090 - Trailing Zeroes (II)

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

  3. 172. Factorial Trailing Zeroes(阶乘中0的个数 数学题)

    Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explan ...

  4. Java 计算N阶乘末尾0的个数-LeetCode 172 Factorial Trailing Zeroes

    题目 Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in ...

  5. POJ 1401:Factorial 求一个数阶乘的末尾0的个数

    Factorial Time Limit: 1500MS   Memory Limit: 65536K Total Submissions: 15137   Accepted: 9349 Descri ...

  6. Algorithm --> 求阶乘末尾0的个数

    求阶乘末尾0的个数 (1)给定一个整数N,那么N的阶乘N!末尾有多少个0?比如:N=10,N!=3628800,N!的末尾有2个0. (2)求N!的二进制表示中最低位为1的位置. 第一题 考虑哪些数相 ...

  7. 求N的阶乘N!中末尾0的个数

    求N的阶乘N!中末尾0的个数 有道问题是这样的:给定一个正整数N,那么N的阶乘N!末尾中有多少个0呢?例如:N=10,N=3628800,则N!的末尾有两个0:直接上干货,算法思想如下:对于任意一个正 ...

  8. lightoj 1138 - Trailing Zeroes (III)【二分】

    题目链接:http://lightoj.com/volume_showproblem.php? problem=1138 题意:问 N. 末尾 0 的个数为 Q 个的数是什么? 解法:二分枚举N,由于 ...

  9. 牛客小白月赛6 水题 求n!在m进制下末尾0的个数 数论

    链接:https://www.nowcoder.com/acm/contest/135/C来源:牛客网 题目描述 其中,f(1)=1;f(2)=1;Z皇后的方案数:即在Z×Z的棋盘上放置Z个皇后,使其 ...

随机推荐

  1. BZOJ1401 : Hexagon

    这题显然是一个最小斯坦纳树的模型,直接上模板即可,就是正六边形比较恶心. #include<cstdio> #include<cstring> #include<algo ...

  2. 不通过App Store,在iOS设备上直接安装应用程序(转)

    今天在iOS设备上安装天翼云存储app,在safari上直接打开http://cloud.189.cn/wap/index.jsp,点击“点击免费安装”,如下图: 神奇的事情发生了,设备上直接下载ap ...

  3. 【BZOJ】2802: [Poi2012]Warehouse Store(贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2802 自己yy了一下... 每一次如果够那么就买. 如果不够,考虑之前买过的,如果之前买过的比当前花 ...

  4. esper 事件引擎,各种事件类型示例代码

    原创文章 转载请注明出处 package com.hp.iot.engine.esper; import java.util.ArrayList; import java.util.HashMap; ...

  5. 关于sql语句的优化问题

    系统要求进行SQL优化,对效率比较低的SQL进行优化,使其运行效率更高,其中要求对SQL中的部分in/not in修改为exists/not exists 修改方法如下: in的SQL语句 SELEC ...

  6. 给iOS工程增加Daily Build

    给iOS工程增加Daily Build  前言 Daily Build 是一件非常有意义的事情,也是敏捷开发中关于 "持续集成" 的一个实践.Daily Build 对于开发来说有 ...

  7. html标签,格式控制标签,内容容器标签,超链接标签,图片标签,表格

    打开DREAMWEAVER,新建HTML,如下图: body的属性: bgcolor 页面背景色 background  背景壁纸.图片 text  文字颜色 topmargin  上边距 leftm ...

  8. web应用防火墙 – 安全伞18.5.1免费版本发布

    “Safe3 Web Application Firewall"是国内安全组织保护伞网络基于新一代Web安全技术开发的全方位企业Web信息安全产品.能有效扫描各种WebShell,同时也可以 ...

  9. nodejs 更新最新版本

    sudo npm cache clean -f sudo npm install -g n sudo n stable

  10. IOS第六天(3:scrollView 图片轮播器)

    IOS第六天(3:scrollView 图片轮播器) #import "HMViewController.h" #define kImageCount 5 @interface H ...