Cod sursa(job #415019)

Utilizator victor.ionescuIonescu Victor Cristian victor.ionescu Data 10 martie 2010 20:36:45
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.44 kb
#include <stdio.h>
long long A,N;

void gcd(long long &cx,long long &cy,long long x,long long y){
	if (y==0){
		cx=1;
		cy=0;
		return ;
	}
	gcd(cx,cy,y,x%y);
	int cp=cx;
	cx=cy;
	cy=cp-cy*(x/y);
}

int main(){

	freopen("inversmodular.in","r",stdin);
	freopen("inversmodular.out","w",stdout);

	scanf("%lld%lld",&A,&N);

	fclose(stdin);

	long long cx,cy;

	gcd(cx,cy,A,N);

	if (cx<0) cx=(cx%N)+N;

	printf("%lld\n",cx);

	fclose(stdout);

	return 0;
}