➽ Problem:-
https://www.hackerrank.com/challenges/between-two-sets/problem
➽ Solution:-
import
java.util.*;
import
java.io.*;
class
Solution
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int a, b;
a = sc.nextInt();
b = sc.nextInt();
int[] x = new int[a];
int[] y = new int[b];
for(int i=0; i<a; i++)
{
x[i] = sc.nextInt();
}
for(int i=0; i<b; i++)
{
y[i] = sc.nextInt();
}
int ans = 0;
for(int j=1; j<=100; j++)
{
int temp = 1;
for(int i=0; i<a; i++)
if(j % x[i] != 0)
temp = 0;
for(int i=0; i<b; i++)
if(y[i] % j != 0)
temp = 0;
if(temp==1)
ans++;
}
System.out.println(ans);
}
}
0 Comments
Please do not enter any spam link in the comment section.