Pagini recente » Cod sursa (job #2808000) | Cod sursa (job #2847230) | Cod sursa (job #378774) | Cod sursa (job #372710) | 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;
}