Cod sursa(job #963464)
| Utilizator | Data | 17 iunie 2013 15:51:54 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <cstdlib>
#include <fstream>
using namespace std;
inline void gcd(int a, int b, int& x, int& y)
{
if(!b)
{
x = 1;
y = 0;
}
else {
int x0, y0;
gcd(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main()
{
int A, N, x, y;
ifstream in("inversmodular.in");ofstream out("inversmodular.out");in >> A >> N;gcd(A, N, x, y);if(x < 0) x += N;out << x << '\n';return EXIT_SUCCESS;}