-
Notifications
You must be signed in to change notification settings - Fork 0
/
he_benny_universe.cs
90 lines (82 loc) · 2.64 KB
/
he_benny_universe.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Collections.Generic;
using System.Linq;
// not solved
namespace MMT_Elitmus
{
class he_benny_universe
{
static List<long> line;
static int indexToStart;
static void Main1(string[] sasa)
{
string[] Nas = Console.ReadLine().Split(' ');
int N = Convert.ToInt32(Nas[0]);
int Q = Convert.ToInt32(Nas[1]);
string dds = Console.ReadLine();
line = dds.Split(new string[] { " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt64(t)).ToList();
line = line.OrderBy(t => t).ToList();
int cnt = line.Count - 1;
while (Q-- > 0)
{
long item = Convert.ToInt64(Console.ReadLine());
int indStat = binarySearch(item,0,cnt);
bool found = false;
for (int j = indStat; j >= 0; j--)
{
if (item % line[j] == 0)
{
Console.WriteLine("YES");
found = true;
break;
}
else
{
item = item % line[j];
}
for (int k = j - 1; k >= 0; k--)
{
if (item < line[k])
continue;
else
{
item = item % line[j];
}
}
}
if (!found)
Console.WriteLine("NO");
}
}
// 5 8 11 : 11
static int binarySearch(long val,int start,int end)
{
if (end < start)
return -1;
if (start == end)
{
indexToStart = start;
return start;
}
int mid = (start + end) / 2;
if (line[mid] == val)
{
indexToStart = mid;
return mid;
}
if (line[mid] < val && line[mid + 1] > val)
{
indexToStart = mid;
return mid;
}
if (line[mid] > val)
{
return binarySearch(val, mid + 1, end);
}
else
{
return binarySearch(val, start, mid);
}
}
}
}