Rightmost DigitTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 32258 Accepted Submission (s): 12403
Problem Descriptiongiven A positive integer N, you should output the most right digit of n^n.
Inputthe 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).
Outputfor Each test case, you should output the rightmost digit of n^n.
Sample Input
#include <iostream> #include <cstring> #include <cstdio> #include <cctype> #include <cstdlib > #include <algorithm> #include <set> #include <vector> #include <string> #include <map > #include <queue>using namespace std; #define LL Long Longll multimod (ll a,ll n,ll m) { ll ans=1,tem=a; while (n) { if (n&1) ans=ans*tem%m; tem=tem*tem%m; n/=2; } return ans;} int main () { LL a,b;int T; cin>>t; while (t--) { cin>>a; Cout<<multimod (a,a,10) <<endl; } return 0;}
HDU 1061-rightmost Digit (Fast power)