码迷,mamicode.com
首页 > 其他好文 > 详细

URAL 1295. Crazy Notions(数学啊 & 找规律)

时间:2015-03-07 11:38:06      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:ural   数学   

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1295



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

input output
1
1
3
2



代码如下(找规律):

#include <cstdio>
#define LL __int64
//int main()
//{
//    int n;
//    for(int i = 1; i <= 32; i++)
//    {
//        LL ans1 = 1;
//        LL ans2 = 1;
//        LL ans3 = 1;
//        LL ans4 = 1;
//        for(int j = 1; j <= i; j++)
//        {
//            ans2*=2;
//            ans3*=3;
//            ans4*=4;
//        }
//        int cnt = 0;
//        LL ans = ans1+ans2+ans3+ans4;
//        while(ans)
//        {
//            if(ans%10 == 0)
//            {
//                cnt++;
//                ans/=10;
//            }
//            else
//            {
//                break;
//            }
//        }
//        printf("%d:: ans:%d\n",i,cnt);
//    }
//    return 0;
//}
int main()
{
    int n;
    int a[30]= {1,1,2,0,2,1,2,0,1,1,2,0,1,1,2,0,1,1,2,0};
    while(~scanf("%d",&n))
    {
        printf("%d\n",a[(n-1)%20]);
    }
    return 0;
//    while(~scanf("%d",&n))
//    {
//        if(n%4 == 0)
//        {
//            printf("0\n");
//        }
//        else if((n%4==1 &&n%5==0) || n%4==3)
//        {
//            printf("2\n");
//        }
//        else
//        {
//            printf("1\n");
//        }
//    }
    return 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)
    {
        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++;
        }
        printf("%lld\n",tt);
    }
    return 0;
}



URAL 1295. Crazy Notions(数学啊 & 找规律)

标签:ural   数学   

原文地址:http://blog.csdn.net/u012860063/article/details/44114499

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!