Pagini recente » Cod sursa (job #1834886) | Cod sursa (job #3264128) | Cod sursa (job #3248576) | Cod sursa (job #1061262) | Cod sursa (job #1688399)
#include <bits/stdc++.h>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int a,n,d,x,y,c;
int euclid(int a,int b,int &x, int &y){
if(b == 0){
x = 1;
y = 0;
return a;
}
int x0,y0;
d = euclid(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
int main()
{
f >> a >> n;
d = euclid(a,n,x,y);
if(x < 0)
x = n + x % n;
g << x;
return 0;
}