1 import fractions, functools, sys 2 3 4 if __name__ == '__main__': 5 T = int(sys.stdin.readline()) 6 7 for _ in range(T): 8 N = int(sys.stdin.readline()) 9 A = list(map(int, sys.stdin.readline().split())) 10 11 gcd = functools.reduce(fractions.gcd, A) # reduce函数的理解 12 print('YES' if gcd == 1 else 'NO')
Link:
https://www.hackerrank.com/challenges/sherlock-and-gcd
学习:
深度抽象问题
不断地抽象问题的本质,层级越高,越简单!
reduce
循环apply fuc
gcd
greatest commen diviosr
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)