/*----<Bồ tác phù hộ code không bị bug>--------
_oo0oo_
o8888888o
88" . "88
(| -_- |)
0\ = /0
___/`---'\___
.' \| |// '.
/ \||| : |||// \
/ _||||| -:- |||||- \
| | \ - /// | |
| \_| ''\---/'' |_/ |
\ .-\__ '-' ___/-. /
___'. .' /--.--\ `. .'___
."" '< `.___\_<|>_/___.' >' "".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `_. \_ __\ /__ _/ .-` / /
=====`-.____`.___ \_____/___.-`___.-'=====
`=---='
------------------<>-------------------------*/
#include <bits/stdc++.h>
#define __Nakano signed
#define Miku__ main()
#define int long long
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr(x, l, r) for (int x = l; x < r; x++)
#define frr(x, l, r) for (int x = l; x <= r; x++)
#define fd(x, l, r) for (int x = l; x >= r; x--)
#define cs const
#define TIME (1.0*clock() / CLOCKS_PER_SEC)
#define RUNTIME cerr << "\n" << "Runtime: " << TIME << "s\n";
#define Fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define Nakanomiku ios_base::sync_with_stdio(0);
#define TiemNetBaTuyen cin.tie(0);
#define THCSPHAMHUYTHONG cout.tie(0);
typedef double db;
typedef std::string str;
typedef std::vector<int> vi;
typedef std::greater<int> gi;
typedef std::map<int, int> mii;
typedef std::pair<int, int> ii;
inline int gcd(int a,int b){int s;while(b){s=a%b;a=b;b=s;}return a;}
inline int lcm(int a, int b){return a/gcd(a,b)*b;}
cs int N = 1e6 + 5;
cs int oo = 1e18;
using namespace std;
int power(int a,int b,int c){
a %= c;
int res = 0;
while (b){
if (b & 1) res = (res + a) % c;
a = (a * 2) % c;
b >>= 1;
}
return res;
}
__Nakano Miku__ {
Nakanomiku TiemNetBaTuyen THCSPHAMHUYTHONG
int a,b,c; cin >> a >> b >> c;
cout << power(a,b,c);
RUNTIME;
return 0;
}
LyotLS0tPELhu5MgdMOhYyBwaMO5IGjhu5kgY29kZSBraMO0bmcgYuG7iyBidWc+LS0tLS0tLS0KICAgICAgICAgICAgICAgX29vMG9vXyAKICAgICAgICAgICAgICBvODg4ODg4OG8gCiAgICAgICAgICAgICAgODgiIC4gIjg4IAogICAgICAgICAgICAgICh8IC1fLSB8KSAKICAgICAgICAgICAgICAwXCAgPSAgLzAgCiAgICAgICAgICAgIF9fXy9gLS0tJ1xfX18gCiAgICAgICAgICAuJyBcfCAgICAgfC8vICcuIAogICAgICAgICAvIFx8fHwgIDogIHx8fC8vIFwgCiAgICAgICAgLyBffHx8fHwgLTotIHx8fHx8LSBcIAogICAgICAgfCAgIHwgXCAgLSAgLy8vIHwgICB8IAogICAgICAgfCBcX3wgICcnXC0tLS8nJyAgfF8vIHwgCiAgICAgICBcICAuLVxfXyAgJy0nICBfX18vLS4gLyAKICAgICBfX18nLiAuJyAgLy0tLi0tXCAgYC4gLidfX18gCiAgLiIiICc8ICBgLl9fX1xfPHw+Xy9fX18uJyA+JyAiIi4gCiB8IHwgOiAgYC0gXGAuO2BcIF8gL2A7LmAvIC0gYCA6IHwgfCAKIFwgIFwgYF8uICAgXF8gX19cIC9fXyBfLyAgIC4tYCAvICAvIAo9PT09PWAtLl9fX19gLl9fXyBcX19fX18vX19fLi1gX19fLi0nPT09PT0gCiAgICAgICAgICAgICAgIGA9LS0tPScKLS0tLS0tLS0tLS0tLS0tLS0tPD4tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tKi8KCiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgoKI2RlZmluZSBfX05ha2FubyAgICAgICAgICBzaWduZWQKI2RlZmluZSBNaWt1X18gICAgICAgICAgICBtYWluKCkKI2RlZmluZSBpbnQgICAgICAgICAgICBsb25nIGxvbmcKI2RlZmluZSBmaSAgICAgICAgICAgICBmaXJzdAojZGVmaW5lIHNlICAgICAgICAgICAgIHNlY29uZAojZGVmaW5lIGFsbCh4KSAgICAgICAgIHguYmVnaW4oKSwgeC5lbmQoKQojZGVmaW5lI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