Pagini recente » Cod sursa (job #1725825) | Cod sursa (job #2228933) | Cod sursa (job #664785) | Cod sursa (job #655302) | Cod sursa (job #3183279)
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void gcd(long long a, long long b, long long& x, long long& y)
{
if(!b)
{
x=1, y=0;
return;
}
else {
long long xx, yy;
gcd(b, a%b, xx, yy);
x=yy;
y=xx-(a/b)*yy;
}
}
long long a, n, rez, y;
int main()
{
ios_base::sync_with_stdio(false);
fin.tie(0);
fin>>a>>n;
fin.close();
gcd(a, n, rez, y);
while(rez < 0)
rez+=n;
fout<<rez;
fout.close();
return 0;
}