A-Again Twenty Five!

来源:互联网 发布:9.9元天天特价淘宝童装 编辑:程序博客网 时间:2024/05/16 19:12

A. Again Twenty Five!
time limit per test0.5 seconds
memory limit per test64 megabytes
inputstandard input
outputstandard output
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. “Do I give such a hard task?” — the HR manager thought. “Just raise number 5 to the power of n and get last two digits of the number. Yes, of course, n can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions.”

Could you pass the interview in the machine vision company in IT City?

Input
The only line of the input contains a single integer n (2 ≤ n ≤ 2·1018) — the power in which you need to raise number 5.

Output
Output the last two digits of 5n without spaces between them.

Examples
input
2
output
25

题意:求出5的n次方,然后输出最后两个数。
PS:只要n大于0,不管怎么平方,输出的最后两位都是25。。。。
当然,鉴于前面有那么多人做错,我决定还是安安静静的用快速幂求模。

直接上代码

#include<cstdio>#include<stack>#include<cstring>#include<cctype>#include<cstdlib>using namespace std;int pow(int a,long long int n,int b)//快速幂取模{    int result=1;    a=a%b;//积的取余等于取余的积取余    while(n>0)    {        if(n%2==1)            result=result*a%b;        n=n/2;        a=a*a%b;    }    return result;}int main(){    long long int n;    while(scanf("%lld",&n)!=EOF)    {        printf("%d\n",pow(5,n,100));    }    return 0;}

关于快速幂取模问题,我之前有篇文章特意总结过
http://blog.csdn.net/qq_32680617/article/details/50640622

0 0
原创粉丝点击