URAL 1295 Crazy Notions 数学 找规律
2015-03-07 19:17
453 查看
1295. Crazy Notions
Time limit: 0.5 secondMemory limit: 64 MB
For five days robot-loader JK546L54p has been buried under the thick layer of the Sibelian plutonium slag. The terrible strike of the atmospheric electricity has led to the depressurization of the robot’s
fuel elements. Who will examine this heap of fused, broken metal here, where there is no any robot technician even at distance of a hundred parsecs? Robot-commissar even did not try to investigate what happened with JK546L54p. He ordered to throw him out into
dumps and that is all. Nobody noticed that positron brains of JK546L54p were still working. If only the robopsychologist was here with JK546L54p! Of course, he would be killed with the hard gamma radiation in a moment, but… If he attached the visualizer of
thoughts to the fused connectors of JK546L54p! He would see the strange performance. Robot was creating! No, I am not joking. He was investigating. Semi casual objects arose in his mind, and he examined them. Crazy properties, crazy theorems.
Besides, here is an example. Let’s take an expression 1n+2n+3n+4n.
How much zeros does its decimal notation end with? JK546L54p solved this problem, and you, student, could you?
Input
The only line contains an integer n (1 ≤ n ≤ 300000).Output
Output the number of zeroes the decimal notation of 1n+2n+3n+4n endswith.
Samples
input | output |
---|---|
1 | 1 |
3 | 2 |
,输出ans末尾几个0。
做法:规律题,刚开始暴力,看了下规律,发现最多末尾只会有2个零。而且有一定规律。所以可以找循环节,n%20。 或者用快速幂,我用快速幂,循环了一遍1到300000,发现确实末尾最多只有两个0,所以。。。
#include <stdio.h> #include <iostream> #include <algorithm> using namespace std; long long mod=100000; long long quickmulti(long long m,long long n)//二分快速幂 { long long ans=1; long long i; while(n) { if(n&1) ans=(m*ans)%mod; m=(m*m)%mod; n>>=1; } return ans; } int main() { long long n; while(scanf("%lld",&n)!=EOF) //for(n=1;n<300000;n++) { //printf("2222:%lld\n",quickmulti(2,n)); long long ans=1; ans+=quickmulti(2,n); ans%=mod; ans+=quickmulti(3,n); ans%=mod; ans+=quickmulti(4,n); ans%=mod; long long tem=ans; long long tt=0; while(tem%10==0) { tem/=10; tt++; } //if(tt>5) //printf("%d\n",n); printf("%lld\n",tt); } return 0; }
相关文章推荐
- URAL 1117. Hierarchy 数学 找规律 二叉树
- URAL —— 1255 & HDU 5100——Chessboard ——————【数学规律】
- URAL 1051 跳跳棋(孔明棋)(加强版) 数学找规律(较弱哦)
- URAL 1295. Crazy Notions(数学啊 & 找规律)
- ural 2029 Towers of Hanoi Strike Back (数学找规律)
- UVA 679 Dropping Balls 【模拟+数学规律】
- hdu 1030 Delta-wave(数学题+找规律)
- Codeforces 715A & 716C Plus and Square Root【数学规律】 (Codeforces Round #372 (Div. 2))
- 【数学 && 规律】HackerRank xor-matrix
- hdu-1220(数学规律)
- URAL 1224. Spiral (规律)
- URAL 2025. Line Fighting 简单数学推理
- URAL 1169. Pairs 图中抽象出数学公式dfs
- 数学发现规律+hdu5014
- HDU - 1061 Rightmost Digit (数学打表)规律
- HDU--5312(规律+数学)
- Delta-wave hdu 1030 找规律的数学题目
- UVA 12683 Odd and Even Zeroes(数学—找规律)
- Codeforces Round #384 (Div. 2) B ,C ,D(规律,数学。树dp)
- Beehive UVALive - 7528 (找规律+数学思维)