【codechef】 Zeroes(大数灵活题)
来源:互联网 发布:知乎 财务进销存一体 编辑:程序博客网 时间:2024/05/18 21:48
Virat loves mathematical questions. The other day he came across an interesting question which required him to find out the number of trailing zeroes for the
function. F(n) = 11*22......NN,where N is an integer. Virat solved the problem after a few attempts. He asked the same
question from his friend Rohit to see if he can solve it. Rohit couldn’t arrive at a solution and has asked for your help. Can you help him out?
Input
- The first line contains a single integer T, the number of test cases. T test cases follow.
- Each line contains a single integer
N.
Output
For each test case, output a single line containing a single integer which denotes the number of trailing zeroes for the value of the function computed for
N.
Constraints
- 1 <= T <= 1000
- 1 <= N <= 10000
Example
Input:35102Output:5150
http://www.codechef.com/problems/ZEROES
F(n) = 11*22......NN,求F(n)的末位有几个0。这种题目就是要找规律。因为值实在是太大了,只能算出前几个,于是我就用了字符串大数模板,也只能勉强算出前200个,规律找得不够彻底。。。
0000 55555 1515151515(为方便我把5个数缩成1个)30 50 100 130 165 205 250 350 405 465 530 600 750 830 915 1005 1100 1300 1405 1515 1630 1750 2125....
我们知道 0 1 3 6 10 15....这个数列的前n项和为 n*(n+1)/2 ,上面白色背景的数字就是它的5倍,间隔为5(前面省去一样的了),红色部分减去白色的值是它的25倍,间隔为25,绿色部分减去红色的值是它的125倍,间隔为125,后面以此类推。
#include<iostream> #include<algorithm> #include<string> #include<map> #include<vector> #include<cmath> #include<string.h> #include<stdlib.h> #include<cstdio> #define ll long long using namespace std;int main(void){int t;scanf("%d",&t);while(t--){int n;cin>>n;ll s=0;for(int i=1;pow(5.0,i)<=n;++i){int m=n/pow(5.0,i);s+=pow(5.0,i)*(m+1)*m/2;}printf("%I64d\n",s);}return 0;}#include<iostream> #include<algorithm> #include<string> #include<map> #include<vector> #include<cmath> #include<string.h> #include<stdlib.h> #include<cstdio> #define ll long long using namespace std;int main (void){int t;scanf("%d",&t);while(t--){int n,i;long long int zero=0;scanf("%d",&n);for(i=5;i<=n;i+=5){if(i%78125 == 0)zero += i*7;else if(i%12625 == 0)zero += i*6;else if(i%3125 == 0)zero += i*5;else if(i%625 == 0)zero += i*4;else if(i%125 == 0)zero += i*3;else if(i%25 == 0)zero += i*2;elsezero += i;}printf("%lld\n",zero);}}
- 【codechef】 Zeroes(大数灵活题)
- 【codechef】Gcd Queries(灵活题,分类)
- 【codechef】Arush Challenge(灵活题)
- 【codechef】Strings Classes(枚举灵活题)
- 【codechef】Set Difference (灵活题,超时)
- 【codechef】The Warehouse(灵活题)
- 【codechef】Chef and Strange Formula(找规律,灵活题)
- 【codechef】Chef and Polygons(灵活题,坑题)
- 【codechef】括号匹配,求子串最大值(灵活题)
- zoj 1180 Self Numbers(大数,灵活题)
- 【codechef】 Count Substrings (大数技巧题)(二分+计数,易超时)
- 分割 (大数的分割) 字符串的灵活使用
- codechef GCD2 无穷大数的最大公约数
- 【codechef】Magical Transformation(dp,技巧题)
- codechef(MAY15)第二题Set Difference
- zoj 3175 Number of Containers (大数灵活题,除2改成平方根)
- CodeChef补题计划
- CodeChef FNCS(分块)
- 动态更改View的大小
- miniGUI窗口管理及控件类
- hive udf
- vi笔记
- java.util.vector中的vector的详细用法
- 【codechef】 Zeroes(大数灵活题)
- 项目实践——MD5加密
- Keil常见错误警告
- ibatis 插入数据获得主键值
- git diff指令
- 嵌入式软件开发培训笔记——java第四天(高级类特性——接口/多态/抽象类/内部类以及异常处理)
- TCP、UDP、IP 协议分析
- JS语句
- 卷积