Skip to content

Latest commit

 

History

History
80 lines (52 loc) · 1.64 KB

2507-smallest-value-after-replacing-with-sum-of-prime-factors.adoc

File metadata and controls

80 lines (52 loc) · 1.64 KB

2507. Smallest Value After Replacing With Sum of Prime Factors

{leetcode}/problems/smallest-value-after-replacing-with-sum-of-prime-factors/[LeetCode - 2507. Smallest Value After Replacing With Sum of Prime Factors ^]

You are given a positive integer n.

Continuously replace n with the sum of its prime factors.

  • Note that if a prime factor divides n multiple times, it should be included in the sum as many times as it divides n.

Return the smallest value _`n` will 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

思路分析

看答案有些懵逼,没看到计算质数的过程。

一刷
link:{sourcedir}/_2507_SmallestValueAfterReplacingWithSumOfPrimeFactors.java[role=include]