From 2820d50cbec08891edc9752d2722eec3338e0d9a Mon Sep 17 00:00:00 2001 From: "xw_y_am@rmbp" Date: Sat, 30 Sep 2017 11:03:38 +0800 Subject: [PATCH] add 139 140 --- python/139.md | 24 +++++++++++++++++++++++ python/139.py | 41 +++++++++++++++++++++++++++++++++++++++ python/140.md | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ python/140.py | 13 +++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 python/139.md create mode 100644 python/139.py create mode 100644 python/140.md create mode 100644 python/140.py diff --git a/python/139.md b/python/139.md new file mode 100644 index 0000000..ace3a57 --- /dev/null +++ b/python/139.md @@ -0,0 +1,24 @@ +毕达哥拉斯数可以由如下公式得出 + +$$ +a=2mn \\ +b=m^2-n^2 \\ +c=m^2+n^2 +$$ +显然 $m>n$ ,因此不妨设 $m=n+k$ ,则 +$$ +a=2n^2+2nk \\ +b=k^2+2nk \\ +c=2n^2+2nk+k^2 +$$ +所以 $a+b+c=4n^2+6nk+2k^2$ 。 + +$4n^2+6n+2 1: + continue + p = 2 * n ** 2 + q = k ** 2 + r = 2 * n * k + if (p + q + r) % abs(p - q): + continue + print(n, k) + count += limit // (2 * p + 2 * q + 3 * r) + return count + +def perfect(limit): + def side(n, k): + return 4 * n ** 2 + 6 * n * k + 2 * k ** 2 + def sqrt2(n): + m = int(n * 2 ** 0.5) + return m + (1 - m % 2) + n, k = 1, 1 + border = 12 + count = 0 + while border < limit: + yield limit // border + n = n + k + k = sqrt2(n) + border = side(n, k) + +#print(search(100000000)) +print(sum(list(perfect(100000000)))) + diff --git a/python/140.md b/python/140.md new file mode 100644 index 0000000..80c584c --- /dev/null +++ b/python/140.md @@ -0,0 +1,53 @@ +根据137题有 +$$ +A_G(x)=\frac{x+3x^2}{1-x-x^2} +$$ + +所以 +$$ +(n+3)x^2+(n+1)x-n=0 +$$ +解此方程,得 +$$ +x=\frac{\sqrt{5n^2+14n+1}-(n+1)}{2(n+3)} +$$ +只有 $5n^2+14n+1$ 是平方数时, $x$ 才会是有理数。 + +尝试分析 $N=5n^2+14n+1$ 是平方数时 $n$ 的变化规律 + +| N | increasing rate of N | +| -------- | -------------------- | +| 2 | | +| 5 | 2.5 | +| 21 | 4.2 | +| 42 | 2.0 | +| 152 | 3.619047619047619 | +| 296 | 1.9473684210526316 | +| 1050 | 3.5472972972972974 | +| 2037 | 1.94 | +| 7205 | 3.5370643102601864 | +| 13970 | 1.9389312977099236 | +| 49392 | 3.535576234788833 | +| 95760 | 1.9387755102040816 | +| 338546 | 3.535359231411863 | +| 656357 | 1.9387527839643652 | +| 2320437 | 3.535327573256627 | +| 4498746 | 1.9387494683113569 | +| 15904520 | 3.535322954441082 | + +观察发现 $1.9387\ldots*3.5353\ldots=\frac{\sqrt{5}+1}{2}$. + +进一步尝试 +$$ +5-2=3 \\ +42-21=21 \\ +296-152=144 +$$ + +$$ +21-5=16=2*8 \\ +152-42=110=2*55 \\ +1050-296=754=2*377 +$$ + +$3,21,144,\ldots,8,55,377\ldots$ 它们都是 Fibonacci 数。 \ No newline at end of file diff --git a/python/140.py b/python/140.py new file mode 100644 index 0000000..52dc9b2 --- /dev/null +++ b/python/140.py @@ -0,0 +1,13 @@ + +def calc(limit): + a, b = 3, 5 + n = 2 + d = 1 + for i in range(limit): + yield n + n += d * a + a, b = b, a + b + a, b = b, a + b + d = 3 - d + +print(sum(list(calc(30))))