#include <iostream> using namespace std; int main() { long long a, b, p; cin >> a >> b >> p; long long res = 0; while(b) { if(b & 1) res = (res + a) % p; a = (a + a) % p; b >>= 1; } cout << res << endl; return 0; }
#include <iostream> using namespace std; int main() { long long a, b, p; cin >> a >> b >> p; long long res = 0; while(b) { if(b & 1) res = (res + a) % p; a = (a + a) % p; b >>= 1; } cout << res << endl; return 0; }