基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题
51nod1004 n^n的末位数字-LMLPHP 收藏
51nod1004 n^n的末位数字-LMLPHP 关注
给出一个整数N,输出N^N(N的N次方)的十进制表示的末位数字。

 
Input
一个数N(1 <= N <= 10^9)
Output
输出N^N的末位数字
Input示例
13
Output示例
3
51nod1004 n^n的末位数字-LMLPHP
李陶冶 (题目提供者)
 
C++的运行时限为:1000 ms ,空间限制为:131072 KB 示例及语言说明请按这里
 
一道快速幂的裸题
但是可以通过打表找循环节的规律
 
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define LL long long
using namespace std;
const LL MAXN=;
inline LL read()
{
char c=getchar();LL flag=,x=;
while(c<''||c>'') {if(c=='-') flag=-;c=getchar();}
while(c>=''&&c<='') x=(x*+c-),c=getchar(); return x*flag;
}
LL a[]={,,,,,,,,,};
LL n;
int main()
{
n=read();
LL p=n%;
n=n%a[p];
if(n==)
{
LL ans=;
for(LL i=;i<=a[p];i++)
ans=ans*p;
cout<<ans%;
}
else
{
LL ans=;
for(LL i=;i<=n;i++)
ans=ans*p;
cout<<ans%;
}
return ;
}
 
05-11 15:38
查看更多