#include <stdio.h> #include <math.h> int f(int a,int b){ int temp, i, n; temp = a%1000; if( temp ==0 ) return 0; n = (int)log(b); for(i=1; i<=n; i++){ temp = (temp*temp) %1000; } for(i=1; i<=b - (2<<(n-1)); i++){ temp = temp * a %1000; } return temp; } void main(){ int a,b; while( (scanf("%d%d", &a, &b)!= EOF) && ( a!=0 || b !=0) ){ printf( "%d/n", f(a,b)); } }