Cod sursa(job #1000326)
Utilizator | Data | 22 septembrie 2013 17:54:37 | |
---|---|---|---|
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 f("lgput.in");
ofstream g("lgput.out");
long n, p, x, y;
int main ()
{
f >> n >> p;
x = 1;
y = n;
while(p != 0)
if(p%2 == 0)
{
y = (y*y)%1999999973;
p /= 2;
}
else
{
x = (x*y)%1999999973;
p --;
}
g << x;
return 0;
}