Cod sursa(job #3376779)
| Utilizator | Data | 19 noiembrie 2026 17:26:27 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void euclid(long long a , long long b , long long &x , long long &y){
if(b == 0){
x = 1;
y = 0;
}
else{
long long x1,y1;
euclid(b , a%b , x1 , y1);
x= y1;
y= x1 - (a/b) * y1;
}
}
int main()
{
long long a,n; fin>>a>>n;
long long x,y;
euclid(a,n,x,y);
// a*x + n*y == 1
// a*x % n== 1
fout<<(x%n+ n)%n;
return 0;
}