Pagini recente » Cod sursa (job #3165283) | Cod sursa (job #90570) | Cod sursa (job #2359012) | Cod sursa (job #2461833) | Cod sursa (job #2300000)
#include <fstream>
using namespace std;
ifstream fin ("inversmodular.in");
ofstream fout ("inversmodular.out");
int euclidextins(int a, int b, int &x, int &y);
int cmmdc (int a, int b);
int a, b, c, hm, ceva, aux, x, y, n, i, p;
int main()
{
fin>>b>>p;
aux=euclidextins(p, b, ceva, x);
while (x<0)
x+=p;
fout<<x<<'\n';
return 0;
}
int euclidextins(int a, int b, int &x, int &y)
{
int x1, y1, d;
if (b==0)
{
x=1; y=0; return a;
}
d=euclidextins(b, a%b, x1, y1);
x=y1;
y=x1-(a/b)*y1;
return d;
}
int cmmdc (int a, int b)
{
if (b==0) return a;
return cmmdc (b, a%b);
}