Pagini recente » Cod sursa (job #922129) | Cod sursa (job #2235558) | Cod sursa (job #513876) | Cod sursa (job #1900308) | Cod sursa (job #2038090)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("inversmodular.in");
ofstream g ("inversmodular.out");
void euclid(int a,int b,int &x,int &y)
{
if(b == 0)
{
x = 1; y = 0;
return;
}
int x0, y0;
euclid(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b)*y0;
}
int main()
{
int a,mod,x , y;
f >> a >> mod;
euclid(a , mod, x , y);
if(x < 0)
x = x % mod + mod;
g << x;
return 0;
}