Pagini recente » Cod sursa (job #851231) | Cod sursa (job #940092) | Cod sursa (job #1940568) | Cod sursa (job #1123516) | Cod sursa (job #624058)
Cod sursa(job #624058)
#include<fstream>
using namespace std;
int A,N;
int ModN(int x)
{
int a=x%N;
if(a<0)
return (a+N);
return a;
}
void Euclid_extins(int a,int b,int &x,int &y)
{
if(b==0)
{
x=1;
y=0;
return;
}
else
{
Euclid_extins(b,a%b,x,y);
int aux,q=a/b;
aux=x;
x=y;
y=aux-y*q;
}
}
int main()
{
int inv=0,aux=0;
ifstream fin("inversmodular.in");
fin>>A>>N;
fin.close();
Euclid_extins(A,N,inv,aux);
ofstream fout("inversmodular.out");
fout<<ModN(inv)<<"\n";
fout.close();
return 0;
}