58 lines
1.2 KiB
C
58 lines
1.2 KiB
C
#include <stdio.h>
|
|
|
|
int test_if_have_value(int a[100],int n,int value) {
|
|
for (int i = 0; i < n; i++) {
|
|
if (a[i] == value)return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
int main()
|
|
{
|
|
int a[100],b[100],c[100],n1,n2,n_=0,temp;
|
|
scanf("%d",&n1);
|
|
for(int i=0;i<n1;i++){
|
|
scanf("%d",&a[i]);
|
|
}
|
|
scanf("%d",&n2);
|
|
for(int i=0;i<n2;i++){
|
|
scanf("%d",&b[i]);
|
|
}
|
|
|
|
for(int i=0;i<n1;i++){
|
|
temp = 1;
|
|
for(int j=0;j<n2;j++){
|
|
if(!(a[i]%b[j])) temp = 0;
|
|
if(a[i]==b[j]) temp = 1;
|
|
}
|
|
if(temp&&(!test_if_have_value(c,n_,a[i]))){
|
|
c[n_]=a[i];
|
|
n_++;
|
|
}
|
|
}
|
|
for(int i=0;i<n2;i++){
|
|
temp = 1;
|
|
for(int j=0;j<n1;j++){
|
|
if(!(b[i]%a[j])) temp = 0;
|
|
if(b[i]==a[j]) temp = 1;
|
|
}
|
|
if(temp&&(!test_if_have_value(c,n_,b[i]))){
|
|
c[n_]=b[i];
|
|
n_++;
|
|
}
|
|
}
|
|
|
|
for(int i=0;i<n_;i++){
|
|
for(int j=i;j<n_;j++){
|
|
if(c[i]>c[j]){
|
|
temp=c[i];
|
|
c[i]=c[j];
|
|
c[j]=temp;
|
|
}
|
|
}
|
|
}
|
|
|
|
for(int i=0;i<n_;i++) {
|
|
printf("%d ", c[i]);
|
|
}
|
|
return 0;
|
|
} |