Cod sursa(job #3185271)
Utilizator | Data | 18 decembrie 2023 17:22:23 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.55 kb |
#include <bits/stdc++.h>
#define MOD 1999999973
#define int long long
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int a, b;
int fast_pow(int a, int b){
int rez = 1;
a %= MOD;
b %= MOD;
while(b){
if(b % 2 == 1){
rez *= a;
rez %= MOD;
}
a = ((a % MOD) * (a % MOD)) % MOD;
b /= 2;
}
return rez;
}
int32_t main(){
fin >> a >> b;
fout << fast_pow(a, b) << "\n";
return 0;
}