Cod sursa(job #1216509)
Utilizator | Data | 4 august 2014 18:53:44 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("lgput.in");
ofstream g ("lgput.out");
const int MOD = 1999999973;
unsigned long long n, p;
unsigned long long putere(unsigned long long n, unsigned long long p) {
if (p) {
int x = putere(n, p / 2); x = (x * x) % MOD;
if (p % 2) x = (x * n) % MOD;
return x % MOD;
}
return 1;
}
int main () {
f >> n >> p;
n = n % MOD;
g << putere(n, p) << '\n';
return 0;
}