my-prime

Recently you invented a brand-new definition of prime numbers. For a given set of positive integers S let's call X a prime if there are no elements in S which are divisors of X (except  X itself).

You are given a set S. Find elements in it which are prime numbers for this set.

Input
The first line contains one integer N - size of the set S.
The second line contains N space-separated integers - elements of S. All the numbers are pairwise different.

Output
Output one line: elements of S which are prime numbers for this set in the order they occur in the input. Separate them by whitespaces.

Constraints
N ≤ 100
1 ≤ S[i] ≤ 10^6 (1 ≤ i ≤ n)

SAMPLE INPUT
5
10 5 3 15 16

SAMPLE OUTPUT
 5 3 16

Difficulty: EASY
Tags: Fundamentals

Complete search
Skill types: Complete search

Starter code:

Solutions:
'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
n = eval(input())
arr = input().split(" ")
res = str()
for i in range(len(arr)):
	flag = 1
	for j in range(len(arr)):
		if i==j:
			continue
		elif int(arr[i])%int(arr[j])==0:
			flag =0
			break
	if flag == 1:
		res += " %s" % arr[i]
print(res)

	



lmt = eval(input())
rng = [int(x) for x in input().split()]


for num in rng:
	if num >= 1:
		for i in rng:
			if num == i:
				continue
			elif num % i == 0:
				break
		else:
			print(num, end=' ')



'''
Created on Apr 7, 2016

@author: ACER
'''
def get_prime(length_of_set, num_set):
	"""Return all primes in set"""
	num_set = num_set.split(' ')
	num_set = list(map(int, num_set))
	prime_list = [] #list to store all prime numbers
	for num in num_set:
		for all_num in num_set:
			if num % all_num == 0 and num != all_num:
				prime_list.append(num)
				break
	prime_list = [str(num) for num in num_set if num not in prime_list]
	return prime_list

if __name__ == '__main__':
	LEN_OF_SET = eval(input(""))
	SET = input("")
	print(" ".join(get_prime(LEN_OF_SET, SET)))


'''
Created on Apr 7, 2016

@author: ACER
'''
def get_prime(length_of_set, num_set):
	"""Return all primes in set"""
	num_set = num_set.split(' ')
	num_set = list(map(int, num_set))
	prime_list = [] #list to store all prime numbers
	for num in num_set:
		for all_num in num_set:
			if num % all_num == 0 and num != all_num:
				prime_list.append(num)
				break
	prime_list = [str(num) for num in num_set if num not in prime_list]
	return prime_list

if __name__ == '__main__':
	LEN_OF_SET = eval(input(""))
	SET = input("")
	print(" ".join(get_prime(LEN_OF_SET, SET)))


'''
Created on Apr 7, 2016

@author: ACER
'''
def get_prime(length_of_set, num_set):
	"""Return all primes in set"""
	num_set = num_set.split(' ')
	num_set = list(map(int, num_set))
	prime_list = [] #list to store all prime numbers
	for num in num_set:
		for all_num in num_set:
			if num % all_num == 0 and num != all_num:
				prime_list.append(num)
				break
	prime_list = [str(num) for num in num_set if num not in prime_list]
	return prime_list

if __name__ == '__main__':
	LEN_OF_SET = eval(input(""))
	SET = input("")
	print(" ".join(get_prime(LEN_OF_SET, SET)))


'''
Created on Apr 7, 2016

@author: ACER
'''
def get_prime(length_of_set, num_set):
	"""Return all primes in set"""
	num_set = num_set.split(' ')
	num_set = list(map(int, num_set))
	prime_list = [] #list to store all prime numbers
	for num in num_set:
		for all_num in num_set:
			if num % all_num == 0 and num != all_num:
				prime_list.append(num)
				break
	prime_list = [str(num) for num in num_set if num not in prime_list]
	return prime_list

if __name__ == '__main__':
	LEN_OF_SET = eval(input(""))
	SET = input("")
	print(" ".join(get_prime(LEN_OF_SET, SET)))


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
length=int(input())
array=list(map(int,input().split()))
primelist=[]
flag=0
for i in range(0,len(array)):
	flag=0
	for j in range(0,len(array)):
		if array[i]%array[j]==0:
			if i!= j:
				flag=1;
	if flag==0:
		primelist.append(array[i])
for value in primelist:
	print(value, end=' ')
			



N = eval(input())
suspects = list(map(int, input().split(" ")))
no_primes = []

for i in range(N):
	for j in range(N):
		if suspects[i] != suspects[j] and suspects[i] % suspects[j] == 0:
			no_primes.append(suspects[i])
			break
