题目连接:

  http://www.lightoj.com/volume_showproblem.php?problem=1090

题目大意:

  给出n,r,p,q四个数字1<=n,r,p,q<=1000000,求出的末尾有几个0?

解题思路:

  是不是一下子懵了,数字好大,复杂度好高,精度怎么办···············,就问你怕不怕?

  其实都是纸老虎啦,因为10的因子只有2和5,所以可以打表保存从1到当前数字相乘的积中分别含有2,5的个数。然后算出中分别含有2,5的个数,取其最小就是结果。(ps:一定不要因为直接统计10的个数方便,而去统计10的个数,两者还是有不同的)。

 #include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
//复杂度O(1)
const int maxn = ;
struct node
{
int x, y;
};
node a[maxn];
int main ()
{
int t, n, r, p, q, l = ;
memset (a, , sizeof(a));
int x , y;
x = y = ;
for (int i=; i<maxn; i++)
{//打表大法好\(^o^)/~
int num = i;
while (num % == )
{
x ++;
num /= ;
}
num = i;
while (num % == )
{
y ++;
num /= ;
}
a[i].x = x;
a[i].y = y;
}
scanf ("%d", &t);
while (t --)
{
scanf ("%d %d %d %d", &n, &r, &p, &q);
int res = min(a[n].x - a[r].x - a[n-r].x + (a[p].x - a[p-].x) * q, a[n].y - a[r].y - a[n-r].y + (a[p].y - a[p-].y) * q);
printf ("Case %d: %d\n", l++, res);
}
return ;
}

Lightoj 1090 - Trailing Zeroes (II)的更多相关文章

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

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

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

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

  3. Trailing Zeroes (II) LightOJ - 1090(预处理+前缀和)

    求C(n,r)*p^q的后缀零 考虑一下 是不是就是求 10^k*m  的k的最大值 而10又是由2 和 5 组成  所以即是求 2^k1 * 5^k2 * m1 中k1和k2小的那一个数 短板效应嘛 ...

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

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

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

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

  6. lightoj 1028 - Trailing Zeroes (I)(素数筛)

    We know what a base of a number is and what the properties are. For example, we use decimal number s ...

  7. LightOJ 1138 Trailing Zeroes (III) 打表

    就是统计5,然后当时因为发现最多有8000w个5的倍数,然后8000w/100,是80w,打表,二分找 然后我看网上的都是直接二分找,真是厉害 #include <cstdio> #inc ...

  8. LightOJ 1028 - Trailing Zeroes (I) 质因数分解/排列组合

    题意:10000组数据 问一个数n[1,1e12] 在k进制下有末尾0的k的个数. 思路:题意很明显,就是求n的因子个数,本来想直接预处理欧拉函数,然后拿它减n就行了.但注意是1e12次方法不可行.而 ...

  9. LightOj 1138 Trailing Zeroes (III)

    题目描述: 假设有一个数n,它的阶乘末尾有Q个零,现在给出Q,问n最小为多少? 解题思路: 由于数字末尾的零等于min(因子2的个数,因子5的个数),又因为2<5,那么假设有一无限大的数n,n= ...

随机推荐

  1. HUNT:一款可提升漏洞扫描能力的BurpSuite漏洞扫描插件

    今天给大家介绍的是一款BurpSuite插件,这款插件名叫HUNT.它不仅可以识别指定漏洞类型的常见攻击参数,而且还可以在BurpSuite中组织测试方法. HUNT Scanner(hunt_sca ...

  2. POJ 1988 Cube Stacking(并查集+路径压缩)

    题目链接:id=1988">POJ 1988 Cube Stacking 并查集的题目 [题目大意] 有n个元素,開始每一个元素自己 一栈.有两种操作,将含有元素x的栈放在含有y的栈的 ...

  3. CSS多种方法实现分隔线

    <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8" /> <title&g ...

  4. MongoDB使用入门

    1.MongoDB的安装 步骤一:下载MongoDB 下载安装包:http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.0.4.tgz 步骤二:设置 ...

  5. 怎样将查询到的数据显示在DataGridView中

    背景介绍: 数据库中的T_Line_Info表中存放着学生上机的记录,也就是我们须要查询上机记录的表.当中详细内容为: 界面设计例如以下: watermark/2/text/aHR0cDovL2Jsb ...

  6. Navicat for MySQL出现1030-Got error 28 from storage engine错误

    Navicat for MySQL出现1030-Got error 28 from storage engine错误  刚刚还能用这会儿就用不了了,估计是磁盘空间不足引起的! 在根目录/下执行命令:d ...

  7. php截取某二个特殊字符串间的某段字符串

    在php开发的过程中,有时候会用到截取某二个特殊字符串间的某个字符串,并对这个字符串做特殊的处理,那么对截取出来的字符串做什么特殊处理我们临时无论.我们今天先讲php截取某二个特殊字符串间的某个字符串 ...

  8. arcgis 发布地图服务

    arcgis中,地图文档需要发布,才能为WEB所用. 咋发布呢? 1.在arcmap里面,点击 文件 - 共享为 - 服务 2.在弹出的对话框里选"发布服务",然后 3.这里面有点 ...

  9. Educational Codeforces Round 17 D. Maximum path DP

    题目链接:http://codeforces.com/contest/762/problem/D 多多分析状态:这个很明了 #include<bits/stdc++.h> using na ...

  10. LDAP方式连接AD获取用户信息

    LDAP资料介绍可以参考:http://wenku.baidu.com/view/262742f9f705cc17552709f9.html ldap访问AD域的的错误一般会如下格式: Ldap lo ...