Cod sursa(job #1685845)
| Utilizator | Data | 11 aprilie 2016 21:26:59 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int n, k;
void euclid(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1, y = 0;
return;
}
int xx = 0, yy = 0;
euclid(b, a%b, xx, yy);
x = yy;
y = xx - (a/b)*yy;
}
int main()
{
int x = 0, y = 0;
f >> n >> k;
euclid(n, k, x, y);
if (x <= 0)
x = (x+k)%k;
g << x;
return 0;
}
