Cod sursa(job #2377995)

Utilizator Silviu.Stancioiu@gmail.comSilviu Stancioiu [email protected] Data 11 martie 2019 15:50:37
Problema Invers modular Scor 50
Compilator c-64 Status done
Runda Arhiva educationala Marime 0.55 kb
#include <stdio.h>

typedef long long ll;

FILE* fin;
FILE* fout;

void Euclid(ll a, ll b, ll* d, ll* x, ll* y)
{
	if (b == 0)
	{
		*d = a;
		*x = 1;
		*y = 0;
	}
	else
	{
		ll x0, y0;
		Euclid(b, a % b, d, &x0, &y0);
		*x = y0;
		*y = (*d - (a * (*x))) / b;
	}
}

int main(void)
{
	ll a, n;
	ll d, x, y;

	fin = fopen("inversmodular.in", "r");
	fout = fopen("inversmodular.out", "w");

	fscanf(fin, "%lld %lld", &a, &n);

	Euclid(a, n, &d, &x, &y);

	fprintf(fout, "%lld", x);

	fclose(fin);
	fclose(fout);

	return 0;
}