Pagini recente » Cod sursa (job #592762) | Cod sursa (job #2522230) | Cod sursa (job #2185723) | Borderou de evaluare (job #1450143) | Cod sursa (job #2181205)
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void gcd(int a, int b, int &x, int &y){
if(b == 0)
{
x = 1;
y = 0;
return;
}
gcd(b, a%b, x, y);
int aux = x;
x = y;
y = aux - (a/b) * y;
}
int main()
{
int a, n;
fin >> a >> n;
int x = 0;
int y = 0;
gcd(a, n, x, y);
while(x < 1)
{
x += n;
}
fout << x;
return 0;
}