Cod sursa(job #3199068)
Utilizator | Data | 31 ianuarie 2024 17:04:35 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a, n;
static inline int Put(int a, int n, int mod) {
long long p = 1;
while(n) {
if(n & 1) p = (p * a) % mod;
a = (a * a) % mod;
n >>= 1;
}
return p;
}
int main() {
cin >> a >> n;
cout << Put(a, n - 2, n);
return 0;
}