Divisor Cutter#13099

Divisor Cutter (Editorial)

Let be the maximum proper divisor of . We want to partition into n_1 + n_2 + \dots + n_k (n_i > 1) to minimize \sum f(n_i).

Notice that the maximum proper divisor f(x) = 1 if and only if is a prime number. For any composite number, f(x) \ge 2. Therefore, to minimize the waste, we should aim to split the log into the minimum possible number of prime parts.

This naturally leads to Goldbach's Conjecture, which states that every even integer greater than 2 can be expressed as the sum of two primes.

Based on this, we can define three cases for :

  1. is prime: We don't split the log at all. The waste is exactly .

  2. is even (and ): By Goldbach's conjecture, can be split into exactly two prime numbers. The waste for each is , making the total waste 1 + 1 = 2.

  3. is odd (and composite): We can try to split into a prime and an even number. If we pull out (the only even prime), we are left with n-2.

    • If n-2 is also prime, we have split into two primes ( and n-2). The waste is .

    • If n-2 is composite, we cannot split into two primes. Instead, we pull out , leaving the even number n-3. By Goldbach's conjecture, n-3 can be split into two primes. This gives us a total of three primes, making the waste .

Complexity: O(\sqrt{n}) per test case for primality testing.