1249: cute A ^ B

A ^ B integer seek the last three digits of the representation. 
Description: A ^ B is the meaning of "A, B power" 
Input data comprising a plurality of test cases, one row for each instance, two positive integers A and B (1 <= A, B <= 10000), if A = 0, B = 0, it means the end of the input data without processing.
For each test case, output a final three A ^ B integer representation, each output per line.
2 3
12 6
6789 10000
0 0
8 
984 
1 


Note seek after three, every time the need to multiply 1000%, 1000% or final, will be out of range
#include <stdio.h>
#include <math.h>

int main(){

    int a,b;
    int temp;
    while(scanf("%d %d",&a,&b)!=EOF){

        if(a!=0&&b!=0){
            temp=a;
        for(int i=1;i<=b-1;i++)
            a=a*temp%1000;
            printf("%d\n",a);
        }
        else
            break;
        
    }
    


    return 0;


}

 

 

Guess you like

Origin www.cnblogs.com/PerZhu/p/11588410.html