Topic Connection
http://acm.hdu.edu.cn/showproblem.php?pid=2035
People See people love a^bdescription
An integer representing the last three digits of the a^b.
Description: The meaning of A^b is "A's B-square"
Input
The input data contains multiple test instances, one row per instance, consisting of two positive integers a and B (1<=a,b<=10000), and if a=0, b=0, indicates the end of the input data and does not process.
Output
For each test instance, output an integer representing the last three bits of a^b, one row for each output.
Sample Input
2 3
12 6
6789 10000
0 0
Sample Output
8
984
1
#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 M = 1000;const int N = 100001;const int INF = 0x3f3 F3f3f;void pow_mod (int A, int B) {int ans = 1; while (b) {if (b & 1) ans = ans * A% M; A = A * a% M; B >>= 1; } printf ("%d\n", ans);} int main () {#ifdef LOCAL freopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w+", stdout); #endif int A, B;while (~SCANF ("%d%d", &a, &b), A + b) {Pow_mod (A, b); } return 0;}
Hdu 2035 people to see people love a^b