/*
Copyright 2011 Marek "p2004a" Rusinowski
Exponentiation by squaring
*/
#include <cstdio>
int pow ( int a, int b, int c) {
if ( ! b) return 1 ;
int tmp = pow ( a, b/ 2 , c) ;
return ( ( ( tmp * tmp) % c) * ( b & 1 ? a : 1 ) ) % c;
}
int main( ) {
int a, b, c;
scanf ( "%d %d %d" , & a, & b, & c) ;
printf ( "%d\n " , pow ( a, b, c) ) ;
return 0 ;
}
LyoKICBDb3B5cmlnaHQgMjAxMSBNYXJlayAicDIwMDRhIiBSdXNpbm93c2tpCiAgRXhwb25lbnRpYXRpb24gYnkgc3F1YXJpbmcKKi8KI2luY2x1ZGUgPGNzdGRpbz4KCmludCBwb3cgKGludCBhLCBpbnQgYiwgaW50IGMpIHsKICBpZiAoIWIpIHJldHVybiAxOwogIGludCB0bXAgPSBwb3coYSwgYi8yLCBjKTsKICByZXR1cm4gKCgodG1wICogdG1wKSAlIGMpICogKGIgJiAxID8gYSA6IDEpKSAlIGM7Cn0KCmludCBtYWluKCkgewogIGludCBhLCBiLCBjOwogIHNjYW5mKCIlZCAlZCAlZCIsICZhLCAmYiwgJmMpOwogIHByaW50ZigiJWRcbiIsIHBvdyhhLCBiLCBjKSk7CiAgcmV0dXJuIDA7Cn0K
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:15: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
stdout