|
| 1 | +# [2549. Count Distinct Numbers on Board](https://leetcode.com/problems/count-distinct-numbers-on-board) |
| 2 | + |
| 3 | +[中文文档](/solution/2500-2599/2549.Count%20Distinct%20Numbers%20on%20Board/README.md) |
| 4 | + |
| 5 | +## Description |
| 6 | + |
| 7 | +<p>You are given a positive integer <code>n</code>, that is initially placed on a board. Every day, for <code>10<sup>9</sup></code> days, you perform the following procedure:</p> |
| 8 | + |
| 9 | +<ul> |
| 10 | + <li>For each number <code>x</code> present on the board, find all numbers <code>1 <= i <= n</code> such that <code>x % i == 1</code>.</li> |
| 11 | + <li>Then, place those numbers on the board.</li> |
| 12 | +</ul> |
| 13 | + |
| 14 | +<p>Return<em> the number of <strong>distinct</strong> integers present on the board after</em> <code>10<sup>9</sup></code> <em>days have elapsed</em>.</p> |
| 15 | + |
| 16 | +<p><strong>Note:</strong></p> |
| 17 | + |
| 18 | +<ul> |
| 19 | + <li>Once a number is placed on the board, it will remain on it until the end.</li> |
| 20 | + <li><code>%</code> stands for the modulo operation. For example, <code>14 % 3</code> is <code>2</code>.</li> |
| 21 | +</ul> |
| 22 | + |
| 23 | +<p> </p> |
| 24 | +<p><strong class="example">Example 1:</strong></p> |
| 25 | + |
| 26 | +<pre> |
| 27 | +<strong>Input:</strong> n = 5 |
| 28 | +<strong>Output:</strong> 4 |
| 29 | +<strong>Explanation:</strong> Initially, 5 is present on the board. |
| 30 | +The next day, 2 and 4 will be added since 5 % 2 == 1 and 5 % 4 == 1. |
| 31 | +After that day, 3 will be added to the board because 4 % 3 == 1. |
| 32 | +At the end of a billion days, the distinct numbers on the board will be 2, 3, 4, and 5. |
| 33 | +</pre> |
| 34 | + |
| 35 | +<p><strong class="example">Example 2:</strong></p> |
| 36 | + |
| 37 | +<pre> |
| 38 | +<strong>Input:</strong> n = 3 |
| 39 | +<strong>Output:</strong> 2 |
| 40 | +<strong>Explanation:</strong> |
| 41 | +Since 3 % 2 == 1, 2 will be added to the board. |
| 42 | +After a billion days, the only two distinct numbers on the board are 2 and 3. |
| 43 | +</pre> |
| 44 | + |
| 45 | +<p> </p> |
| 46 | +<p><strong>Constraints:</strong></p> |
| 47 | + |
| 48 | +<ul> |
| 49 | + <li><code>1 <= n <= 100</code></li> |
| 50 | +</ul> |
| 51 | + |
| 52 | +## Solutions |
| 53 | + |
| 54 | +<!-- tabs:start --> |
| 55 | + |
| 56 | +### **Python3** |
| 57 | + |
| 58 | +```python |
| 59 | +class Solution: |
| 60 | + def distinctIntegers(self, n: int) -> int: |
| 61 | + return max(1, n - 1) |
| 62 | +``` |
| 63 | + |
| 64 | +### **Java** |
| 65 | + |
| 66 | +```java |
| 67 | +class Solution { |
| 68 | + public int distinctIntegers(int n) { |
| 69 | + return Math.max(1, n - 1); |
| 70 | + } |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +### **C++** |
| 75 | + |
| 76 | +```cpp |
| 77 | +class Solution { |
| 78 | +public: |
| 79 | + int distinctIntegers(int n) { |
| 80 | + return max(1, n - 1); |
| 81 | + } |
| 82 | +}; |
| 83 | +``` |
| 84 | +
|
| 85 | +### **Go** |
| 86 | +
|
| 87 | +```go |
| 88 | +func distinctIntegers(n int) int { |
| 89 | + if n == 1 { |
| 90 | + return 1 |
| 91 | + } |
| 92 | + return n - 1 |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +### **...** |
| 97 | + |
| 98 | +``` |
| 99 | +
|
| 100 | +``` |
| 101 | + |
| 102 | +<!-- tabs:end --> |
0 commit comments