← RoseCode

ROSECODE 333

Subtracting proper divisors

Philippe_57721 · Programming ·

Given an integer n, we apply the following process:
- search the largest proper divisor of n
- subtract this number from n
- repeat until we reach 1

Let f(n) the number of steps before reaching 1.

Example with n = 30
  • n = 30 - 15 (15 = Largest proper divisor of 30)
  • n = 15 - 5 (5 = Largest proper divisor of 15)
  • n = 10 - 5 (5 = Largest proper divisor of 10)
  • n = 5 - 1 (1 = Largest proper divisor of 5)
  • n = 4 - 2 (2 = Largest proper divisor of 4)
  • n = 2 - 1 (1 = Largest proper divisor of 2)
  • n = 1 Stop => f(30) = 6
Find f(1000000!) // Factorial(1000000)

[My timing: 6 sec]