Cod sursa(job #3202906)

Utilizator Letitia_MilkoLetitia Marin Letitia_Milko Data 12 februarie 2024 16:55:48
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.44 kb
#include<bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
typedef long long int ll;
ll euclid(ll a,ll mod,ll &x,ll &y)
{
	if(mod==0)
	{
		x=1;
		y=0;
		return a;
	}
	else {
		ll p,q;
		int r=euclid(mod,a%mod,p,q);
		x=q;
		y=p-q*(a/mod);
		return r;
	}
}
int main()
{
	ll a,mod,aux,inv;
	fin>>a>>mod;
	ll i=euclid(a,mod,inv,aux);
	while(inv<=0) inv+=mod;
	fout<<inv;
}