1 Star 0 Fork 0

阿坚/projecteuler

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
p062.py 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
阿坚 提交于 2022-05-19 22:48 . 61,62
"""
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])]
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/kuperain/projecteuler.git
git@gitee.com:kuperain/projecteuler.git
kuperain
projecteuler
projecteuler
master

搜索帮助