URAL 1295 Crazy Notions 数学 找规律

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 1 n+2 n+3 n+4 n. 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 1 n+2 n+3 n+4 n ends with.

Samples

input output
1
1
3
2





题意:输入一个n,计算ans=  1 n +2 n +3 n +4 n   ,输出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;
}









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值