Pagini recente » Cod sursa (job #238116) | Cod sursa (job #2705115) | Cod sursa (job #3000886) | Cod sursa (job #2194459) | Cod sursa (job #846195)
Cod sursa(job #846195)
#include<iostream>
#include<fstream>
using namespace std;
inline void gcd(int a, int b, int &x, int &y)
{
if(b==0) {
x=1;
y=0;
}
else {
int x0,y0;
gcd(b,a%b,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
}
int main ()
{
int a,n,x,y;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
f>>a>>n;
f.close();
gcd(a,n,x,y);
while(x<=0)
x=x+n;
if(x==n)
x=0;
g<<x;
g.close();
return 0;
}