def davenPort3(listValues): print('davenPort 3') x = int(listValues[0]) y = int(listValues[1]) z = int(listValues[2]) if x in [2, 3, 4, 6]: if int(x) == int(y): return compute_constant(listValues) elif ((x == 3) & (x < int(y)) & (y == int(z)) & (bltin_gcd(int(y / 3), 6) == 1)): return compute_constant(listValues) elif (x * (y**2) - (2 * y) - x - 2) <= z: return compute_constant(listValues) elif ((bltin_gcd(x, y) == 1) & (bltin_gcd(y, z) == 1)): values = [] prod = x * y * z values.append(prod) return davenPort1(values) return errorMessage() elif (x == y == z): list = decompose_number(x) if all(val == list[0] for val in list): return compute_constant(listValues) #if all(val == list[0] for val in list) & (int(list[0]) == 2) & (len(list)%5 == 0): # return compute_constant(lisValues) return errorMessage()
def primRoots(modulo): required_set = {num for num in range(1, modulo) if bltin_gcd(num, modulo)} return [ g for g in range(1, modulo) if required_set == {pow(g, powers, modulo) for powers in range(1, modulo)} ]
def calculate_k(order): rand = 0 while not bltin_gcd(rand, int(order)) == 1: rand = randint(1, order - 1) return rand
def davenPort2(listValues): x = int(listValues[0]) y = int(listValues[1]) if (checkListIsValid(listValues)): return compute_constant(listValues) elif (bltin_gcd(x, y) == 1): return x * y return errorMessage()
def main_process(): num = 0 limit = 12000 for d in range(2, limit + 1): for n in range(d // 3, d // 2 + 1): if (d > 2 * n) and (d < 3 * n) and bltin_gcd(n, d) == 1: num += 1 print(colored('mycount=', 'red'), num)
def numbers_are_co_prime(number1, number2): result = bltin_gcd(number1, number2) if result == 1: print("{} and {} are co-prime".format(number1, number2)) return True else: print( "{} and {} are not co-prime and can both be divided by {}".format( number1, number2, result)) return False
def __init__(self, a, b, mstr): from math import gcd as bltin_gcd super(T52, self).__init__() self.a = int(a) self.b = int(b) self.mstr = mstr self.m = len(mstr) assert (len(set(mstr)) == self.m), "alphabet has repeated symbols" assert (bltin_gcd(a, self.m) == 1), "{} and {} are not coprime".format( self.a, self.m)
def primRoots(_inprime): required_set = { num for num in range(1, _inprime) if bltin_gcd(num, _inprime) } return [ g for g in range(1, _inprime) if required_set == {pow(g, powers, _inprime) for powers in range(1, _inprime)} ]
def generate_keys(self, p, q): n = p * q totient = (p-1)*(q-1) e = 2 while(bltin_gcd(e, totient) != 1): e += 1 print("totient = {} e = {}".format(totient, e)) d = modinv(e, totient) print("d = ", d) return (e, n), (d, n)
def __init__(self): self.sharedPrime = sympy.randprime(1, 100) required_set = { num for num in range(1, self.sharedPrime) if bltin_gcd(num, self.sharedPrime) } self.sharedBase = random.choice([ g for g in range(1, self.sharedPrime) if required_set == { pow(g, powers, self.sharedPrime) for powers in range(1, self.sharedPrime) } ]) % self.sharedPrime self.secretKey = None self.encodedMessage = None
def solve(): """ this function considers 10 random values for m and n and returns the solutions for all the values between (1 and max(m)) """ count = 0 while count <= 10: m_choice = np.random.choice(list_m) n_choice = np.random.choice(list_n) # m should be be equal to n if m_choice != n_choice: if bltin_gcd(m_choice, n_choice) == 1: count = count + 1 for i in range(1, m_choice + 1): print(m_choice, n_choice, i) puzzle = WaterJug(initial_state, m_choice, n_choice, i) ans = iterative_deepening_search(puzzle) print(ans.path())
def _coprime2(a, b): return bltin_gcd(a, b) == 1
def coprime2(a, b): if a == 1 or b == 1: return False return bltin_gcd(a, b) == 1
def isCoprime(a, b): return bltin_gcd(a, b) == 1
def co1(a, b): return bltin_gcd(a, b) != 1
def are_relatively_prime(self, a, b): if bltin_gcd(a, b) == 1: return True return False
from itertools import permutations from math import gcd as bltin_gcd # Write your code here N = input() String_special = '47474747474747474744444444444' st1 = len(N)-len(String_special) if st1>0: for i in range(st1): String_special=String_special+'47' s2 = sorted([int(''.join(p)) for p in set(permutations(String_special,len(N)))]) SpecialList=[] for i in s2: if i <= int(N): SpecialList.append(i) for i in range(1,len(N)): s = sorted([int(''.join(p)) for p in set(permutations(String_special,i))]) SpecialList = SpecialList+s result=[] print(SpecialList) for i in range(len(SpecialList)): for j in range(i,len(SpecialList)): a=SpecialList[i] b=SpecialList[j] if bltin_gcd(a, b) == 1 and ((a,b) or(b,a)) not in result : result.append((SpecialList[i], SpecialList[j])) print(len(result))
def coprime(a, b): """Returns True if a is coprime to b, otherwise False""" return bltin_gcd(a, b) == 1
def check_solvability(self, state, m, n): """ Checks if m and n are co-prime""" return bltin_gcd(m, n) == 1
def is_coprime(self, a, b): return bltin_gcd(a, b) == 1
from math import gcd as bltin_gcd import random primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] for t in range(int(input())): n = int(input()) a = list(map(int, input().split()[:n])) c = 0 if (bltin_gcd(a[0], a[n - 1]) != 1): if (a[0] not in primes and bltin_gcd(a[0], a[n - 1]) != 1): ind = random.randint(0, 14) a[0] = primes[ind] c += 1 elif (a[n - 1] not in primes and bltin_gcd(a[0], a[n - 1]) != 1): ind = random.randint(0, 14) a[n - 1] = primes[ind] c += 1 for i in range(1, n): if (bltin_gcd(a[i - 1], a[i]) != 1): if (a[i - 1] not in primes and bltin_gcd(a[i - 1], a[i]) != 1): ind = random.randint(0, 14) a[i - 1] = primes[ind] c += 1 elif (a[i] not in primes and bltin_gcd(a[i - 1], a[i]) != 1): ind = random.randint(0, 14) a[i] = primes[ind] c += 1 print(c) for i in a: print(i, end=' ') print()
def checkcoprime(p, q): return bltin_gcd(p, q) == 1
def coprime2(a, b): # chech relative prime or not return bltin_gcd(a, b) == 1
def coprime(a: int, b: int) -> bool: return bltin_gcd(a, b) == 1
def coprime(a, b): """Function that checks if a and b are coprime""" return bltin_gcd(a, b) == 1
def coprime(a, b): return bltin_gcd(a, b) == 1
def co_prime(num, n_or_num_of_coprimes): return bltin_gcd(num, n_or_num_of_coprimes) == 1
def check_coprimality(a, b): return bltin_gcd(a, b) == 1
from math import gcd as bltin_gcd #import random #primes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47] for t in range(int(input())): n = int(input()) a = list(map(int, input().split()[:n])) flag = 0 i = 1 while ((i < n) and (bltin_gcd(a[0], a[i]) == 1)): i += 1 if (i == n): flag = 0 else: flag = 1 if (a[0] == 47): a[i] = 43 else: a[i] = 47 print(flag) for k in a: print(k, end=' ') print() '''if(bltin_gcd(a[0],a[n-1])!=1): if(a[0] not in primes and bltin_gcd(a[0],a[n-1])!=1): ind=random.randint(0,14) a[0]=primes[ind] c+=1 elif(a[n-1] not in primes and bltin_gcd(a[0],a[n-1])!=1): ind=random.randint(0,14) a[n-1]=primes[ind]