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