Cod sursa(job #1144689)
Utilizator | Data | 17 martie 2014 14:21:49 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <iostream>
#include <fstream>
#define nr 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long putere(long long x, long long y)
{
if(!((unsigned long)y&1))
return putere(x*x,y/2);
else return x*putere(x*x,(y-1)/2);
}
int main()
{
long long n,p;
f>>n>>p;
g<<putere(n,p)%nr;
return 0;
}