-
Notifications
You must be signed in to change notification settings - Fork 6
/
Solution.cs
69 lines (54 loc) · 1.61 KB
/
Solution.cs
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
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Linq;
class Result
{
public static int getTotalX(int[] a, int[] b)
{
var totalXs = 0;
var maximumA = a.Max();
var minimumB = b.Min();
var counter = 1;
var multipleOfMaxA = maximumA;
while (multipleOfMaxA <= minimumB)
{
var factorOfAll = true;
foreach (var item in a)
{
if (multipleOfMaxA % item != 0)
{
factorOfAll = false;
break;
}
}
if (factorOfAll)
{
foreach (var item in b)
{
if (item % multipleOfMaxA != 0)
{
factorOfAll = false;
break;
}
}
}
if (factorOfAll)
totalXs++;
counter++;
multipleOfMaxA = maximumA * counter;
}
return totalXs;
}
}
class Solution
{
public static void Main(string[] args)
{
string[] firstMultipleInput = Console.ReadLine().TrimEnd().Split(' ');
int n = Convert.ToInt32(firstMultipleInput[0]);
int m = Convert.ToInt32(firstMultipleInput[1]);
var arr = Console.ReadLine().TrimEnd().Split(' ').ToList().Select(arrTemp => Convert.ToInt32(arrTemp)).ToArray();
var brr = Console.ReadLine().TrimEnd().Split(' ').ToList().Select(brrTemp => Convert.ToInt32(brrTemp)).ToArray();
int total = Result.getTotalX(arr, brr);
Console.WriteLine(total);
}
}