forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_2549.java
35 lines (33 loc) · 1.11 KB
/
_2549.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.fishercoder.solutions;
import java.util.HashSet;
import java.util.Set;
public class _2549 {
public static class Solution1 {
public int distinctIntegers(int n) {
Set<Integer> total = new HashSet<>();
total.add(n);
Set<Integer> setToGoThrough = new HashSet<>();
setToGoThrough.add(n);
Set<Integer> newSet = new HashSet<>();
int days = 1000000000;
int lastTotal = total.size();
while (days-- > 0) {
for (int num : setToGoThrough) {
for (int i = 1; i <= num; i++) {
if (num % i == 1 && !total.contains(i)) {
newSet.add(i);
}
}
}
setToGoThrough = new HashSet<>(newSet);
total.addAll(newSet);
if (lastTotal == total.size()) {
return total.size();
}
lastTotal = total.size();
newSet.clear();
}
return total.size();
}
}
}