Pagini recente » Cod sursa (job #1711899) | Cod sursa (job #837825) | Cod sursa (job #1322057) | Cod sursa (job #831135) | Cod sursa (job #1679702)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
void gcd(int a, int b, int &x, int &y) {
if(b == 0) {
x = 1;
y = 0;
return;
}
int x0,y0;
gcd(b, a%b, x0, y0);
x = y0;
y = x0 - (a/b)*y0;
}
int main() {
int a,n,inv,y;
in >> a >> n;
gcd(a, n, inv, y);
inv = (inv+n)%n;
out << inv;
return 0;
}