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 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

题意:输入一个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;
}

时间: 2024-12-29 14:00:13

URAL 1295 Crazy Notions 数学 找规律的相关文章

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

题目链接: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 th

ural 2029 Towers of Hanoi Strike Back (数学找规律)

ural 2029 Towers of Hanoi Strike Back 链接:http://acm.timus.ru/problem.aspx?space=1&num=2029 题意:汉诺塔问题,给定一串只有(A, B, C)的字符串(A代表在第一根柱子,B代表在第二根柱子,C代表在第三根柱子),从前往后代表盘子的大小,第 i 个字母代表di i 个盘子在某个柱子上.问移动给定字母状态的盘子最少需要多少步. 思路:首先,从后往前看(最大的盘子),如果不在当前柱子上,那么移动到目标柱子需要 2

数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight

题目传送门 1 /* 2 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <iostream> 8 #include <cmath> 9 #include <vector> 10 using namespace std; 11

URAL 1502. Domino Dots (找规律)

1502. Domino Dots Time limit: 0.5 second Memory limit: 64 MB In order to run huge capitals, New Russians need exceptional brains. Of course, with such workload, they also need peculiar relaxation methods. In casinos there are special domino sets for

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

[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 样例输入

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