杭电ACM最右数



Description 


Given a positive integer N, you should output the most right digit of N^N. 




Input 


The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. 
Each test case contains a single positive integer N(1<=N<=1,000,000,000). 




Output 


For each test case, you should output the rightmost digit of N^N. 






Sample Input 




2
3
4


Sample Output 




7
6




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. 





//错误的,我写的
/*#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int a,i,b,m;
long int s;
cin>>a;
for(i=1;i<=a;i++)
{
cin>>b;
if(b>=1&&b<=1000000000)
{
s=pow(b,b);
m=s%10;
cout<<m<<endl;
}
}
return 0;
}

*/

//正确的,转载的

#include<iostream>
 using namespace std;
 int main()
 {
 int a,b,c;
 cin>>a;
 while(a--)
 { 
   cin>>b;
   c=b%10;
   if(c==0||c==1||c==5||c==6||c==9)
     cout<<c;
   else if(c==4)
     cout<<'6';
   else if(c==8||c==2)
   if(b%4==2)
     cout<<'4';
   else 
     cout<<'6';
   else if(c==3||c==7)
   if(b%4==1)
     cout<<c;
   else  
   if(c==7)
     cout<<'3';
   else
     cout<<'7';
     cout<<endl;
 }
 return 0;
}
 

你可能感兴趣的:(杭电ACM最右数)