-
Notifications
You must be signed in to change notification settings - Fork 0
/
outOfSort.py
45 lines (35 loc) · 931 Bytes
/
outOfSort.py
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
n,m,a,c, x0= map(lambda x: int(x), input().split(" "))
sequence = []
def func(a, xPrev, c, m):
return (a*xPrev+c)%m
def sequenceGenerator():
prev = x0
for i in range(n):
calculation = func(a,prev, c, m)
sequence.append(calculation)
prev = calculation
def binarySearch(toSearch):
left = 0
right = n-1
# print(currHeight)
# print(obstacles)
# print("CHECKING")
# print(toSearch)
while(left<=right):
midPoint = int((left+right)//2)
# print(midPoint)
if sequence[midPoint] == toSearch:
return True
elif sequence[midPoint] < toSearch:
left = midPoint+1
elif sequence[midPoint] > toSearch:
right = midPoint-1
return False
count = 0
sequenceGenerator()
# print(sequence)
for val in sequence:
isFound = binarySearch(val)
if isFound:
count = count+1
print(count)