#2549
Count Distinct Numbers on Board
pupil · 420 · lc easy +25 · verified · 61.7% accepted · 319 likes · top 62%
Description
A positive integer n is placed on a board. Each day, for every number x currently on the board, any integer i satisfying 1 <= i <= n and x % i == 1 is also added. Numbers are never removed. After 109 days, return the count of distinct integers on the board.
Example 1:
Input: n = 5
Output: 4
Explanation: Initially, 5 is 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.
Example 2:
Input: n = 3
Output: 2
Explanation:
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.
Code
1
2
3