-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBetweenTwoSets.cs
More file actions
40 lines (37 loc) · 1.22 KB
/
Copy pathBetweenTwoSets.cs
File metadata and controls
40 lines (37 loc) · 1.22 KB
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {
static void Main(String[] args) {
string[] tokens_n = Console.ReadLine().Split(' ');
int n = Convert.ToInt32(tokens_n[0]);
int m = Convert.ToInt32(tokens_n[1]);
string[] a_temp = Console.ReadLine().Split(' ');
int[] a = Array.ConvertAll(a_temp,Int32.Parse);
string[] b_temp = Console.ReadLine().Split(' ');
int[] b = Array.ConvertAll(b_temp,Int32.Parse);
var total = 0;
var maxlen = Math.Max(n, m);
//assuming the elements are sorted
for (var x = a[n - 1]; x <= b[0]; x++)
{
var goodx = true;
for (var j = 0; j < maxlen; j++)
{
if (j < n && x % a[j] != 0)
{
goodx = false;
break;
}
if (j < m && b[j] % x != 0)
{
goodx = false;
break;
}
}
total += (goodx ? 1 : 0);
}
Console.WriteLine(total);
}
}