7

Given a number n, Here are two operations can be taken:

  • n - 1
  • n divide by its prime factor

Question: In order to decompose n to 1, what is the minimal operations should be taken?

For example, in term of number 29, it is a prime number. So, the number of operation is 1. For number 30, the number of operations is 2(30 minus 1 and it is a prime number).

PS: It seems that we can decompose a number in no more than 4 operations(Not sure).

unknown
  • 89
  • 1
    What do you do when a number has more than one prime factor? Do you get to choose which prime factor to divide by? – Gerry Myerson Sep 27 '22 at 13:42
  • 3
    It can require $5$ operations too, the first number that requires it is $27436$ – EnEm Sep 27 '22 at 13:54
  • @EnEm Please spare my feelings and tell me you didn't do the calculations in your head. – user2661923 Sep 27 '22 at 14:54
  • 1
    @user2661923 LOL NO! Who would hurt themselves like that? Ran a small python script which is still running to check for 6 operations – EnEm Sep 27 '22 at 15:25
  • 1
    First of all, Gerry's comment should be clarified. Can we choose the prime factor to get an optimal solution ? – Peter Sep 27 '22 at 15:27
  • @Peter Per EnEm's find of $(27436)$ at each step, you can (presumably ?) either deduct $(1)$ or divide by any of the (current) number's prime factors. – user2661923 Sep 27 '22 at 15:30
  • I would interprete it this way as well. – Peter Sep 27 '22 at 15:31
  • Intuitively , I guess the number of necessary operations grows without bound , but quite slowly. Large numbers tend to be composite. Trivial upper bounds are bigomega(n) and $n-p+1$ , if $p$ is the largest prime not exceeding $n$. So to get hard cases, we need numbers with a large number of (repeated) prime factors and far above the closest smaller prime. – Peter Sep 27 '22 at 15:36
  • 2
    "its prime factor"? That's not well defined. I don't understand how is there so much discussion here about a ill-posed problem. – jjagmath Sep 27 '22 at 16:01
  • 1
    @jjagmath You are right, but some users seem to assume that we can divide by which prime factor we want and the task is to minimize the number of steps. I also wonder that the users do not wait until this is clarified. The Python-routine however is surely interesting. To the programmer : How do you efficiently enumerate over all possibilities ? – Peter Sep 27 '22 at 16:03

2 Answers2

6

Let $f(n)$ be the minimal number of operations (subtracting $1$ or dividing by any prime factor of $n$) required to reach $1$ from $n$. I claim that not only is $f(n)$ unbounded, but for any positive integer $k$, the set of $n$ for which $f(n)>k$ has density $1$ (that is, "almost all" integers have $f(n)>k$). This follows from the upper bound $$ \#\{n\le x\colon f(n)\le k\} \ll_k \frac{x(\log\log x)^{k-1}}{\log x} \tag{$*$} $$ which we can prove by induction on $k$. The base case $k=1$ follows from the prime number theorem since $f(n)=1$ is equivalent to $n$ being prime.

Suppose the upper bound ($*$) holds for some integer $k$. Consider integers $n$ such that $f(n)\le k+1$. One possibility is that $f(n-1) \le k$; by hypothesis there are only $\ll_k x(\log\log x)^{k-1}/\log x$ such integers $n\le x$. The other possibility is that there exists a prime $p\le x$ and an integer $m\le x/p$ with $f(m)\le k$ such that $n=mp$. But the number of such integers is at most \begin{align*} \sum_{p\le x} \#\{m\le x\colon f(m)\le k\} &\ll_k \sum_{p\le x} \frac{\frac xp(\log\log \frac xp)^{k-1}}{\log \frac xp} \\ &\ll_k \frac{x(\log\log x)^{k-1}}{\log x} \sum_{p\le x} \frac1p \ll \frac{x(\log\log x)^{k-1}}{\log x} \log\log x \end{align*} as required to establish ($*$) for $k+1$.

