import math
def fast_pow(base, exponent, mod):
result = 1
while exponent > 0:
if exponent % 2 == 1:
result = (result * base) % mod
base = (base * base) % mod
exponent = exponent // 2
return result
def main():
P = int(input())
log10_2 = 0.30102999566398114
num_digits = int(P * log10_2) + 1
mod = 10**500
last_500_digits = (fast_pow(2, P, mod) - 1) % mod
print(num_digits)
last_500_str = f"{last_500_digits:0500d}"
for i in range(0, 500, 50):
print(last_500_str[i:i+50])
if __name__ == "__main__":
main()思考如何计算 的位数 的位数与 的位数几乎相同 因此, 的位数为:
代码实现步骤
1.计算位数
2.计算最后500位数字
3.输出位数
4.输出最后500位数字,每行50位
求过QwQ