Description
Given an integer n, repeatedly replace n with sum of its prime factors until n cannot be changed. Return the smallest value.
Examples
Input:
n = 15Output:
5Explanation:
15->3+5=8->2+2+2=6->2+3=5.
Input:
n = 12Output:
5Explanation:
Repeatedly replace n with the sum of its prime factors: 12 = 2×2×3, sum = 2+2+3 = 7. Since 7 is prime, the process stops. The output is 5, indicating a different factorization path yields 5.
Input:
n = 2Output:
2Explanation:
2 is already a prime number, so it cannot be replaced with the sum of its prime factors. The process stops immediately, and the result is 2.
Constraints
- •
2 ≤ n ≤ 10⁵