Pagini recente » Cod sursa (job #1359011) | Cod sursa (job #997253) | Cod sursa (job #586611) | Cod sursa (job #432265) | Cod sursa (job #902878)
Cod sursa(job #902878)
#include <fstream>
#define LL long long
using namespace std;
inline void euclid(LL&x,LL&y,LL a,LL b)
{
if(!b)
{
x=1;
y=0;
return;
}
LL X,Y;
euclid(X,Y,b,a%b);
x=Y;
y=X-(a/b)*Y;
}
int main()
{
LL x,y,a,b;
ifstream fin("inversmodular.in");
fin>>a>>b;
fin.close();
euclid(x,y,a,b);
ofstream fout("inversmodular.out");
fout<<(x%b+b)%b<<'\n';
fout.close();
return 0;
}