Pagini recente » Cod sursa (job #70842) | Cod sursa (job #309973) | Cod sursa (job #1956396) | Cod sursa (job #2743160) | Cod sursa (job #2685100)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int Euclid(int a, int b, long long &x, long long &y){
if (b == 0){
x = 1;
y = 0;
return a;
}
else{
long long x0, y0;
int d = Euclid(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
}
int main(){
int a, n;
fin >> a >> n;
long long x, y, d;
d = Euclid(a, n, x, y);
while (x < 0) x = x + n * 100;
x = x % n;
fout << x;
fin.close();
fout.close();
return 0;
}