-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBetweenTwoSets.java
More file actions
41 lines (38 loc) · 976 Bytes
/
BetweenTwoSets.java
File metadata and controls
41 lines (38 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
int[] a = new int[n];
int count=0,flag;
for(int a_i=0; a_i < n; a_i++){
a[a_i] = in.nextInt();
}
int[] b = new int[m];
for(int b_i=0; b_i < m; b_i++){
b[b_i] = in.nextInt();
}
for(int i=a[n-1];i<=b[0];i++){
flag=1;
for(int j=0;j<n;j++){
if(i%a[j]!=0){
flag=0;
}
}
for(int j=0;j<m;j++){
if(b[j]%i!=0){
flag=0;
}
}
if(flag==1){
count++;
}
}
System.out.print(count);
}
}