2507. Smallest Value After Replacing With Sum of Prime Factors Medium

@problem@discussion
#Math#Number Theory



1/**
2 * [2507] Smallest Value After Replacing With Sum of Prime Factors
3 *
4 * You are given a positive integer n.
5 * Continuously replace n with the sum of its prime factors.
6 * 
7 * 	Note that if a prime factor divides n multiple times, it should be included in the sum as many times as it divides n.
8 * 
9 * Return the smallest value n will take on.
10 *  
11 * <strong class="example">Example 1:
12 * 
13 * Input: n = 15
14 * Output: 5
15 * Explanation: Initially, n = 15.
16 * 15 = 3 * 5, so replace n with 3 + 5 = 8.
17 * 8 = 2 * 2 * 2, so replace n with 2 + 2 + 2 = 6.
18 * 6 = 2 * 3, so replace n with 2 + 3 = 5.
19 * 5 is the smallest value n will take on.
20 * 
21 * <strong class="example">Example 2:
22 * 
23 * Input: n = 3
24 * Output: 3
25 * Explanation: Initially, n = 3.
26 * 3 is the smallest value n will take on.
27 * 
28 *  
29 * Constraints:
30 * 
31 * 	2 <= n <= 10^5
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/smallest-value-after-replacing-with-sum-of-prime-factors/
37// discuss: https://leetcode.com/problems/smallest-value-after-replacing-with-sum-of-prime-factors/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn smallest_value(n: i32) -> i32 {
43        0
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_2507() {
55    }
56}
57


Back
© 2025 bowen.ge All Rights Reserved.