Cod sursa(job #1400401)
| Utilizator | Data | 25 martie 2015 11:41:18 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include <cstdio>
using namespace std;
void euclid(long long a,long long b,long long &x,long long &y)
{
if(b==0)
{
x=1;
y=0;
}
else
{
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);
long long a,n,x,y;
scanf("%lld%lld",&a,&n);
euclid(a,n,x,y);
while(x<=0)
x+=n;
if(x==n)
printf("%lld",n);
else
printf("%lld",x%n);
return 0;
}
