Cod sursa(job #966391)
| Utilizator | Data | 25 iunie 2013 20:32:49 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <cstdio>
using namespace std;
long long a, b, i, p=1, x;
int c;
int main()
{
freopen("modulo.in", "r", stdin);
freopen("modulo.out", "w", stdout);
scanf("%lld %lld %d", &a, &b, &c);
if(!b%2)
{
for(i=1;i<=b/2;++i)
p=((p%c)*(a%c)%c);
a=((p%c)*(p%c))%c;
}
else
{
for(i=1;i<=b/2;++i)
p=((p%c)*(a%c))%c;
a=((a%c)*(p%c)*(p%c))%c;
}
printf("%d\n", a);
return 0;
}
