Find the smallest distinct whole numbers, M and N such that you can rearrange the digits of M to get N, and you can rearrange the digits of M4 to get N4, and where neither M nor M4 contains a 0.
Depending on how you define the smallest pair, the first pair has the overall smallest number, but the second pair has the smallest sum:
(M, N): (125413, 152314)
The 4th powers: (247383213595342283761, 538219333452784723216)
(M, N): (127286, 127826)
The 4th powers: (262495918768771833616, 266978811763592348176)
-------------
big = 1000000
numbDict = {}
quartDict = {}
for k in range(1,big):
if '0' in str(k):
continue
kquartd = k**4
numbKey = ''.join(sorted(str(k)))
if '0' in numbKey:
continue
quartKey = ''.join(sorted(str(kquartd)))
if '0' in quartKey:
continue
if numbKey not in numbDict:
numbDict[numbKey] = [k]
else:
numbDict[numbKey].append(k)
if quartKey not in quartDict:
quartDict[quartKey] = [kquartd]
else:
quartDict[quartKey].append(kquartd)
for k,v in quartDict.items():
if len(v) == 1:
continue
these_N_keys = []
thesenumbs = []
for cub in v:
n = round(cub**(1/4))
keyOfN = ''.join(sorted(str(n)))
these_N_keys.append(keyOfN)
thesenumbs.append(n)
if len(these_N_keys) == len(set(these_N_keys)):
continue
print('M and N are among:', thesenumbs )
print('The 4th powers are among:', v)
print()
|
Posted by Larry
on 2024-03-30 11:58:26 |