Received this question during recently FB onsite. Not much clue on the optimized solution.
There are N people sitting around a round table, labeled 1 to N. Also, a number P is given. The game starts with person 1, and this person will say out 1, then person 2 say out 2,...all the way till P is called out.
One speical thing about this game is that, a number K will also be given before the game starts. When the spoken-out number is a mutiple of K, or it contains K (this means say K = 35, then numbers like 354,135,5354 contains K, i.e. viewing K as a string, then it is a substring of the spoken-out number as a string), the person will get a point (each one's points will be accumulated till the game ends), and he/she will continue to speak out the next number until this number is neither a multiple of K, nor contains K. For example, K = 2, P = 100, and when it's someone's turn to call out 20, he/she will get a point, then he will continue to call out 21, get another point,...all the way till the person calls out 31 (i.e. this person will get 11 points in this round).
Q1: Which person will get the most point and how much? Which person will get the least point and how much?
Q2. If the point one receives is changed to: the number he/she calls out, which is not a mutiple of K, nor contains K (i.e in above example, the person will get 31 points and next person will get 33 points), what will be the answers to the questions in Q1.