Pagini recente » Cod sursa (job #2171465) | Cod sursa (job #227367) | Cod sursa (job #1199430) | Cod sursa (job #1073763) | Cod sursa (job #1819973)
#include<iostream>
#include<fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
long long x, y;
long long a, n;
void Inverse(long long a, long long b, long long & x, long long & y)
{
if(b == 0){
x = 1;
y = 0;
return;
}
Inverse(b, a%b, x, y);
swap(x, y);
y = y - (a / b)*x;
}
int main()
{
f>>a>>n;
Inverse(a, n, x, y);
if(x < 0)
x = n + x % n;
g<<x<<"\n";
return 0;
}