Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: DHMath
Views: 73
Kernel: Python 3 (old Anaconda 3)

CK104-填4

import math n = 50 tempL = [] for i in range(n,1,-1): tempL.append(math.floor(n/i)) print(tempL)
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 6, 7, 8, 10, 12, 16, 25]
n = 2015 temp = set() for i in range(n,1,-1): temp.add(math.floor(n/i)) sortedTemp = list(temp) sortedTemp.sort() print(sortedTemp)
[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, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 53, 54, 55, 57, 59, 61, 62, 65, 67, 69, 71, 74, 77, 80, 83, 87, 91, 95, 100, 106, 111, 118, 125, 134, 143, 155, 167, 183, 201, 223, 251, 287, 335, 403, 503, 671, 1007]

關鍵在於找出 [ni][ni+1]>1[\frac{n}{i}] - [\frac{n}{i+1}] > 1 的臨界 i 值。

n = 2015 def findGap(n): pre = 1 for i in range(n,1,-1): if math.floor(n/i) - pre > 1: return i,pre+1 else: pre = math.floor(n/i) print(n,findGap(n))
2015 (41, 48)