Cod sursa(job #1040992)
| Utilizator | Data | 25 noiembrie 2013 12:29:02 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int c, n;
void Euclid(int a, int b, int &x, int &y)
{
if(!b)
{
x = 1;
y = 0;
}
else
{
int x0, y0;
Euclid(b, a%b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main()
{
int x = 0, y;
fin>>c>>n;
Euclid(c, n, x, y);
if(x <= 0)
x = n + x % n;
fout<<x;
return 0;
}
