Cod sursa(job #878478)
Utilizator | Data | 14 februarie 2013 15:20:25 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <iostream>
#include <fstream>
using std::cout;
long putere(long x, long n)
{
x = x % 1999999973;
if ( n == 1 ) return x;
if ( n % 2 ) return x * putere(x, n - 1 );
else return putere (x*x, n / 2);
}
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;
}