Class Solution
- java.lang.Object
-
- g2501_2600.s2507_smallest_value_after_replacing_with_sum_of_prime_factors.Solution
-
public class Solution extends Object
2507 - Smallest Value After Replacing With Sum of Prime Factors.Medium
You are given a positive integer
n.Continuously replace
nwith the sum of its prime factors.- Note that if a prime factor divides
nmultiple times, it should be included in the sum as many times as it dividesn.
Return the smallest value
nwill take on.Example 1:
Input: n = 15
Output: 5
Explanation: Initially, n = 15.
15 = 3 * 5, so replace n with 3 + 5 = 8.
8 = 2 * 2 * 2, so replace n with 2 + 2 + 2 = 6.
6 = 2 * 3, so replace n with 2 + 3 = 5.
5 is the smallest value n will take on.
Example 2:
Input: n = 3
Output: 3
Explanation: Initially, n = 3. 3 is the smallest value n will take on.
Constraints:
2 <= n <= 105
- Note that if a prime factor divides
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intsmallestValue(int n)
-