Last digit of 51nod1004 n ^ n, 51nod1004 last digit
Source: Author Ignatius. L (Hdu 1061) benchmark time limit: 1 second space limit: 131072 KB score: 5 difficulty: Level 1 algorithm question collection attention to give an integer N, output the last digit in decimal format of N ^ N (N's N power. Input
N (1 <= N <= 10 ^ 9)
Output
Output the last number of N ^ N
Input example
13
Output example
3
Li Ye (subject provider) C ++ runtime: 1000 MS, space limit: for the 131072 KB example and language description, please refer to the following example for a fast power bare question, but you can find the pattern of the circular section by making a table.
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #define LL long long 6 using namespace std; 7 const LL MAXN=200000001; 8 inline LL read() 9 {10 char c=getchar();LL flag=1,x=0;11 while(c<'0'||c>'9') {if(c=='-') flag=-1;c=getchar();}12 while(c>='0'&&c<='9') x=(x*10+c-48),c=getchar(); return x*flag;13 }14 LL a[15]={1,1,4,4,2,1,1,4,4,2};15 LL n;16 int main()17 {18 n=read();19 LL p=n%10;20 n=n%a[p];21 if(n==0)22 {23 LL ans=1;24 for(LL i=1;i<=a[p];i++)25 ans=ans*p;26 cout<<ans%10;27 }28 else29 {30 LL ans=1;31 for(LL i=1;i<=n;i++)32 ans=ans*p;33 cout<<ans%10; 34 }35 return 0;36 }