HackerRank

This is a very smart observation:
http://www.martinkysel.com/hackerrank-sherlock-and-gcd-solution/

# http://www.martinkysel.com/hackerrank-sherlock-and-gcd-solution/
#
from functools import reduce

def gcd(a, b):
    if a == 1 or b == 1:
        return 1
    if a % b == 0:
        return b
    return gcd(b, a % b)
    
def multiple_gcd(arr):
    return reduce(lambda x,y: gcd(x, y), arr)
    
#################
T = int(input())
for i in range(0,T):
    n = int(input())
    arr = list(map(int, input().split()))
    if len(arr) < 2:
        print ("NO")
        continue
    if (multiple_gcd(arr) == 1):
        print ("YES")
    else:
        print ("NO")
原文地址:https://www.cnblogs.com/tonix/p/4331426.html