-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
650.java
27 lines (27 loc) · 801 Bytes
/
650.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
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public int minSteps(int n) {
if (n == 1) return 0;
for (int i = 2; i <= Math.sqrt(n); i++) {
if (n % i == 0) return i + minSteps(n / i);
}
return n;
}
}
__________________________________________________________________________________________________
sample 31668 kb submission
class Solution {
public int minSteps(int n) {
int ans = 0, d = 2;
while (n > 1) {
while (n % d == 0) {
ans += d;
n /= d;
}
d++;
}
return ans;
}
}
__________________________________________________________________________________________________