Cod sursa(job #1000379)
Utilizator | Data | 22 septembrie 2013 19:39:27 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <fstream>
#define nmax 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long n, p, x, y;
int main ()
{
f >> n >> p;
x = 1;
y = n%nmax;
while(p > 0)
if(p%2 == 0)
{
y = (y*y)%nmax;
p /= 2;
}
else
{
x = (x*y)%nmax;
p --;
}
g << x%nmax;
return 0;
}