解答:
- #coding:utf-8
- def is_cycle(n):
- return True if str(n) == str(n)[::-1] else False
- limit = 1000
- window_s = 1
- window_e = int(limit ** 0.5)
- while window_s<window_e:
- s = window_s*window_s
- for i in range(window_s+1,window_e):
- s += i*i
- if s >= limit:
- break
- if is_cycle(s):
- print (s, list(range(window_s,i+1)))
- window_s += 1
复制代码
输出:
- 5 [1, 2]
- 55 [1, 2, 3, 4, 5]
- 505 [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
- 818 [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
- 77 [4, 5, 6]
- 636 [4, 5, 6, 7, 8, 9, 10, 11, 12]
- 595 [6, 7, 8, 9, 10, 11, 12]
- 181 [9, 10]
- 434 [11, 12, 13]
- 313 [12, 13]
- 545 [16, 17]
复制代码 |