forked from Tecmax/JavaAndroidPractise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp085.py
More file actions
26 lines (19 loc) · 606 Bytes
/
Copy pathp085.py
File metadata and controls
26 lines (19 loc) · 606 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
#
# Solution to Project Euler problem 85
# Copyright (c) Project Nayuki. All rights reserved.
#
# https://www.nayuki.io/page/project-euler-solutions
# https://github.com/nayuki/Project-Euler-solutions
#
import eulerlib
def compute():
TARGET = 2000000
end = eulerlib.sqrt(TARGET) + 1
gen = ((w, h) for w in range(1, end) for h in range(1, end))
func = lambda wh: abs(num_rectangles(*wh) - TARGET)
ans = min(gen, key=func)
return str(ans[0] * ans[1])
def num_rectangles(m, n):
return (m + 1) * m * (n + 1) * n // 4 # A bit more than m^2 n^2 / 4
if __name__ == "__main__":
print(compute())