Cod sursa(job #666961)
Utilizator | Data | 22 ianuarie 2012 14:50:39 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include<fstream>
using namespace std;
unsigned long long a,n,x,y;
inline void euclid(unsigned long long a, unsigned long long b, unsigned long long &x,unsigned long long &y)
{
if(b==0)
{
x=1;
y=0;
}
else
{ unsigned long long x0,y0;
euclid(b,a%b,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
}
int main()
{
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
scanf("%lld %lld",&a,&n);
euclid(a,n,x,y);
if(x<0)
x=n+x%n;
printf("%lld",x);
return 0;
}