Cod sursa(job #1428570)
| Utilizator | Data | 4 mai 2015 19:37:55 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
void cmmdc(int a, int b, int &x, int &y)
{
if(!b)
{
x = 1, y = 0;
return;
}
int q = a / b, x1, y1;
cmmdc(b, a % b, x1, y1);
x = y1;
y = x1 - q * y1;
}
int A, N;
int main()
{
in >> A >> N;
int x, y;
cmmdc(A, N, x, y);
while(x < 0)
x += N;
out << x << '\n';
return 0;
}
