Cod sursa(job #1611236)
Utilizator | Data | 23 februarie 2016 23:35:53 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include<fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
unsigned a,b,MOD=1999999973,x=1;
unsigned p;
unsigned lgpow(unsigned a, unsigned b)
{
while(b>1)
{
if(b%2==0)
{
b/=2;
a=(a*a)%MOD;
}
else
{
x=(x*a)%MOD;
b--;
}
}
return (a*x)%MOD;
}
int main()
{
fin>>a>>b;
p=lgpow(a,b);
fout<<p;
}