Cod sursa(job #1052399)
Utilizator | Data | 11 decembrie 2013 11:19:42 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <cstdio>
using namespace std;
void euclid( long a, long b, long &x, long &y)
{
if(b==0)
{
x=1;
y=0;
}
else
{
long x0=0, y0=0;
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 A,N,X,Y;
cin>>A>>N;
euclid(A,N,X,Y);
while(X<0)
X+=N;
cout<<X;
return 0;
}