Cod sursa(job #377299)

Utilizator ChallengeMurtaza Alexandru Challenge Data 23 decembrie 2009 22:52:24
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <fstream>

using namespace std;

const char InFile[]="inversmodular.in";
const char OutFile[]="inversmodular.out";

long long int a,n,x,y;

void gcd(long long int a,long long int b)  
{  
	if(!b){  
		x=1;
		y=0;  
	}else{             
		gcd(b,a%b);
		long long int aux=x;
		x=y;
		y=aux-y*(a/b);
	}
}

int main()
{
    ifstream fin(InFile);
    fin>>a>>n;
	fin.close();
	
    gcd(a,n);
    if(x<=0){
       x=n+x%n;
	}
	
	ofstream fout(OutFile);
	fout<<x;
	fout.close();
    return 0;
}