进过数学推导,不难写出以下代码:
n=int(input())
print(int((n+1)*(n+2)*(n+3)*(n+4)//24))
交上去发现 RE 了
本地测试,发现运行错误:
Traceback (most recent call last):
File "/home/konyakest/code/2.py", line 1, in <module>
n=int(input())
ValueError: Exceeds the limit (4300) for integer string conversion: value has 100000 digits; use sys.set_int_max_str_digits() to increase the limit
然后,我们按照提示,把代码改成这样:
import sys
sys.set_int_max_str_digits(500000)
n=int(input())
print(int((n+1)*(n+2)*(n+3)*(n+4)//24))
交上去发现 TLE
然后我们用 PyPy 3 交,直接就过了
最慢点不到 300ms,感觉是卡不掉的
(毕竟能写出比 python 实现还快的高精度算法很困难)