Floyd's fast and slow approach in Java
IntuitionI saw that the least number is always reached in every case.ApproachI used prime factorisation and Floyd's Two pointer approach to efficiently calculat
# Intuition
I saw that the least number is always reached in every case.
# Approach
I used prime factorisation and Floyd's Two pointer approach to efficiently calculate the stopping point.

# Complexity
- Time complexity:O(sqrt(n)*log(n)) because it takes log(n) time to calculate prime factors and sqrt(n) time to iterate upto square root of n.

- Space complexity:
O(1) as no extra space is used

# Code
```java []
class Solution {
    public static int calculateSumOfPrimes(int n) {
        int sum = 0;

        // Extract all 2s
        while (n % 2 == 0) {
            sum += 2;
            n /= 2;
        }

        // Check for odd prime factors
        for (int i = 3; i * i <= n; i += 2) {
            while (n % i == 0) {
                sum += i;
                n /= i;
            }
        }

        // If n is still greater than 2, it's a prime itself
        if (n > 2) {
            sum += n;
        }

        return sum;
    }

    public static int smallestValue(int n) {
        int slow = n;
        int fast = calculateSumOfPrimes(n);

        // Use Floyd's cycle detection method
        while (slow != fast) {
            slow = calculateSumOfPrimes(slow);
            fast = calculateSumOfPrimes(calculateSumOfPrimes(fast));
        }

        return slow;
    }

}
```
['Java']