Cod sursa(job #1509784)
Utilizator | Data | 24 octombrie 2015 12:21:36 | |
---|---|---|---|
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 f("lgput.in");
ofstream g("lgput.out");
int main()
{
long p,n,k;
f>>n;
f>>p;
long r=1;
while (p!=1)
{
if(p%2==0)
{
n=(n*n)% 1999999973;
p/=2;
}
else
{
p--;
r=(r*n)% 1999999973;
}
}
g<<(n*r)% 1999999973;
return 0;
}