Pagini recente » Cod sursa (job #2699739) | Cod sursa (job #1274166) | Cod sursa (job #1849023) | Cod sursa (job #2242031) | Cod sursa (job #1928495)
#include <stdio.h>
using namespace std;
FILE*f=fopen("inversmodular.in","r");
FILE*g=fopen("inversmodular.out","w");
void inv(int &x,int &y,int a,int b)
{
if (b==0)
{
x=1;
y=0;
}
else
{
inv(x,y,b,a%b);
int aux=x;
x=y;
y=aux-a/b*y;
}
}
int main()
{
int a,n,x,y;
fscanf(f,"%d %d",&a,&n);
inv(x,y,a,n);
if (x<0) x=x+n;
x=x%n;
fprintf(g,"%d",x);
fclose(f);
fclose(g);
return 0;
}