Cod sursa(job #1275376)
| Utilizator | Data | 25 noiembrie 2014 02:17:49 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <fstream>
using namespace std;
void cmmdc (int a, int b, int& x, int& y)
{
if (b == 0)
{
x = 1;
y = 0;
return;
}
int x0, y0;
cmmdc(b, a%b, x0, y0);
x = y0;
y = x0 - (a/b) * y0;
}
int main()
{
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
int a, b, x, y;
in>>a>>b;
cmmdc(a, b, x, y);
while(x<0)
x+=b;
out<<x;
in.close();
out.close();
return 0;
}
