标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 35099 Accepted Submission(s):
12610
1 #include <iostream> 2 using namespace std; 3 int s[5]; 4 void add(int t) 5 { 6 int i,k=1; 7 for(i=1; i<=4; i++) //通过打表找规律,发现a^b的个位数字4个一循环,而且只需要保存个位数 8 { 9 k=k*t%10; 10 s[i]=k; 11 } 12 } 13 int main() 14 { 15 int a,b,i,k; 16 while(cin>>a>>b) 17 { 18 if(b==0) 19 { 20 cout<<1<<endl; 21 continue ; 22 } 23 a=a%10; 24 add(a); 25 k=b%4; 26 if(k==0) 27 cout<<s[4]<<endl; 28 else 29 cout<<s[k]<<endl; 30 } 31 return 0; 32 }
标签:
原文地址:http://www.cnblogs.com/pshw/p/4816879.html