Cod sursa(job #1714069)

Utilizator valentin50517Vozian Valentin valentin50517 Data 7 iunie 2016 12:21:07
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.35 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
typedef long long ll;
void gcd(ll &x,ll &y,ll a,ll b){
	if(!b) x = 1, y = 0;
	else{
		gcd(x,y,b,a%b);
		ll aux = x;
		x = y;
		y = aux - y*(a/b);
	}
}

ll N,A,X,Y;
int main(){
	fin >> A >> N;
	gcd(X,Y,A,N);
	while(X <= 0) X=N+X%N;
	fout << X;
}