0
Guys how do I write a function that returns the smallest number whose first (n) multiples contain the digit 2
124 is the smallest number whose first 3 multiples contain the digit 2.124*1=124,124*2=248,124*3=372.each multiple contains 2
1 ответ
+ 4
I'm not going to give you working code, but more of a general idea how to solve this problem (albeit very naively) by breaking it down into smaller ones.
A. Think of a way to check, whether a given number contains the digit two.
B. Use what you learned in A on each one of a number's first n multiples.
C. Start with 2 and count up in a reasonable way, checking every number with what you got from B, until you find a number, which fulfills your condition.
Of course that is more of a brute force approach and of you want to check that for very large n, you will need a smarter way to do it. I'm sure there is one, maybe you can find it.