Cod sursa(job #1737923)
Utilizator | Data | 5 august 2016 12:36:11 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
int main()
{
long long n,p,s=1,i,x=1999999973;
in>>n>>p;
while(p)
{
if(p%2==0)
{
p/=2;
n=(n*n)%x;
}
else
{
p--;
s=(s*n)%x;
}
}
out<<s;
return 0;
}