Cod sursa(job #3225302)
| Utilizator | Data | 17 aprilie 2024 12:09:50 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <bits/stdc++.h>
#define QED fin.close(); fout.close(); return 0;
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
#define cin fin
#define cout fout
void EuclidExtins(int a, int b, int &d, int &x, int &y)
{
if(b == 0)
{
x = 1, y = 0, d = a;
}
else
{
int x0, y0;
EuclidExtins(b, a % b, d, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main()
{
int a,n,d,x,y;
cin>>a>>n;
EuclidExtins(a,n,d,x,y);
if(x<=0) x+=n;
cout<<x;
QED
}
