Topic Connection
http://acm.hdu.edu.cn/showproblem.php?pid=1061
Rightmost digitdescription
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
3
3
5
Sample Output
7
5
Fast power:
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < cstdio> #include <vector> #include <map>using std::map;using std::min;using std::find;using std::p air; Using std::vector;using std::multimap; #define PB (E) push_back (e) #define SZ (c) (int) (c). Size () #define MP (A, b) make_pair (A, B) #define ALL (c) (c). Begin (), (c). End () #define ITER (c) __typeof ((c). Begin ()) #define CLS (arr, Val) memset (arr, Val, si Zeof (arr)) #define Cpresent (C, E) (Find (All (c), (e))! = (c). End ()) #define REP (i, n) for (int i = 0; i < (int) n; i++) #defi NE tr (c, I) for (ITER (c) i = (c). Begin (); I! = (c). end (); ++i) const int N = 100001;const int INF = 0x3f3f3f3f;typedef Unsig Ned Long Long ull;ull pow_mod (int n) {ull ans = 1, x = n; while (n) {if (n & 1) ans = ans * x% 10; x = x * x% 10; n >>= 1; } return ans; int main () {#ifdef LOCAL freopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w+", stdout); #endif int t, n; scanf ("%d", &t); while (t--) {scanf ("%d", &n); printf ("%lld\n", Pow_mod (n)); } return 0;}
Hdu 1061 rightmost Digit