Cod sursa(job #2764336)
| Utilizator | Data | 20 iulie 2021 13:52:32 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <iostream>
#include <fstream>
using namespace std;
int gcd(int a, int b, int &x, int &y) {
if (b==0) {
x = 1;
y = 0;
return a;
}
int x0, y0, d;
d = gcd(b, a%b, x0, y0);
x = y0;
y = x0 - (a/b)*y0;
return d;
}
int main()
{
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a, n;
fin>>a>>n;
for (int i = 1; i <= n-1; i++) {
int s = a+i;
if (n%s==1) {
fout<<i<<'\n';
break;
}
}
return 0;
}