Cod sursa(job #3274597)
Utilizator | Data | 7 februarie 2025 14:07:25 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <bits/stdc++.h>
#define int long long
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a, mod;
int power(int b, int e){
int ret = 1;
while(e){
if(e % 2 == 1)
ret = (ret * b) % mod;
b = (b * b) % mod;
e /= 2;
}
return ret % mod;
}
int32_t main(){
fin >> a >> mod;
fout << power(a, mod-2);
}