Problem T
Time limit:1000 MS Memory limit:32 MB 64bit IO Format:%i64d
submitted:81 accepted:25
[Submit] [Status] [Web Board]
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 was a single integer T which is the number of test cases. T test Cases follow.
Each test case is 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 = rightmost, so the-the-digit is 7.
In the second case, 4 * 4 * 4 * 4 = at the very rightmost digit is 6.
Bit operator is really a very useful tool AH. (In fact, there are rules to follow)
#include <stdio.h>
int main ()
{
long n,t,x,m,i;
scanf ("%i64d", &m);
for (i=0; i<m; i++)
{
scanf ("%i64d", &n);
t=n%10;
X=1;
while (n!=0)
{
if (n&1==1)
{
x*=t;
x=x%10;
}
t*=t;
t=t%10;
n>>=1;
}
x=x%10;
printf ("%i64d\n", x);
}
return 0;
}