N - Rightmost Digit
Given a positive integer N, you should output the most right digit of N^N.
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
2 3 4
7 6
#include<stdio.h> int Quick_MI(int n,int m,int c) { int s=1; n=n%c; while(m) { if(m&1) { s=(s*n)%c; } n=(n*n)%c; m=m/2; } //快速幂 return s; } int main() { int T,N,k,c=10; scanf("%d",&T); while(T--) { scanf("%d",&N); k=Quick_MI(N,N,c); printf("%d\n",k); } return 0; }