[HDU] [2035] Everyone Loves A^B

Problem Description

Loading...

Problem Analysis

Another congruence theorem problem, I suppose
But I didn’t know that back then…
So I just wrote it… and it passed…

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#include<stdio.h>
int main() {
	int n,i,a,b;
	while(scanf("%d %d",&a,&b),a!=0||b!=0) {
		n=a;
		for(i=1; i<b; i++) {
			n=n*a;
			n=n%1000;
		}
		printf("%d\n",n);
	}
	return 0;
}

Loading...