代码拉取完成,页面将自动刷新
"""
Problem 99: https://projecteuler.net/problem=99
Comparing two numbers written in index form like 2'11 and 3'7 is not difficult, as any
calculator would confirm that 2^11 = 2048 < 3^7 = 2187.
However, confirming that 632382^518061 > 519432^525806 would be much more difficult, as
both numbers contain over three million digits.
Using base_exp.txt, a 22K text file containing one thousand lines with a base/exponent
pair on each line, determine which line number has the greatest numerical value.
"""
# _*_ conding:UTF-8 _*_
'''
@author = Kuperain
@email = kuperain@aliyun.com
@IDE = VSCODE Python3.8.3
@creat_time = 2022/6/9
'''
from math import log10
DataFile = 'p099_base_exp.txt'
def readData(filepath: str = DataFile) -> list:
data = []
with open(filepath, 'r') as fp:
for line in fp:
linedata = eval('[' + line.strip() + ']')
data.append(linedata)
return data
Data = readData(DataFile)
def solution(data: list = Data):
res = (0, data[0][1]*log10(data[0][0]))
for i in range(1, len(data)):
tmp = data[i][1]*log10(data[i][0])
if tmp > res[1]:
res = (i, tmp)
return res[0]+1, data[res[0]] # line = 1,2,3...
if __name__ == "__main__":
import doctest
doctest.testmod(verbose=False)
print(solution())
# (709, [895447, 504922])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。