Input: n =5Output: 4Explanation: Initially,5is present on the board.The next day,2 and 4 will be added since 5%2==1 and 5%4==1.After that day,3 will be added to the board because 4%3==1.At the end of a billion days, the distinct numbers on the board will be 2,3,4, and 5.
Input: n =3Output: 2Explanation:
Since 3%2==1,2 will be added to the board.After a billion days, the only two distinct numbers on the board are 2 and 3.
Every number from 1 to n can be generated except 1 (if n > 1). This is because for any x > 1, x % (x-1) == 1, so (x-1) will be added, and this process continues until 1. But 1 % i == 1 only for i = 2, so 1 is only added if n = 1. Thus, for n > 1, all numbers from 2 to n will be present.