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
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<stdio.h> #include<iostream> using namespace std; int solve(long long n) { int t,b; long long i; b=n%10; t=1; if(b==0)return 0; while(n) { if(n%2==1) { t*=b; t%=10; } b*=b; b%=10; n/=2; } return t; } int main() { int T; long long n; cin>>T; while(T--) { cin>>n; cout<<solve(n)<<endl; } return 0; }
-------------------------------------1月20号测试