# Task
 Consider the following operation:
 
 We take a positive integer `n` and replace it with the sum of its `prime factors` (if a prime number is presented multiple times in the factorization of `n`, then it's counted the same number of times in the sum). 
 
 This operation is applied sequentially first to the given number, then to the first result, then to the second result and so on.., until the result remains the same.

  Given number `n`, find the final result of the operation.

# Example

  For `n = 24`, the output should be `5`.
```
24 -> (2 + 2 + 2 + 3) = 9 -> (3 + 3) = 6 -> (2 + 3) = 5 -> 5.
So the answer for n = 24 is 5.```

# Input/Output


 - `[input]` integer `n`

  Constraints: `2 ≤ n ≤ 10000.`


 - `[output]` an integer

Difficulty: introductory

Starter code:

def factor_sum(n):
	

Solutions:
def factor_sum(n):
    while True:
        i=2
        s=0
        a=n
        while i<=n:
            if n%i==0:
                s+=i
                n/=i
                if n==1:
                    break
            else:
                i+=1
                
        if a!=s:
            n=s
        else:
            return s

from functools import lru_cache

@lru_cache(maxsize=None)
def factor_sum(n):
    i, res, save = 2, 0, n
    while i*i <= n:
        while not n%i:
            n, res = n//i, res+i
        i += 1 + i%2 # 2 -> 3 -> 5 -> 7 -> ...
    if n > 2: res += n
    return res if res == save else factor_sum(res)

def prime_factors(n):
    factors = []
    for k in (2, 3):
        while n % k == 0:
            n //= k
            factors.append(k)
    k = 5
    step = 2
    while k * k <= n:
        if n % k:
            k += step
            step = 6 - step
        else:
            n //= k
            factors.append(k)
    if n > 1:
        factors.append(n)
    return factors


def factor_sum(n):
    while True:
        fs = sum(prime_factors(n))
        if fs == n:
            return fs
        n = fs

from collections import Counter

def factors(n):
    c = Counter()
    d = 2
    while d * d <= n:
        while n % d == 0:
            n //= d
            c[d] += 1
        d += 1 + (d>2)
    if n > 1:
        c[n] += 1
    return c

def factor_sum(n):
    while True:
        c = factors(n)
        result = sum(key*value for key, value in c.items())
        if result == n:
            return n
        n = result

r=lambda n:next((p+r(n//p)for p in range(2,int(n**.5)+1)if n%p<1),n)
factor_sum=f=lambda n:(lambda s:s<n and f(s)or n)(r(n))

import math
def factor_sum(n):
    primes = [i for i in range(2, int(math.sqrt(n))+1)]
    while n not in primes:
        if n == sum(prime_factors(n, primes)):
            return n
        n = sum(prime_factors(n, primes))
    return n
    
def prime_factors(n, primes):
    for i in primes:
        for j in primes:
            if j>i and j%i == 0:
                primes.pop(primes.index(j))
    factors = []
    for p in primes:
        while n%p == 0:
            n //= p
            factors.append(p)
    if n != 1:
        factors.append(n)
    return factors

from math import ceil


def is_prime(num):
    if num == 2:
        return True
    for i in range(2, ceil(num**0.5)+1):
        if num % i == 0:
            return False
    return True

def factor_sum(num):
    while not is_prime(num):
        n = num
        factors_sum = 0
        while num % 2 == 0:
            factors_sum += 2
            num /= 2

        i = 3
        max_factor = num**0.5
        while i <= max_factor:
            while num % i == 0:
                factors_sum += i
                num /= i
                max_factor = num**0.5
            i += 2

        if num > 1:
            factors_sum += num

        if n == factors_sum:
            return n
        num = factors_sum
    return num

def aux(x):
    s = 0
    i = 2
    while x > 1:
        while x % i == 0:
            s += i
            x /= i
        i += 1
    return s
def factor_sum(num):
    l = None
    while l != num:
        l = num
        num = aux(num)
    return l

import math
def factors(n):
    f = []
    while n > 1:
        for i in range(2, n + 1):
            if n % i == 0:
                f.append(i)
                n = n // i
                break
    return f

def factor_sum(n):
    f = factors(n)
    last = sum(f)
    while n != f[0]:
        n = sum(f)
        f = factors(n)
        if f == last:
           return n
        last = f
    return n

def factor_sum(n):
    while True:
        t, s, d = n, 0, 2
        while d * d <= t:
            while t % d == 0:
                s += d
                t //= d
            d += 1
        if t > 1:
            s += t
        if s == n:
            return s
        n = s