Pagini recente » Cod sursa (job #20357) | Cod sursa (job #1533632) | Cod sursa (job #582471) | Cod sursa (job #2747707) | Cod sursa (job #2047689)
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
long long t,i;
int gcd(long long a,long long b,long long &x,long long &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
long long x0,y0,d;
d=gcd(b,a%b,x0,y0);
x=y0;
y=x0-(a/b)*y0;
return d;
}
int main()
{
long long a,b,c;
f>>a>>b;
long long d,x,y;
d=gcd(a,b,x,y);
if (x <= 0)
x = b + x % b;
g<<x;
return 0;
}