forked from RyanFehr/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution.java
57 lines (51 loc) · 1.46 KB
/
Solution.java
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//Problem: https://www.hackerrank.com/challenges/between-two-sets
//Java 8
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 maxA = 0;
int minB = 101;
int[] a = new int[n];
for(int a_i=0; a_i < n; a_i++){
int tmp = in.nextInt();
maxA = tmp > maxA ? tmp:maxA;
a[a_i] = tmp;
}
int[] b = new int[m];
for(int b_i=0; b_i < m; b_i++){
int tmp = in.nextInt();
minB = tmp < minB ? tmp:minB;
b[b_i] = tmp;
}
int integersBetween = 0;
intCheck:
for(int i = maxA; i <= minB; i += maxA)
{
//Check if all A are a factor of i
for(int num : a)
{
if(i%num != 0)
{
continue intCheck;
}
}
//Check if i is a factor of all B
for(int num : b)
{
if(num%i != 0)
{
continue intCheck;
}
}
integersBetween++;
}
System.out.println(integersBetween);
}
}