TADEPALLI #include int main() { int n,m; scanf(“%d %d”,&n,&m); int arr1[n],arr2[m]; int i,j,count=0; for(i=0;i<n;i++) scanf("%d",&arr1[i]); for(i=0;i<m;i++) scanf("%d",&arr2[i]); for(int k=arr1[n-1];k<=arr2[0];k++) { int flag1=0,flag2=0; for(i=0;i<n;i++) { if(k%arr1[i]==0) { flag1++; } } for(j=0;j<m;j++) { if(arr2[j]%k==0) { flag2++; } } if(flag1==n&&flag2==m) count++; } printf("The number of terms are %d\n",count); return 0; } Log in to Reply
#include
int main()
{
int n,m;
scanf(“%d %d”,&n,&m);
int arr1[n],arr2[m];
int i,j,count=0;
for(i=0;i<n;i++)
scanf("%d",&arr1[i]);
for(i=0;i<m;i++)
scanf("%d",&arr2[i]);
for(int k=arr1[n-1];k<=arr2[0];k++)
{
int flag1=0,flag2=0;
for(i=0;i<n;i++)
{
if(k%arr1[i]==0)
{
flag1++;
}
}
for(j=0;j<m;j++)
{
if(arr2[j]%k==0)
{
flag2++;
}
}
if(flag1==n&&flag2==m)
count++;
}
printf("The number of terms are %d\n",count);
return 0;
}