Pagini recente » Cod sursa (job #1896157) | Cod sursa (job #1314846) | Cod sursa (job #1453831) | Cod sursa (job #2297103) | Cod sursa (job #1653120)
// inversmodular.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include <fstream>
using namespace std;
int inversmodular(long long a, long long n)
{
int x = 1, x2 = 0;
int y = 0, y2 = 1;
while (n != 0)
{
int c = a / n;
int r = a % n;
a = n;
n = r;
int xnou, ynou;
xnou = x - c * x2;
ynou = y - c * y2;
x = x2;
y = y2;
x2 = xnou;
y2 = ynou;
}
return x;
}
int main()
{
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
long long a, n;
fin >> a >> n;
fout << inversmodular(a, n);
return 0;
}