Cod sursa(job #2980339)
Utilizator | Data | 16 februarie 2023 12:56:03 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("inversmodular.in");
ofstream fout ("inversmodular.out");
long long pw (long long a, long long b, long long mod){
long long p = 1;
while (b > 0){
if (b & 1){
p = (p * a) % mod;
}
a = (a * a) % mod;
b >>= 1;
}
return p;
}
int main(){
ios_base::sync_with_stdio(false);
long long a, b; fin >> a >> b;
fout << pw(a, b - 2, b);
}