Cod sursa(job #2270548)
| Utilizator | Data | 27 octombrie 2018 11:30:37 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 50 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <iostream>
#include <fstream>
using namespace std;
void euclid(int a, int b, int &d, int &x, int &y)
{
if (b == 0)
{
if (d%a!=0)
x=0;
else
x = d/a;
y = 0;
}
else
{
int x0, y0;
euclid(b, a % b, d, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main()
{
ifstream fin ("inversmodular.in");
ofstream fout ("inversmodular.out");
int a,n,c,x,y;
fin>>a>>n;
c=1;
euclid(a, n, c, x, y);
fout<<x<<'\n';
return 0;
}
