代码拉取完成,页面将自动刷新
"""
Problem 62: https://projecteuler.net/problem=62
The cube, 41063625 (345^3), can be permuted to produce two other cubes:
56623104 (384^3) and 66430125 (405^3). In fact, 41063625 is the smallest cube
which has exactly three permutations of its digits which are also cube.
Find the smallest cube for which exactly five permutations of its digits are
cube.
"""
# _*_ conding:UTF-8 _*_
'''
@author = Kuperain
@email = kuperain@aliyun.com
@IDE = VSCODE Python3.8.3
@creat_time = 2022/5/19
'''
def solution(total: int = 5) -> tuple:
CubesDict = {k: ''.join(sorted(list(str(k**3)), reverse=True))
for k in range(10000)}
# print(CubesDict)
CubesDict_rev = dict()
for key, val in CubesDict.items():
if val in CubesDict_rev:
CubesDict_rev[val] = CubesDict_rev[val] + [key]
else:
CubesDict_rev[val] = [key]
# print(CubesDict_rev)
res = [(key, val)
for key, val in CubesDict_rev.items() if len(val) == total]
print(res)
return min([item[1][0] for item in res])
if __name__ == "__main__":
import doctest
doctest.testmod(verbose=False)
print(solution())
# 5027
# [('987655433210', [5027, 7061, 7202, 8288, 8384]),
# ('987665433210', [5196, 8124, 8496, 9702, 9783])]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。