Pagini recente » Cod sursa (job #278132) | Cod sursa (job #2266251) | Cod sursa (job #2760882) | Diferente pentru documentatie/conventii-de-formatare intre reviziile 3 si 2 | Cod sursa (job #544781)
Cod sursa(job #544781)
#include <fstream.h>
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int a,n;
void e(long long &x, long long &y, int a,int b)
{
if(b==0) x=1,y=0;
else
{
e(x,y,b,a%b);
long long c=x;
x=y;
y=c-y*(a/b);
}
}
int main()
{
f>>a>>n;
long long x=0,y=0;
e(x,y,a,n);
if(x<=0) x=n+x%n;
g<<x;
}