Mai intai trebuie sa te autentifici.
Cod sursa(job #1792163)
| Utilizator | Data | 30 octombrie 2016 09:24:00 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.62 kb |
#include <iostream>
#include <fstream>
const long long MOD = 1999999973;
long long power(long long x, long long n){
if(n == 0){
return 1;
}
if(n == 1){
return x % MOD;
}
if(n % 2 == 0){
return ((power(x, n / 2) % MOD) * (power(x, n / 2) % MOD)) % MOD;
}
if(n % 2 == 1){
return ((x % MOD) * (power(x, (n - 1) / 2) % MOD) * (power(x, (n - 1) / 2) % MOD)) % MOD;
}
}
int main(){
std::ifstream fin("lgput.in");
std::ofstream fout("lgput.out");
long long n, p;
fin >> n >> p;
fout << power(n, p);
fin.close();
fout.close();
return 0;
}
