Cod sursa(job #2720957)
| Utilizator | Data | 11 martie 2021 14:08:05 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <bits/stdc++.h>
#define mod 1999999973;
using namespace std;
int lgput(int base, int exponent){
if(exponent == 0) return 1;
if(exponent == 1) return base;
if(exponent % 2 == 0) return (1LL * lgput(base, exponent / 2) * lgput(base, exponent / 2)) % mod;
return (1LL * base * lgput(base, exponent / 2) * lgput(base, exponent / 2)) % mod;
}
int main(){
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int x, pow;
fin >> x >> pow;
fout << lgput(x, pow);
return 0;
}