Skip to content

Commit 32043a0

Browse files
committed
Create 2549-CountDistinctNumbersOnBoard.cpp
1 parent 159642a commit 32043a0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

2549-CountDistinctNumbersOnBoard.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
int distinctIntegers(int n) {
4+
std::queue<int> q; q.push(n);
5+
std::set<int> s; s.insert(n);
6+
7+
while(!q.empty()){
8+
int x = q.front(); q.pop();
9+
for(int p = 2; p < x; p++){
10+
if(x % p == 1 && !s.count(p)){s.insert(p); q.push(p);}
11+
}
12+
}
13+
14+
return s.size();
15+
}
16+
};

0 commit comments

Comments
 (0)