import os
import sys
import math
# 计算组合数
# a下 b上
import time
def C(a, b):
start = 1
res = 1
for i in range(b):
res = res * (a / start)
a = a - 1
start = start + 1
return int(res)
if __name__ == '__main__':
n = int(input())
if n == 1:
print(1)
else:
for col in range(16, -1, -1):
start_row = 2 * col
final_row = max(start_row, n)
flag = False
if C(start_row, col) > n:
continue
else:
while start_row < final_row:
mid = int((start_row + final_row) / 2)
number = C(mid, col)
if C(mid, col) > n:
final_row = mid
elif C(mid, col) == n:
print((mid + 1) * mid // 2 + col + 1)
flag = True
break
elif C(mid, col) < n:
start_row = mid
if flag:
break
在本机调试上,应该比案例更快,按逻辑,和案例是差不多,先判断每一列有效值第一个,若大于便进入二分查找,否则进入n-1列循环。但是不知道为什么丢进检测里,会超时