Pagini recente » Rating Balan Felix Adrian (Lopimank) | Cod sursa (job #2562229) | Cod sursa (job #946891) | Cod sursa (job #2390181) | Cod sursa (job #544824)
Cod sursa(job #544824)
#include<fstream.h>
ifstream F("inversmodular.in");
ofstream G("inversmodular.out");
long long x,y;
int A,B;
void f(long long &x, long long &y, int A,int B)
{if(B==0) x=1,y=0;
else { f(x,y,B,A%B);
long long z=x;
x=y;
y=z-y*(A/B);
}
}
int main ()
{F>>A>>B;
f(x,y,A,B);
if(x<=0) x=B-x%B;
G<<x;
F.close();
G.close();
return 0;
}