Cod sursa(job #2673691)
Utilizator | Data | 17 noiembrie 2020 15:57:50 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#include <bits/stdc++.h>
using namespace std;
long long a, n, w, z;
void cmmdc(long long a,long long b,long long &x,long long &y)
{
if(b == 0){
x = 1;
y = 0;
}else{
int x0, y0;
cmmdc(b, a%b, x0, y0);
x = y0;
y = x0 - a/b*y0;
}
}
int main() {
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
scanf("%lld%lld", &a, &n);
cmmdc(a, n, w, z);
printf("%lld", w);
return 0;
}