반응형
#!/usr/bin/env python
# Project Euler 62
# http://projecteuler.net/index.php?section=problems&id=62
# Problem 62
#
# The cube, 41063625 (3453), can be permuted to produce two other cubes:
# 56623104 (3843) and 66430125 (4053). 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.
def solve():
di = {} # python dictionary, hash
n = 1
while True:
l = list(str(n * n * n))
l.sort()
sorted_str = "".join(l)
if sorted_str not in di:
di[sorted_str] = []
di[sorted_str].append(n)
if len(di[sorted_str]) == 5:
break
n += 1
print(di[sorted_str])
for n in di[sorted_str]:
print(sorted_str, n * n * n)
if __name__ == "__main__":
solve()
728x90
'프로그래밍 > 알고리즘' 카테고리의 다른 글
[Python] 분수의 순환소수, 순환마디 구하기 (0) | 2022.07.27 |
---|---|
파이썬 자리수곱의합 (0) | 2022.07.18 |
[EP 057] 2의 제곱근의 연분수 표현 (0) | 2022.06.08 |
Swift codewars 연습문제 gravity (0) | 2022.05.27 |
[EP 047] 소인수분해의 소수의 갯수가 4개 (0) | 2021.12.30 |