Le Monde puzzle [#1111]

[This article was first published on R – Xi’an’s Og, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don’t.

Another low-key arithmetic problem as Le Monde current mathematical puzzle:

Notice that there are 10 numbers less than, and prime with 11, 100 less than and prime with 101, 1000 less than, and prime with 1111? What is the smallest integer N such that the cardinal of the set of M

As it is indeed a case for brute force resolution as in the following R code

homanycoprim=function(n){ many=1 for (i in 2:(n-1)) many=many+coprime(i,n) return(many)} smallest=function(){ n=1e4 many=homanycoprim(n) while (many!=1e4) many=homanycoprim(n<-n+1) return(n)}

which returns n=10291 as the smallest value of N.  For the other two questions, the usual integer2digit function is necessary

smalldiff=function(){ n=1111;mul=1 while (mul<1e6) { x=as.numeric(strsplit(as.character(n*mul), "")[[1]]) while (sum(duplicated(x))!=0){ mul=mul+1 x=as.numeric(strsplit(as.character(n*mul), "")[[1]])} print(n*mul);mul=mul+1}}

leading to 241,087 as the smallest and 9,875,612,340 as the largest (with 10 digits).

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook


Leave a Comment