The permutations of digits of the cube of 345, 41063625, can be the cubes of 384 and 405.
Find the smallest cube such that exactly five of its permutations are cubes.
Since we need to count how many cubes there are in permutations of a particular set of digits, we will store every distinct set of digits, along with their smallest cubic permutation and the total cubic permutations until we encounter the first/smallest set of digits that have exactly 5 cubic permutations. We will store this information in mapped objects, i.e., Dictionary
in Python.
13451,31451,11453… are all permutations of a particular set of digits, i.e., {1,1,3,4,5}.
We will run a while
loop for n
times, starting from 1, until any of the keys have the counter
in Digit_dict == 5
.
n_cube
= cube of n
, i.e., $n^3$.
sorted_cube
= the sorted string of n_cube
.
cube
= the n
whose cube is the smallest cubic permutation of sorted_cube
.
counter
= the number of cubic permutations of sorted_cube
.
Digit_dict
= a Python dictionary, where:
i. keys are sorted_cube
.
ii. values are [ cube
,counter
].
if
sorted_cube
is already in Digit_dict
keys:
sorted_cube
is already inDigit_keys
. This meansn_cube
is just a permutation ofsorted_cube
. Therefore, we will simply incrementcounter
inDigit_keys
forsorted_cube
by 1.
else
:
sorted_cube
is not inDigit_keys
. This meansn_cube
is not a permutation of any previous cubes. Therefore, we will add thissorted_cube
inDigit_dict
.
Digit_dict = dict() n = 1 while True: n_cube = n**3 sorted_cube = ''.join(sorted(str(n_cube))) if sorted_cube in list(Digit_dict.keys()): Digit_dict[sorted_cube] = [Digit_dict[sorted_cube][0],Digit_dict[sorted_cube][1]+1] else: Digit_dict.update({sorted_cube : [n_cube,1]}) if Digit_dict[sorted_cube][1] == 5: print(Digit_dict[sorted_cube][0]) break n+=1
RELATED TAGS
CONTRIBUTOR
View all Courses