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.
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.
Sample Input:
5
10 5 3 15 16
Sample Output:
5 3 16
C Implementation:
#include <stdio.h>
int main()
{
int n;
int a[1000000];
int i;
int flag;
int j;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
flag = 1;
for(j=0;j<n;j++)
{
if(i!=j && a[i]%a[j]==0)
{
flag = 0;
break;
}
}
if(flag)
printf("%d ",a[i]);
}
return 0;
}