-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathades1.py
More file actions
40 lines (36 loc) · 692 Bytes
/
ades1.py
File metadata and controls
40 lines (36 loc) · 692 Bytes
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
from math import sqrt,ceil,sqrt
def rouns(a):
if a-int(a)>=0.5:
return ceil(a)
else:
return int(a)
def builds(a,b):
c=[]
while b!=0:
c.append(rouns(a/b))
a-=rouns(a/b)
b-=1
return c
def mins(a,k):
import heapq
n=len(a)
h = list(zip(a[:k], range(k)))
heapq.heapify(h)
p=h[0][0]-(k-1)
for i in range(k, n):
heapq.heappush(h, (a[i], i));
while h[0][1] <= i - k:
heapq.heappop(h)
p+=h[0][0]-(k-1)
return p
n=int(input())
if n>=4:
h=int(sqrt(n))
a=(builds(n,h))
a=sorted(a)[::-1]
d=0
for i in range(2,len(a)+1):
d+=mins(a,i)
print(d)
else:
print(0)