Cod sursa(job #635392)
Utilizator | Data | 19 noiembrie 2011 11:05:07 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.34 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream fin("data.in");
ofstream fout("data.out");
long long n,p,rez=1,mod;
fin>>p>>n>>mod;
while(p)
{
if(p%2==1)
rez=(rez*n)%mod;
n=(n*n)%mod;
p/=2;
}
fout<<rez;
return 0;
}