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.
Trying up to 5-digit base numbers found only one such case. Going to 6-digit numbers brought the total to six such pairs of numbers.
clearvars,clc
for n=1:999999
ns=char(string(n));
n2s=char(string(n^2));
nct=[];
for i=0:9
ct=length(strfind(ns,char(string(i))));
nct=[nct ct];
end
n2ct=[];
for i=0:9
ct=length(strfind(n2s,char(string(i))));
n2ct=[n2ct ct];
end
if n2ct==2*nct
disp([n n^2]);
end
end
finds
n n^2
72576 5267275776
406512 165252006144
415278 172455817284
494462 244492669444
603297 363967270209
725760 526727577600
|
Posted by Charlie
on 2023-09-28 08:47:43 |