Pagini recente » Cod sursa (job #2511797) | Cod sursa (job #2900150) | Cod sursa (job #1379268) | Cod sursa (job #2460536) | Cod sursa (job #2147324)
#include <fstream>
using namespace std;
ofstream fout("inversmodular.out");
ifstream fin("inversmodular.in");
void gcd(int a, int b, int &x, int &y){
if(b == 0){
x = 1;
y = 0;
return;
}
gcd(b, a%b, x, y);
int aux = x;
x = y;
y = aux - (a/b) * y;
}
int main()
{
int a, n;
fin >> a >> n;
int x = 0;
int y = 0;
gcd(a, n, x, y);
while(x < 1){
x += n;
}
fout << x;
return 0;
}