标签:
Description
Input
Output
Sample Input
Sample Output
Hint
In the first case, 3 * 3 * 3 = 27, so the rightmost digit is 7. In the
second case, 4 * 4 * 4 * 4 = 256, so the rightmost digit is 6.
N的N次方,只需要求N的个位数的N的方的个位数,同时有一个规律,
1 1 1 1 1 1 1 1
2 4 8 6 2 4 8 6
3 9 7 1 3 9 7 1
4 6 4 6 4 6 4 6
5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6
7 9 3 1 7 9 3 1
8 4 2 6 8 4 2 6
1 9 1 9 1 9 1 9
所以应该很简单把
1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 int main() 5 { 6 int t; 7 int n; 8 int i,j; 9 while(cin>>t) 10 { 11 while(t--) 12 { 13 cin>>n; 14 i=n%10; 15 j=n%4; 16 if(j==0) 17 cout<<i*i*i*i%10<<endl; 18 else 19 { 20 int ans=1; 21 while(j--) 22 { 23 ans*=i; 24 ans=ans%10; 25 } 26 cout<<ans<<endl; 27 } 28 } 29 } 30 return 0; 31 }
标签:
原文地址:http://www.cnblogs.com/Aa1039510121/p/5689862.html