Cod sursa(job #3223990)
Utilizator | Ioja Andrei-Iosif dey44and | Data | 14 aprilie 2024 11:50:23 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
using namespace std;
ifstream cin("lgput.in");
ofstream cout("lgput.out");
long long fast_exp(long long base, long long exp, long long mod) {
exp = exp % (mod - 1);
long long result = 1;
while(exp) {
if(exp & 1)
result = result * base % mod;
base = base * base % mod;
exp >>= 1;
}
return result;
}
int main() {
long long base, exp;
const long long mod = 1999999973;
cin >> base >> exp;
cout << fast_exp(base, exp, mod);
return 0;
}