Cod sursa(job #667258)
| Utilizator | Data | 22 ianuarie 2012 19:40:49 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 kb |
#include<fstream>
using namespace std;
int a,n;
long long x,y;
void euler(int a,int b,long long &x,long long &y)
{
if(b==0)
{
x=1;
y=0;
}
else
{
long long aux;
euler(b,a%b,x,y);
aux=x;
x=y;
y=aux-(a/b)*y;
}
}
int main()
{
FILE *f=fopen("inversmodular.in","r");
FILE *g=fopen("inversmodular.out","w");
fscanf(f,"%d%d",&a,&n);
euler(a,n,x,y);
while(x<0)
x=n+x%n;
fprintf(g,"%lld",x);
return 0;
}