It would be interesting to look at the distribution of $f(n)$. For example, $f(n)$ is certainly bounded above by the number of prime factors of $n$; does $f(n)$ follow the same Erdös–Kac law? (In the above argument, it depends on the size of the implicit constant depending on $k$.)

Greg Martin
  • 78,820
  • Wow, thank you for taking the time to post this. I was expecting it to be unbounded but seeing a proof like this is really satisfying. Though can you elaborate a little on the $\sum_{p\le x} \frac{\frac xp(\log\log \frac xp)^{k-1}}{\log \frac xp} \ll_k \frac{x(\log\log x)^{k-1}}{\log x} \sum_{p\le x} \frac1p$ part?, Can't $\log (x/p)$ be really smaller than $x$? Also here is the distribution of $f(n)$ up until $5\cdot 10^7$ : https://imgur.com/a/QgFPYxe , I've checked till $3 \cdot 10^8$ but cannot find a $f(n)=6$, must be somewhere around the $10^9$ mark – EnEm Sep 27 '22 at 16:47
  • 1
    While $\log\frac xp$ can be a lot smaller than $x$, that happens for only a few small primes ($\log\frac xp\ll\log x$ holds for all primes above $\sqrt x$ for example), so the overall bound still holds. – Greg Martin Sep 27 '22 at 20:14
  • Thanks for your reply. Further, how can I make a strategy to get to 1 from n in minimal operations? – unknown Sep 28 '22 at 01:37
2

Here's a simple Python script that will count the number of steps needed to reach 1, for all integers less than a million:

import math

def prime_factors(n): ''' Return a set of the unique prime factors of n. ''' result = set() upper_bound = int(math.sqrt(n) * 1.00000001) for divisor in range(2, upper_bound + 1): if n == 1: return result while n % divisor == 0: result.add(divisor) n //= divisor # If we reach this point, n itself is prime result.add(n) return result

number of steps required to reduce the number to 1

STEP_COUNT = [None, 0] for n in range(2, 10**6): next_step = {n - 1} | {n // p for p in prime_factors(n)} - {n} num_steps = 1 + min(STEP_COUNT[ns] for ns in next_step) STEP_COUNT.append(num_steps)

PS: It seems that we can decompose a number in no more than 4 operations(Not sure).

Not true for $n = 27436 = 2^2 19^3$, which requires 5 steps (all divisions by a prime factor).

More generally,

  • 1 is the only number requiring 0 steps.
  • 2 is the smallest number requiring 1 step.
  • 4 is the smallest number requiring 2 steps.
  • 16 is the smallest number requiring 3 steps.
  • 176 is the smallest number requiring 4 steps.
  • 27436 is the smallest number requiring 5 steps.
  • 602868736 is the smallest number requiring 6 steps. (Thanks to @EnEm.)
Dan
  • 14,978
  • 1
    @Peter: I'm running it again with a greater upper bound. Will let you know if/when I find one. – Dan Sep 27 '22 at 16:28
  • 1
    OK, I am curious ! By the way . +1. – Peter Sep 27 '22 at 16:29
  • 1
    You can run sieve first and store all the primes in their own lists to decrease runtime from $O(n\sqrt{n})$ to $O(n\log\log n)$, the memory requirement will increase but will still be almost linear. Also C++ helps – EnEm Sep 27 '22 at 16:35
  • 1
    Well, I let it run up to n = 18 269 364 before I stopped it. Still haven't found any numbers requiring 6 steps. – Dan Sep 27 '22 at 17:06
  • 1
    @Peter It's $602868736$ – EnEm Sep 27 '22 at 18:03
  • 2
    Wow, did you use brute force only or the below function ? – Peter Sep 27 '22 at 18:05
  • 1
    Nah I don't think the Greg's answer gives a good function to find the lowest possible n-step number. It can be used to find any n-step number by picking a random number though. I brute forced it up until $10^9$ – EnEm Sep 27 '22 at 18:11