Pagini recente » Cod sursa (job #2422311) | Cod sursa (job #1469073) | Cod sursa (job #846865) | Cod sursa (job #2050975) | Cod sursa (job #1371208)
#include <fstream>
using namespace std;
void euclid(int a,int b,int& x,int& y){
if(b == 0){
x = 1;
y = 0;
return;
}
else{
int x0,y0;
euclid(b,a%b,x0,y0);
x = y0;
y = x0 - (a/b) * y0;
return;
}
}
int main()
{
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int A,B;
fin >> A >> B;
int x,y;
euclid(A,B,x,y);
while(x < 0) x += B;
fout << x;
}