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.<p>Medium</p> <p>You are given a positive integer <code>n</code>.</p> <p>Continuously replace <code>n</code> with the sum of its <strong>prime factors</strong>.</p> <ul> <li>Note that if a prime factor divides <code>n</code> multiple times, it should be included in the sum as many times as it divides <code>n</code>.</li> </ul> <p>Return <em>the smallest value</em> <code>n</code> <em>will take on.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 15</p> <p><strong>Output:</strong> 5</p> <p><strong>Explanation:</strong> Initially, n = 15.</p> <p>15 = 3 * 5, so replace n with 3 + 5 = 8.</p> <p>8 = 2 * 2 * 2, so replace n with 2 + 2 + 2 = 6.</p> <p>6 = 2 * 3, so replace n with 2 + 3 = 5.</p> <p>5 is the smallest value n will take on.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 3</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> Initially, n = 3. 3 is the smallest value n will take on.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= n <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • smallestValue

      public int smallestValue(int n)