Le Monde puzzle [#843]

A straightforward Le Monde mathematical puzzle:

Find integers x with 4 to 8 digits which are (a) perfect squares x=y² such that [x/100] is also a perfect square; (b) perfect cubes x=y³ such that [x/1000] is also a perfect cube; (c) perfect cubes x=y³ such that [x/100] is also a perfect cube (where [y] denotes here the integer part).

I first ran an R code in the train from Luxembourg that was not workng (the code not the train!), as I had started with

[sourcecode language=”r” gutter=”false”]
cubs=(34:999)^2 #perfect square
cubs=cubs[cubs%%10>0] #no 0 at the end
trubs=trunc(cubs/100)
difs=apply(abs(outer(cubs,trubs,"-")),2,min)
mots=cubs[difs==0]
[/sourcecode]

If namely too high a lower bound in the list of perfect squares. It thus returned an empty set with good reasons. Using instead

[sourcecode language=”r” gutter=”false”]
cubs=(1:999)^2 #perfect square
[/sourcecode]

produced the outcome

[sourcecode language=”r” gutter=”false”]
> mots
[1] 121 144 169 196 441 484 961 1681
[/sourcecode]

and hence the solution 1681. For the other questions, I used

[sourcecode language=”r” gutter=”false”]
trubs=(1:999)^3
for (i in 1:length(trubs)){
cubs=trubs[i]*100+(1:99)
sol=abs(cubs-round(exp(log(cubs)/3))^3)
if (min(sol)==0){ print(cubs[sol==0])}
}
[/sourcecode]

and got the outcome

[sourcecode language=”r” gutter=”false”]
[1] 125
[1] 2744
[/sourcecode]

which means a solution of 2744. Same thing for

[sourcecode language=”r” gutter=”false”]
trubs=(1:999)^3
for (i in 1:length(trubs)){
cubs=trubs[i]*1000+(1:999)
sol=abs(cubs-round(exp(log(cubs)/3))^3)
if (min(sol)==0){ print(cubs[sol==0])}
}
[/sourcecode]

and

[sourcecode language=”r” gutter=”false”]
[1] 1331 1728
[/sourcecode]

and two solutions. (Of course, writing things on a piece of paper goes way faster…)

Leave a Reply

Discover more from Xi'an's Og

Subscribe now to keep reading and get access to the full archive.

Continue reading