Cod sursa(job #1487855)
Utilizator | Data | 17 septembrie 2015 15:45:49 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <iostream>
#include <fstream>
using namespace std;
long long N,P;
long long putere( long long x, long long p)
{
long long m=1999999973;
if (p==0)
return 1;
long long aux=putere (x,p/2);
if (p%2==0)
return aux*aux%m;
return aux*aux*x%m;
}
int main()
{
ifstream f("lgput.in");
ofstream g("lgput.out");
f>>N>>P;
g<<putere(N,P);
return 0;
}