Cod sursa(job #1649452)
Utilizator | Data | 11 martie 2016 13:42:21 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include<fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
unsigned n,p,rez;
const long long MOD=1999999973;
unsigned put(unsigned a,unsigned b)
{
unsigned r=1;
while(b>1)
{
if(b%2==0)
{
a=(a*a)%MOD;
b/=2;
}
else
{
r=(r*a)%MOD;
b--;
}
}
return (a*r)%MOD;
}
int main()
{
fin>>n>>p;
rez=put(n,p);
fout<<rez;
return 0;
}