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

题目链接: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;
}
时间: 2025-01-05 00:32:42

URAL 1295. Crazy Notions(数学啊 & 找规律)的相关文章

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 depressurizati

[CSP-S模拟测试]:排列组合(数学 or 找规律)

题目描述 $T$组数据,每次给定$n$,请求出下式的值,对$10^9+7$取模: $$C_n^0\times C_n^0+C_n^1\times C_n^1+C_n^2\times C_n^2+...+C_n^n\times C_n^n$$ 输入格式 第一行一个整数$T$,表示数据组数.接下来$T$行,每一行包含一个整数$n$,含义如题所示. 输出格式 输出$T$行,每行包含一个整数,表示对$10^9+7$取模后的答案. 样例 样例输入: 212 样例输出: 26 数据范围与提示 对于$30\%

[CSP-S模拟测试]:小盆友的游戏(数学 or 找规律)

题目传送门(内部题110) 输入格式 第一行一个整数$N$,表示小盆友的个数. 第二行$N$个整数$A_i$,如果$A_i=-1$表示$i$目前是自由身,否则$i$是$A_i$的跟班. 输出格式 一个整数$X$,表示在模$10^9+7$的情况下,期望总猜拳次数. 样例 样例输入1: 2-1 -1 样例输出1: 1 样例输入2: 3-1 -1 -1 样例输出2: 3 样例输入3: 4-1 -1 -1 -1 样例输出3: 7 样例输入4: 5-1 -1 -1 -1 -1 样例输出4: 15 样例输入

[CSP-S模拟测试]:小W的魔术(数学 or 找规律)

题目传送门(内部题130) 输入格式 第一行一个整数$n$,表示字符串的长度. 第二行一个只包含小写字母的字符串$s$. 输出格式 一行一个整数表示答案对$998244353$取模后的结果. 样例 样例输入: 2a 样例输出: 625 数据范围与提示 对于$20\%$的测试数据,$n\leqslant 4$. 对于$40\%$的测试数据,$n\leqslant 100$. 对于$60\%$的测试数据,$n\leqslant 10,000,000$. 对于另外$20\%$的测试数据,保证$s$只由

uva1315 Crazy tea party(找规律)

题意就是说把顺时针排的1到n换成逆时针排的需要的最少交换步数. 如果是线形的一串数,需要的交换次数就是个冒泡排序的交换次数:n*(n-1)/2,或者用a[i]=(i-1)+a[i-1]推出来. 对于环形,切成两个线形就行了,通过观察规律知:越接近平均切开越好. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #incl

HDU 4588 Count The Carries(数学 二进制 找规律啊)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4588 Problem Description One day, Implus gets interested in binary addition and binary carry. He will transfer all decimal digits to binary digits to make the addition. Not as clever as Gauss, to make th

Acdream 1416 Crazy Nim(简单博弈找规律)

传送门 Crazy Nim Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Submit Statistic Next Problem Problem Description Alice and Bob like to play crazy nim. The game proceeds as follows. There are several stones arranged in

hdu1466 计算直线的交点数(找规律+数学)

转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1466 计算直线的交点数 Problem Description 平面上有n条直线,且无三线共点,问这些直线能有多少种不同交点数. 比如,如果n=2,则可能的交点数量为0(平行)或者1(不平行). Input 输入数据包含多个测试实例,每个测试实例占一行,每行包含一个正整数n(n<=20

ZOJ 3622 Magic Number 打表找规律

A - Magic Number Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3622 Appoint description: Description A positive number y is called magic number if for every positive integer x it satisfies that