#include <iostream>
unsigned long long mult(unsigned long long x,unsigned long long y,unsigned long long const z){
if(y == 1)return x % z;
else if( y== 0)return 0;
else if(!(y & 1))return mult((x + x)%z,(y/2) % z,z);
else return (x % z + mult(x % z,(y - 1) % z,z))%z;
}
int main() {
unsigned long long a,b,c;
std::cin >> a >> b >> c;
std::cout << mult(a,b,c);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1bnNpZ25lZCBsb25nIGxvbmcgbXVsdCh1bnNpZ25lZCBsb25nIGxvbmcgeCx1bnNpZ25lZCBsb25nIGxvbmcgeSx1bnNpZ25lZCBsb25nIGxvbmcgY29uc3Qgeil7CglpZih5ID09IDEpcmV0dXJuIHggJSB6OwoJZWxzZSBpZiggeT09IDApcmV0dXJuIDA7CgllbHNlIGlmKCEoeSAmIDEpKXJldHVybiBtdWx0KCh4ICsgeCkleiwoeS8yKSAlIHoseik7CgllbHNlIHJldHVybiAoeCAlIHogKyBtdWx0KHggJSB6LCh5IC0gMSkgJSB6LHopKSV6OwoJCn0KaW50IG1haW4oKSB7Cgl1bnNpZ25lZCBsb25nIGxvbmcgYSxiLGM7CglzdGQ6OmNpbiA+PiBhID4+IGIgPj4gYzsKCXN0ZDo6Y291dCA8PCBtdWx0KGEsYixjKTsKfQ==