Swift Solution
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```swift []
class Solution {
private func primeFactors(_ n: Int) -> [Int] {
    guard n > 1 else { return [] }
    var primes: [Int] = []
    var number = n
    for i in 2...number {
        while number % i == 0 {
            primes.append(i)
            number /= i
        }
    }
   return primes
}

private func isPrime(_ n: Int) -> Bool {
    if n < 2 { return false }
    for i in 2 ..< n {
        if n % i == 0 { return false }
    }
    return true
}

func smallestValue(_ n: Int) -> Int {
     var n = n
    while !isPrime(n) {
        let sum  = primeFactors(n).reduce(0, +)
        if sum == n {
            return n
        }
        n =  sum
    }
    
    return n
}
}
```
['Swift']