Your IP : 216.73.216.40


Current Path : /var/www/html/venkat/check/
Upload File :
Current File : /var/www/html/venkat/check/gcd.py

def gcd(a,b):
	while a:
		a, b = b%a, a
	return a 

def modinv(a,m):
	gcd , x, y = egcd(a,m)
	if gcd != 1:
		return 0  # modular inverse does not exist
	else:
		return x % m

def egcd(a,b):
	x,y, u,v = 0,1, 1,0
	while a != 0:
		q, r = b//a, b%a
		m, n = x-u*q, y-v*q
		b,a, x,y, u,v = a,r, u,v, m,n
	gcd = b
	return gcd, x, y
kk = input("f: ")
pp = input("p: ")
print modinv(kk,pp)