第二题鸟洞,Python可以调库,异常简单,算作弊吗 from decimal import Decimal from math import factorial n, p = input().split() n, p = int(n), Decimal(p) # 二分 s, e = 1, n + 1 val = Decimal(factorial(n)) while s < e: mid = (s + e) // 2 tmp = val / factorial(n - mid) if (1 - p) * n ** mid > tmp: e = mid - 1 elif (1 - p) * n ** mid < tmp: s = mid + 1 else: s = mid break print(s)