answers = []
for item in suspects:
	if item not in no_primes:
		print(item, end=' ')




n=eval(input())
numbers=list(map(int,input().split()))
k=0
leng=n
arr=[]
temp=numbers

for item in temp:
	i=0
	for it in temp:
		if item%it==0:
			i=i+1
			
	if i==1:
		print(item, end=' ')


import sys

res = []
n = int(input())
lst = list(map(int, input().split()))
for num in lst:
	flag = 1
	remove_list = []
	for m in res:
		if not (num % m and m % num):
			if m > num:
				remove_list.append(m)
			else:
				flag = 0
				break
	l3 = [x for x in res if x not in remove_list]
	res = l3
	if flag:
		res.append(num)
for m in res:
	sys.stdout.write(str(m) + " ")


import sys

res = []
n = int(input())
lst = list(map(int, input().split()))
for num in lst:
	flag = 1
	remove_list = []
	for m in res:
		if not (num % m and m % num):
			if m > num:
				remove_list.append(m)
			else:
				flag = 0
				break
	l3 = [x for x in res if x not in remove_list]
	res = l3
	if flag:
		res.append(num)
for m in res:
	sys.stdout.write(str(m) + " ")


'''
Created on Apr 7, 2016

@author: ACER
'''
def get_prime(length_of_set, num_set):
	"""Return all primes in set"""
	num_set = num_set.split(' ')
	num_set = list(map(int, num_set))
	prime_list = [] #list to store all prime numbers
	for num in num_set:
		for all_num in num_set:
			if num % all_num == 0 and num != all_num:
				prime_list.append(num)
				break
	prime_list = [str(num) for num in num_set if num not in prime_list]
	return prime_list

if __name__ == '__main__':
	LEN_OF_SET = eval(input(""))
	SET = input("")
	print(" ".join(get_prime(LEN_OF_SET, SET)))


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
n = int(input())
li = list(map(int, input().split()))
flag = 0
for i in range(len(li)):
	flag = 1
	for j in range(len(li)):
		if i != j and li[i] % li[j] ==0:
			flag=0
			break
	if flag:
			print(li[i], end=' ')


n=eval(input())
arr=list(map(int,input().split()))
for i in range(n):
	k=0
	for j in range(n):
		if i!=j:
			if arr[i]%arr[j]==0:
				k+=1
				break
			else:
				continue
	if k!=1:
		print(arr[i], end=' ')


r = eval(input())

numbers = [int(i) for i in input().split()]

out = sorted(numbers)

i = 0

while i<len(out):
	for j in out[i+1:]:
		if not j%out[i]:
			out.remove(j)
	i = i+1

for i in numbers:
	if i in out:
		print(i, end=' ')


n, arr = eval(input()), [int(i) for i in input().strip().split()]
for i in range(0,n):
	c=0
	for j in range(0,n):
		if (arr[i]%arr[j]==0):
			c=c+1
	if c==1:
		print(arr[i], end=' ')




counts = eval(input())
s = input()
input_data = s.split(' ')
result = ''
for index in range(counts):
	count = 0
	for i in range(counts):
	   
		if(int(input_data[index]) % int(input_data[i]) == 0):
			count = count + 1

	if(count == 1):
		result = result + input_data[index] + ' '
print(result)


'''
Created on Apr 7, 2016

@author: ACER
'''
def get_prime(length_of_set, num_set):
	"""Return all primes in set"""
	num_set = num_set.split(' ')
	num_set = list(map(int, num_set))
	prime_list = [] #list to store all prime numbers
	for num in num_set:
		for all_num in num_set:
			if num % all_num == 0 and num != all_num:
				prime_list.append(num)
				break
	prime_list = [str(num) for num in num_set if num not in prime_list]
	return prime_list

if __name__ == '__main__':
	LEN_OF_SET = eval(input(""))
	SET = input("")
	print(" ".join(get_prime(LEN_OF_SET, SET)))


'''
Created on Apr 7, 2016

@author: ACER
'''
def get_prime(length_of_set, num_set):
	"""Return all primes in set"""
	num_set = num_set.split(' ')
	num_set = list(map(int, num_set))
	prime_list = [] #list to store all prime numbers
	for num in num_set:
		for all_num in num_set:
			if num % all_num == 0 and num != all_num:
				prime_list.append(num)
				break
	prime_list = [str(num) for num in num_set if num not in prime_list]
	return prime_list

if __name__ == '__main__':
	LEN_OF_SET = eval(input(""))
	SET = input("")
	print(" ".join(get_prime(LEN_OF_SET, SET)))


