A 6-digit positive integer N is squared to form a 12-digit number. The center six digits of N^2 constitute N. Determine all possible values of N.
(If 'abcdef' was the 6-digit number, then the 12-digit number would look like 'uvwabcdefxyz'.)
Will there be any further solution(s) if N contained a leading zero?
for n=1:999999
nstr=char(string(n));
nsq=char(string(n^2));
if length(nstr)==6 && length(nsq)==12
if isequal(nsq(4:9),nstr)
fprintf('%s %s\n',nstr,nsq)
end
else
nstr=sprintf('%06s',nstr);
nsq=sprintf('%012s',nsq);
if isequal(nsq(4:9),nstr)
fprintf(' %s %s\n',nstr,nsq)
end
end
end
finds there is one example with leading zeros and four examples with no leading zeros:
>> center6digits
001000 000001000000
376000 141376000000
495475 245495475625
625000 390625000000
971582 943971582724
|
Posted by Charlie
on 2023-07-15 10:33:28 |