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.
output
Each test case contains a single positive integer N(1=N=1,000,000,000).
For each test case, you should output the rightmost digit of N^N.
#include<stdio.h>
int main()
{
int N,i,j,m,t,b;
scanf("%d",&N);
for(i=0;i<N;i++)
{
scanf("%d",&b);
m=b;
b%=10;
t=b;
for(j=0;j<m-1;j++){
t%=10;
t=b*t;
}
printf("%d\n",t%10);
}
return 0;
}
做这题的时候开始的时候,想到的是用数组a[i]^a[i],处理的数据太大,导致程序无法运行;请教了一下大神,发现这个题找到规律,循环出来就不难了。