Browse Source

Solved Sherlock and GCD

main
Titouan Rigoudy 11 years ago
parent
commit
8a8c8b4dba
1 changed files with 25 additions and 0 deletions
  1. +25
    -0
      sherlock_and_gcd/sherlock_and_gcd.py

+ 25
- 0
sherlock_and_gcd/sherlock_and_gcd.py View File

@ -0,0 +1,25 @@
#!/usr/bin/python3
# https://www.hackerrank.com/challenges/sherlock-and-gcd
import sys
from fractions import gcd
def gcd_all(numbers):
res = 0
for n in numbers:
res = gcd(res, n)
return res
def main():
T = int(sys.stdin.readline())
for _ in range(T):
N = int(sys.stdin.readline())
A = [ int(x) for x in sys.stdin.readline().split() ]
if gcd_all(A) == 1:
print('YES')
else:
print('NO')
if __name__ == '__main__':
main()

Loading…
Cancel
Save