Pagini recente » ONIS 2015, Solutii Runda 1 | Cod sursa (job #1574193) | Cod sursa (job #1574393) | Cod sursa (job #40950) | 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;
}