Cod sursa(job #1629846)
| Utilizator | Data | 4 martie 2016 19:11:06 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
long long im,y;
int a,n;
void euclid(int a, int b, long long &x, long long &y)
{
if(b==0)
{
x=1; y=0;
}
else
{
long long x0,y0,d;
euclid(b,a%b,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
}
int main()
{
f>>a>>n;
euclid(a,n,im,y);
if(im<=0) im=n+im%n;
g<<im;
return 0;
}
