Cod sursa(job #1657766)
| Utilizator | Data | 20 martie 2016 19:45:10 | |
|---|---|---|---|
| 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");
int a, n, x1, y1;
void cmmdc(int a, int b, int &x, int &y)
{
if (b == 0)
x = 1, y = 0;
else
{
int xx = 0, yy = 0;
cmmdc(b, a%b, xx, yy);
x = yy;
y = xx-(a/b)*yy;
}
}
int main()
{
f >> a >> n;
cmmdc(a, n, x1, y1);
if (x1 <= 0)
x1 = n+x1%n;
g << x1;
return 0;
}
