Find the smallest
and largest hexadecimal integers such
that each of their squares contains
each of the 16 hexadecimal digits (0
through 9 and A through F) once and
only once. A leading zero is not allowed.
largest hex pandigital:
FEDCBA9876543210 is 18364758544493064720
the square root of which is about 4285412295
smallest hex pandigital:
1023456789ABCDEF is 1162849439785405935
the square root of which is about 1078354969
The smallest and largest solutions are:
Smallest:
dec n 1078631835
dec n^2 1163446635475467225
hex n 404A9D9B
hex n^2 1025648CFEA37BD9 hex pandigital
Largest
dec n 4285181505
dec n^2 18362780530794065025
hex n FF6AAE41
hex n^2 FED5B39A42706C81 hex pandigital
-----
first = 1078354969
last = 4285412295
ans = []
for n in range(first, last+1):
s = n**2
n16 = base2base(n,10,16)
n16sqared = base2base(s,10,16)
if len(n16sqared) == len(set(n16sqared)):
print('Smallest')
print(n, s, n16, n16sqared)
ans.append([n, n**2, n16, n16sqared])
break
print()
for n in range(last, first-1, -1):
s = n**2
n16 = base2base(n,10,16)
n16sqared = base2base(s,10,16)
if len(n16sqared) == len(set(n16sqared)):
print('Largest')
print(n, s, n16, n16sqared)
ans.append([n, n**2, n16, n16sqared])
break
|
Posted by Larry
on 2025-01-15 12:05:42 |