Common Divisor
You are given a sequence of integers. You want to find out if all the numbers have a common divisor.
If there exists such a number, print "YES", otherwise print "NO".
If there exists such a number, print "YES", otherwise print "NO".
Input Format:
The first line of the input contains an integer N, denoting the number of elements in the array.
The second line contains N space-separated integers.
The first line of the input contains an integer N, denoting the number of elements in the array.
The second line contains N space-separated integers.
Output Format:
Print "YES" or "NO" on a single line(without quotes) according to the above condition.
Print "YES" or "NO" on a single line(without quotes) according to the above condition.
Example:
Input:
3
2 3 4
Output:
NO
Input:
5
5 10 15 20 25
Output:
YES
5
5 10 15 20 25
Output:
YES
CODE::
n=int(input())a=list(map(int,input().split()))
b=min(a)
divi=1
count=0
for i in range(2,b+1):
count=0
for j in range(n):
if a[j]%i==0:
count+=1
if count==n:
divi=i
if divi==1:
print("NO")
else:
print("YES")
No comments:
Post a Comment