n=eval(input())
a=[]
l=list(map(int,input().split()))
for i in range(n):
	t=True
	for j in range(n):
		if l[i]!=l[j] and l[i]%l[j]==0:
			t=False
			break
		
	if t==True:
		a.append(l[i])
for i in a:
	print(i, end=' ')


n=eval(input())
myset=list(map(float,input().split()))
flag=True
local=0
count=0
i=0
j=-1
#poplist=[]
#print 'Begins'
#print myset
while flag==True:
	while i<len(myset):
		j=0
		#print 'blah'
		while j<len(myset):
			#print i,j
			if(j!=i):
				#print 'here1'
				#print myset[i]/myset[j]
				if (myset[i]/myset[j])%1 == 0:
					tmp=myset[i]
					while True:
						try:
							myset.remove(tmp)
							#poplist.append(tmp)
							#print 'did'
							#print myset
						except:
							#print 'changed i in exception'
							i=0
							j=0
							break;
				else:
					j=j+1
					continue
					
			else :
				#print 'here2'
				j=j+1
				continue
								  
		flag=False
		i=i+1


for i in myset:
	print(repr(int(i)), end=' ')




#number of inputs
number = input()
number = int(number)
#numbers to check
inputList = input().split()
#print 'Input List is ',inputList
resultList = []
if '1' in inputList:
	print(1, end=' ')
elif number ==1:
	print(inputList[0])
else:
	for i in range(0,number):
		prime = True
		for j in inputList:
			if int(j) == int(inputList[i]):
				pass 
			elif int(inputList[i])%int(j) ==0:
				prime = False
				break
			else:
				prime = True
		if prime == True:
			print(inputList[i], end=' ')
			
			


#number of inputs
number = input()
number = int(number)
#numbers to check
inputList = input().split()
#print 'Input List is ',inputList
resultList = []
if '1' in inputList:
	print(1, end=' ')
elif number ==1:
	print(inputList[0])
else:
	for i in range(0,number):
		prime = True
		for j in inputList:
			if int(j) == int(inputList[i]):
				pass 
			elif int(inputList[i])%int(j) ==0:
				prime = False
				break
			else:
				prime = True
		if prime == True:
			print(inputList[i], end=' ')
			
			


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
N = int(input())
result = []
str_input = input()
S = str_input.split(' ')
for ci in range(0,N):
	for cj in range(0,N):
		if ci != cj and int(S[ci]) % int(S[cj]) == 0:
			result.append(S[ci])
			break
	   
for ci in range(0,len(result)):
	S.remove(result[ci])
print(" ".join(S))


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
#let my set of number is in a list s.
s = []
prime_list = s
output = []
item = input()
maxLengthList = int(item)
item1 = input()
#item1 = input("")
s = item1.split(' ')
s= list(map(int,s))
for x in s:
	for p in s:
	  if x != p:
		  if x%p == 0:
		  	#prime_list.remove(x)
		  	prime_list.append(x)
		  	break
#print prime_list
for x in s:
	 if x not in prime_list:
	 	print(x, end=' ')
		  
	   


n=int(input())
s=list(map(int,input().split()))

for a in s:
	count = 0
	for i in range(0,n):
		if (a%s[i]) is 0:
			count+=1
	if count is 1:
		print(a, end=' ')


#number of inputs
number = input()
number = int(number)
#numbers to check
inputList = input().split()
#print 'Input List is ',inputList
resultList = []
if '1' in inputList:
	print(1, end=' ')
elif number ==1:
	print(inputList[0])
else:
	for i in range(0,number):
		prime = True
		for j in inputList:
			if int(j) == int(inputList[i]):
				pass 
			elif int(inputList[i])%int(j) ==0:
				prime = False
				break
			else:
				prime = True
		if prime == True:
			print(inputList[i], end=' ')
			
			


no=int(input(""))
l=list(map(int,input("").split()))
cnt=0
for i in l:
	cnt=0
	for j in l:
		if i%j==0:
			cnt+=1
	if cnt==1:
		print(i, end=' ')	


counts = eval(input())
s = input()
input_data = s.split(' ')
result = ''
for index in range(counts):
	count = 0
	for i in range(counts):
	   
		if(int(input_data[index]) % int(input_data[i]) == 0):
			count = count + 1

	if(count == 1):
		result = result + input_data[index] + ' '
print(result)


#!/usr/bin/python
n = int(eval(input()))
all = [int(x) for x in input().split(' ')]

prime = []

for i in all:
	isprime = 1
	for j in all:
		if i != j and i % j == 0:
			isprime = 0
	if isprime == 1:
		prime.append(i)
primes = ''
for i in prime:
	primes = primes + str(i) + ' '
print(primes)