首页 > 其他 > 详细

HackerRank - "Sherlock and GCD"

时间:2015-03-12 06:23:07      阅读:295      评论:0      收藏:0      [点我收藏+]

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")

HackerRank - "Sherlock and GCD"

原文:http://www.cnblogs.com/tonix/p/4331426.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!