Pagini recente » Cod sursa (job #2693723) | Cod sursa (job #1209153) | Rating SpiruHaret Enache Feleaga Postu (nu_stiu) | Borderou de evaluare (job #3291080) | Cod sursa (job #2830952)
#include <bits/stdc++.h>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
void euclid(int a, int b, int &x, int &y)
{
if(!b)
{
x = 1;
y = 0;
}
else
{
int x1,y1;
euclid(b, a%b, x1,y1);
x = y1;
y = x1 - (a/b)*y1;
}
}
int main()
{
int a, n,d,x,y;
f>>a>>n;
euclid(a,n,x,y);
while(x < 0)
x = x+n;
g<<x;
return 0;
}