Cod sursa(job #1509852)
Utilizator | Data | 24 octombrie 2015 12:48:48 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int main()
{ long long n,p,prod=1;
f >>n>>p;
while (p>1)
{if (p%2==0)
{
n=(n*n)%1999999973;
p=p/2;
}
else {prod=(prod*n)%1999999973;p--;}
}
g <<(n*prod)%1999999973;
return 0;
}