Pagini recente » Cod sursa (job #1485284) | Cod sursa (job #1646991) | Cod sursa (job #1144562) | Cod sursa (job #1381024) | Cod sursa (job #1568724)
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int squaringExponentiation(int x, int n, int m) {
if (n == 1)
return x;
else if (n % 2 == 1)
return 1LL * ((x%m) * (squaringExponentiation(x * x, (n - 1) / 2, m)%m))%m;
else if (n % 2 == 0)
return 1LL*(squaringExponentiation(x * x, n / 2, m)%m)%m;
}
int main()
{
int a, b, c;
fin >> a >> b >> c;
fout << squaringExponentiation(a, b, c);
return 0;
}