Cod sursa(job #630142)
Utilizator | Data | 4 noiembrie 2011 19:27:22 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include <stdio.h>
long a,n;
long long x,y,c;
void euclid(long long a, long long b)
{
if(!b)x=1,y=0;
else
{euclid(b,a%b);
c=x;x=y;y=c-y*(a/b);}}
int main()
{
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
scanf("%ld%ld",&a,&n);
euclid(a,n);
if(x<1)x=n+x%n;
printf("%lld\n",x);
return 0;
}