Cod sursa(job #3350421)
| Utilizator | Data | 7 aprilie 2026 18:44:48 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int euclidExtins(int a, int b, int &x, int &y){
if(b == 0){
x = 1;
y = 0;
return a;
}
int x0, y0;
int d = euclidExtins(b, a%b, x0, y0);
x = y0;
y = x0 - (a/b)*y0;
return d;
}
int main(){
int a,n, x, y;
fin >> a >> n;
euclidExtins(a,n,x,y);
while(x < 0){
x += n;
}
fout << x;
return 0;
}