-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2507.cpp
More file actions
28 lines (28 loc) · 702 Bytes
/
2507.cpp
File metadata and controls
28 lines (28 loc) · 702 Bytes
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
class Solution {
public:
bool isPrime(int n) {
for (int i = 2; i * i <= n; ++i) {
if (n % i == 0) return false;
}
return true;
}
int smallestValue(int n) {
int temp = n;
bool dividable = true;
int sum = 0;
while (dividable) {
dividable = false;
for (int i = 2; i <= n; ++i) {
if (n % i == 0) {
n /= i;
sum += i;
dividable = true;
break;
}
}
}
if (sum == temp) return sum;
if (isPrime(sum)) return sum;
else return smallestValue(sum);
}
};