Cod sursa(job #878481)
Utilizator | Data | 14 februarie 2013 15:21:39 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <iostream>
#include <fstream>
using std::cout;
long putere(long x, long n)
{
if ( n == 1 ) return x % 1999999973;
if ( n % 2 ) return x * putere(x, n - 1 ) % 1999999973;
else return putere (x*x, n / 2) % 1999999973;
}
int main()
{
long N,P;
std::ifstream in("lgput.in");
std::ofstream out("lgput.out");
in >> N >> P;
N = putere(N, P );
out << N;
return 0;
}