The binary integer 110101 has 2 zeroes and 4 ones. Its square 101011111001 has double that, namely 4 zeroes and 8 ones.
Similarly, the ternary integer 20211 has 1 zero, 2 ones and 2 twos. Its square 1201102221 has double that, namely 2 zeroes, 4 ones and 4 twos.
Find the first 3 decimal (base ten) integers with this property.
Here are the first several:
n n^2
72576 5267275776
406512 165252006144
415278 172455817284
494462 244492669444
603297 363967270209
725760 526727577600
-------------
sqrt_of_10 = 10**.5
for digits in range(1,7):
lo = 1+int(sqrt_of_10*(10**(digits-1)))
for n in range(lo, 10**(digits)+1):
string1 = ''.join(sorted(str(n**2)))
string2 = ''.join(sorted(str(n)*2))
if string1 == string2:
print(n, n**2)
|
Posted by Larry
on 2023-09-28 11:12:02 |