Cod sursa(job #878502)
Utilizator | Spinei Dionis SPDionis | Data | 14 februarie 2013 15:30:20 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <iostream>
#include <fstream>
using std::cout;
long long putere(long long x, long long n)
{
x = x % 1999999973;
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 long N,P;
std::ifstream in("lgput.in");
std::ofstream out("lgput.out");
in >> N >> P;
N = putere(N, P );
out << N;
return 0;
}