add 139 140
This commit is contained in:
parent
772f1f8d15
commit
2820d50cbe
24
python/139.md
Normal file
24
python/139.md
Normal file
@ -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<N$ ,所以
|
||||
$$
|
||||
n<\frac{\sqrt{4N+1}-3}{4}
|
||||
$$
|
||||
$2k^2+6nk+4n^<N$ ,所以
|
||||
$$
|
||||
k<\frac{\sqrt{2N+n^2}-3n}{2}
|
||||
$$
|
||||
|
41
python/139.py
Normal file
41
python/139.py
Normal file
@ -0,0 +1,41 @@
|
||||
from tools import number_theory
|
||||
|
||||
def range_n(N):
|
||||
return int(((4 * N + 1) ** 0.5 - 3) / 4) + 1
|
||||
|
||||
def range_k(N, n):
|
||||
return int(((2 * N + n ** 2) ** 0.5 - 3 * n) / 2) + 1
|
||||
|
||||
def search(limit):
|
||||
count = 0
|
||||
for n in range(1, range_n(limit)):
|
||||
for k in range(1, range_k(limit, n), 2):
|
||||
if number_theory.gcd(n, k) > 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))))
|
||||
|
53
python/140.md
Normal file
53
python/140.md
Normal file
@ -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 数。
|
13
python/140.py
Normal file
13
python/140.py
Normal file
@ -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))))
|
Loading…
x
Reference in New Issue
Block a user