def solution(n1: int, n2: int) -> bool:
# your code here
lis1 = [i for i in range(1, n1 + 1) if n1 % i == 0]
lis2 = [i for i in range(1, n2 + 1) if n2 % i == 0]
return True if set(lis1).intersection(lis2) == {1} else False
assert solution(20, 27) is True
assert solution(12, 39) is False
def solution(n1: int, n2: int) -> bool:
if n1 > n2:
n1, n2 = n2, n1
for i in range(2, n1 + 1):
if n1 % i == 0 and n2 % i == 0:
return False
return True
def solution(n1: int, n2: int) -> bool:
def factor_list(num: int) -> set:
s = set()
for i in range(1, int(num ** 0.5) + 1):
if num % i == 0:
j = num / i
s.update([i, j])
return s
new_set = factor_list(n1) & factor_list(n2)
if len(new_set) > 1:
return False
return True
assert solution(20, 27) is True
assert solution(12, 39) is False
assert solution(15, 98) is True
assert solution(18, 98) is False
def solution(n1: int, n2: int)-> bool:
rest1 = [i for i in range(1, n1) if n1 % i == 0]
rest2 = [i for i in range(1, n2) if n2 % i == 0]
if (set(rest1) & set(rest2) ) != {1}:
return False
return True
assert solution(20, 27) is True
assert solution(12, 39) is False
assert solution(15, 98) is True
assert solution(18, 98) is False
def solution(n1: int, n2: int) -> bool:
# your code here
tmp = n1 if n1 > n2 else n2
for i in range(2, tmp+1):
if n1 % i == 0 and n2 % i == 0:
return False
return True
assert solution(20, 27) is True
assert solution(12, 39) is False
assert solution(15, 98) is True
assert solution(18, 98) is False
def solution(n,m):
max_v=max(m,n)
min_v=min(m,n)
#欧几里得算法(辗转相除法)
#以除数和余数反复做除法运算,当余数为 0 时,取当前算式除数为最大公约数
while max_v % min_v != 0:
max_v,min_v = min_v,max_v%min_v
return min_v==1
#解法二
for i in range(2,n+1):
if n % i ==0 and m % i == 0:
return False
return True
def solution(n1: int, n2: int) -> bool:
n1_list=[i for i in range(1,n1+1) if n1%i==0]
n2_list=[i for i in range(1,n2+1) if n2%i==0]
return True if 1 in n1_list and 1 in n2_list and len(set(n1_list+n2_list))==len(n1_list)+len(n2_list)-1 else False
assert solution(20, 27) is True
assert solution(12, 39) is False
assert solution(15, 98) is True
assert solution(18, 98) is False