Pagini recente » Cod sursa (job #1108639) | Cod sursa (job #1046580) | Cod sursa (job #2458160) | Cod sursa (job #2506147) | Cod sursa (job #544828)
Cod sursa(job #544828)
#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<<'\n';
F.close();
G.close();
return 0;
}