Cod sursa(job #1450698)
Utilizator | Data | 14 iunie 2015 13:43:08 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include<fstream>
using namespace std;
const int mod = 1999999973;
long long n,p;
int main()
{
ifstream f("lgput.in");
ofstream g("lgput.out");
f>>n>>p;
if(p==0)
{
g<<"1";
return 0;
}
long sol=1;
while(p)
if(p%2==0)
{
n=n*n%mod;
p/=2;
}
else
{
sol=sol*n%mod;
p--;
}
g<<sol<<"\n";
return 0;
}