Cod sursa(job #1928490)
Utilizator | Data | 16 martie 2017 13:23:38 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#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);
fprintf(g,"%d",x);
fclose(f);
fclose(g);
return 0;
}