Cod sursa(job #1669400)
Utilizator | Data | 30 martie 2016 18:02:54 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include <iostream>
#include<fstream>
using namespace std;
unsigned long long a,b,c,mod,aux;
int main()
{
ifstream f("modulo.in");
ofstream g("modulo.out");
f>>a>>b>>c;
mod=1;aux=1;
while(b>1)
{
if(b%2==1)
{b--;aux=((aux%c)*(a%c))%c;}
else
{b/=2;a=(a*a)%c;}
}
a*=aux;
a%=c;
g<<mod;
return 0;
}