您的位置:首页 > 其它

URAL 1295 Crazy Notions 数学 找规律

2015-03-07 19:17 453 查看


1295. Crazy Notions

Time limit: 0.5 second

Memory 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 ends
with.

Samples

inputoutput
1

1

3

2


题意:输入一个n,计算ans= 1n+2n+3n+4n
,输出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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: