Pagini recente » Cod sursa (job #414812) | Cod sursa (job #1231686) | Cod sursa (job #2489893) | Cod sursa (job #2218473) | Cod sursa (job #2230276)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
void euclid(int &x,int &y,int a,int b){
if(!b){
x = 1;
y = 0;
return ;
}
euclid(x,y,b,a%b);
int newx = y;
int newy = x - y * (a/b);
x = newx;
y = newy;
}
int main()
{
int x,y,a,b,d;
in>>a>>b;
euclid(x,y,a,b);
x %= b;
if(x < 0)
x += b;
out<<x;
return 0;
}