Nu aveti permisiuni pentru a descarca fisierul grader_test8.ok
Cod sursa(job #2000481)
Utilizator | Data | 13 iulie 2017 19:43:47 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
int a, b, d, t, x, y;
void f(int a, int b, int &d, int &x, int &y)
{
if(b == 0)
d = a, x = 1, y = 0;
else
{
int nr1, nr2;
f(b, a % b, d, nr1, nr2);
x = nr2, y = nr1 - (a / b) * nr2;
}
}
int main()
{
in >> a >> b;
f(a, b, d, x, y);
if(x < 0)
x = x + (x / b + 1) * b;
out << x;
return 0;
}