2013-04-17 14:34:39 +08:00

25 lines
473 B
Python

def sum(m, n):
return m * n * (m + 1) * (n + 1) / 4
maxx = 2000000
x = int((8 * maxx + 1) ** 0.5 / 2)
while sum(x, 1) < maxx: x += 1
orisub = abs(sum(x, 1) - maxx)
near = [orisub]
y = 1
while x > y:
tmp = maxx
y_lst = y
while tmp > maxx - orisub and y > 0:
tmp = sum(x, y)
if abs(tmp - maxx) < near[0]:
near = [abs(tmp - maxx), x, y]
y -= 1
x -= 1
y = y_lst
while sum(x, y) < maxx: y += 1
print near[1] * near[2]