Cod sursa(job #2388181)
Utilizator | Data | 25 martie 2019 18:56:07 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("modulo.in");
ofstream g("modulo.out");
long long a, b, c, r = 1;
int main()
{
f >> a >> b >> c;
if(b == 0)
{
g << 1 % c;
return 0;
}
while(b > 1)
{
if(b % 2 == 0) a = a % c * a % c;
else
{
r = r * a % c;
a = a % c * a % c;
}
b /= 2;
}
g << a * r % c;
return 0;
}