People See people love a^b
Problem Description An integer representing the last three digits of the a^b. Description: The meaning of A^b is "A's B-square"
Input data contains multiple test instances, one row per instance, consisting of two positive integers a and B (1<=a,b<=10000), if a=0,
B=0, it indicates the end of the input data and does not handle it.
Output for each test instance, print the last three bits of the a^b that represent the integers, one row for each output.
Sample Input
2 3 12 6 6789 10000 0 0
Sample Output
8 984 1
A topic of the same remainder theorem , water problem.
Congruence theorem:
The mathematical notation is:
A≡b (mod D)
Its meaning is a mod d = b mod D
Here are the seven laws of the congruence theorem
1) a≡a (mod d)
2) a≡b (mod d) →b≡a (mod d)
3) (A≡b (mod D), b≡c (mod D)) →a≡c (mod d)
If A≡x (mod d), b≡m (mod d), then
4) a+b≡x+m (mod d)
5) a-b≡x-m (mod d)
6) a*b≡x*m (mod d)
7) a≡b (mod D) is a-B divisible by D
Then for
(A * b) (mod c) = (x * y) (mod c)
x = a mod c
y = b mod C
So for (a^b) MoD C in this form, set the mid-volume mid, the initial value is 1, then perform a B-operation can be obtained the answer:
MID = (Mid * (a mod c)) MoD C
The following is the implementation code:
#include <stdio.h>#define MOD(i) (i) % 1000int main(){ int a,b; while(scanf("%d%d",&a,&b) != EOF && a | b){ int0; int mul_mod_value = MOD(a); while(b--) ans = MOD(ans * mul_mod_value); printf("%d\n",ans); } return0;}
Avionics OJ-2035 people to see people love a^b