51

For the numbers $1, \ldots, N$, how many ways can I arrange them such that either:

  • The number at $i$ is evenly divisible by $i$, or
  • $i$ is evenly divisible by the number at $i$.

Example: for $N = 2$, we have:

  • $\{1, 2\}$

    • number at $i = 1$ is $1$ and is evenly divisible by $i = 1$.
    • number at $i = 2$ is $2$ and $i = 2$ is evenly divisible by $2$.
  • $\{2, 1\}$

    • number at $i = 1$ is $2$ and is evenly divisible by $i = 1$.
    • number at $i = 2$ is $1$ and $i = 1$ is evenly divisible by $1$.

so there are two such arrangements for $N = 2$.

joriki
  • 242,601
lissachen
  • 619
  • 5
    Point of interest: Where did this problem come from? Did you make it up, or did it come from a book, or what? – Brian Tung Jul 19 '16 at 17:19
  • Also, point of clarification: Any number can therefore appear in the first position, and $1$ can appear in any position, is that right? – Brian Tung Jul 19 '16 at 17:20
  • So basically, the $i$th position contains either a divisor of $i$ or a multiple of $i$, meaning there are $\lfloor N/i \rfloor+d(i)-1$ possible options for the $i$th position, where $d(n)$ is the number of divisors of $n$. – JasonM Jul 19 '16 at 17:21
  • 1
    I saw the first three lines of this question on the back of a textbook. Well that's how I remember the questions. I went away thinking I could solve the question, but when I couldn't I formulated it more formally for myself and then here. – lissachen Jul 19 '16 at 17:23
  • 1
    Such permutations do not form a group under composition, for otherwise surely $(1, k)$ would be in such a group for any $k$, yet composing these forms all permutations, which is certainly not the case for $N \geq 3$. – JasonM Jul 19 '16 at 17:58
  • 13
    As I understand the question, the number of combinations for $N = 1$ to $10$ are $1, 2, 3, 8, 10, 36, 41, 132, 250, 700$. I couldn't find this sequence in OEIS, but it's possible I've made an error somewhere. – Brian Tung Jul 19 '16 at 18:08
  • @BrianTung I checked the first five by hand. If the 36 is right, then it's certainly not in OEIS, since the only hit is not monotonically increasing. – Bart Michels Jul 19 '16 at 18:14
  • I checked @BrianTung's number with GAP, and got the same result. Thanks to JasonM and barto for explaining to me, in a comment to an attempted answer of mine, that I had misunderstood the problem. – Andreas Caranti Jul 19 '16 at 20:43
  • 2
    We're looking for the number of partitions into directed cycles of the undirected Hasse diagram of the divisibility poset. – Bart Michels Jul 19 '16 at 20:54
  • @barto And with that, I think the tag "elementary-number theory" can be removed. This is clearly a very complex problem. – JasonM Jul 20 '16 at 01:58
  • 1
    @JasonM I think the tag does no harm. After all, the problem originates in number theory. – Bart Michels Jul 20 '16 at 07:50
  • @BrianTung: I don't understand how you generated $1, 2, 3, 8, 10, 36, 41, 132, \ldots$. Could you please explain? – lissachen Jul 20 '16 at 16:58
  • @lissachen: Sure, although I don't think it's particularly enlightening. I wrote a piece of code to go through all $N!$ permutations for $N = 1$ to $10$, and then counted up the ones that satisfied the condition. I'm afraid that isn't going to be much help toward an analytical understanding. – Brian Tung Jul 20 '16 at 17:54
  • Expanding a bit on the cycle partitioning of the Hasse diagram: the graph contains complete subgraphs of size $k$ for each prime power $p^k\leq n$. A complete graph of size $k$ has $B_k$ (Bell-number) partitions into cycles. The number of partitions where no cycle passes through multiple of those complete subgraphs is thus a certain product of Bell-numbers. One could then analyse the cases where cycles can pass through two of those subgraphs, etc... Maybe, with a lot of work, there is a closed form in terms of sums and products of Bell-numbers... – Bart Michels Jul 20 '16 at 20:29
  • In the first case, we have the fact that N has to be the last in the list. In fact you could argue the same for the second last element ... and the N-y to last in general. The second case, gets a little more interesting. If N is prime in this case we have the possibility set {1,N}, in general we have the number of values less than N that have i as a divisor. so we have $N,\lfloor\frac{N}{2}\rfloor,\lfloor\frac{N}{3}\rfloor,\ldots$ numbers posisble in each place. The problem then is that there's some overlap. placing them distinctly becomes harder. –  Jun 30 '17 at 13:32
  • Whoops the bijection statement I made is not true so the $\frac{1}{n-1} T_{n-1}$ part is wrong. In any case, here are the values for $N=1,...29$, computed via enumeration (recursive backtracking): [1, 2, 3, 8, 10, 36, 41, 132, 250, 700, 750, 4010, 4237, 10680, 24679, 87328, 90478, 435812, 449586, 1939684, 3853278, 8650900, 8840110, 60035322, 80605209, 177211024, 368759752, 1380348224, 1401414640]. – Andrew Szymczak Sep 14 '17 at 15:59
  • And more $T_{30} = 8892787136$ and $T_{31} = 9014369784$. – Andrew Szymczak Sep 15 '17 at 02:44
  • 2
    $T_{32} = 33923638848$... As @barto said, we need to count the number of cycle partitions of the undirected divisibility graph (edge if $i|j$ or $j|i$). This is equivalent to computing the permanent of the adjacency matrix, which is in general NP-hard. Here is my $\mathcal{O}(n 2^n)$ python implementation that uses the BBFG formula. – Andrew Szymczak Sep 17 '17 at 06:24
  • 14
    In 2018, OEIS A320843 was added for the sequence in question. – Fabius Wiesner Dec 20 '20 at 17:37
  • @almagest: Sorry, re-establishing context. I don't know how you got $T_6 = 26$, but $T_7-T_6 = 5 = |A|$ where $A = {(7, 2, 3, 4, 5, 6, 1), (7, 2, 6, 4, 5, 3, 1), (7, 4, 3, 2, 5, 6, 1), (7, 4, 6, 2, 5, 3, 1), (7, 6, 3, 4, 5, 2, 1)}$. – Brian Tung Jan 14 '21 at 23:32
  • @BrianTung Ah, many thanks! I stupidly missed the last one, where $3,4$ remain in their places, but $2,6$ swap places. No doubt I made a slimilar kind of mistake in going from $T_5$ to $T_6$. – almagest Jan 16 '21 at 16:18
  • @BillyJoe: Thanks for the heads up! – Brian Tung Jan 16 '21 at 17:36

1 Answers1

1

[reformulation that might be useful]


The following matrix tells if the number $j$ can be the $i$-th term of the sequence ($1$ means 'true', $0$ means 'false'). The general term is $M_{ij}$ and the index counting starts at $1$.

$$M = \begin{bmatrix}[1] & [1] & [1] & [1] & [1] & [1] & [1] & [1] & [1] & \cdots \\ (1) & [1 & 0] & [1 & 0] & [1 & 0] & [1 & 0] & \cdots\\ (1) & 0 & [1 & 0 & 0] & [1 & 0 & 0] & [1 & \cdots\\ (1) & (1) & 0 & [1 & 0 & 0 & 0] & [1 & 0 & \cdots\\ (1) & 0 & 0 & 0 & [1 & 0 & 0 & 0 & 0] & \cdots\\ (1) & (1) & (1) & 0 & 0 & [1 & 0 & 0 & 0 & \cdots\\ (1) & 0 & 0 & 0 & 0 & 0 & [1 & 0 & 0 & \cdots\\ (1) & (1) & 0 & (1) & 0 & 0 & 0 & [1 & 0 & \cdots\\ (1) & 0 & (1) & 0 & 0 & 0 & 0 & 0 & [1 & \cdots\\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \ddots \end{bmatrix}$$

Below the main diagonal, each $(1)$ value indicates that $j$ divides $i$. In the rest of each row, we have a pattern for the multiples of $i$, which is a 'one' followed by $i-1$ 'zeroes': $\begin{bmatrix}1&0&0&\cdots&0\end{bmatrix}$.

Note that $M$ is $\textbf{symmetric}$! So the pattern for the multiples can be seen in the columns too, even for the values below the main diagonal:

$$M = \begin{bmatrix}\color{blue}{1} & \color{blue}{1} & \color{blue}{1} & \color{blue}{1} & \color{blue}{1} & \color{blue}{1} & \color{blue}{1} & \color{blue}{1} & \color{blue}{1} & \color{blue}{\cdots} \\ \color{blue}{1} & \color{green}{1} & \color{green}{0} & \color{green}{1} & \color{green}{0} & \color{green}{1} & \color{green}{0} & \color{green}{1} & \color{green}{0} & \color{green}{\cdots}\\ \color{blue}{1} & \color{green}{0} & \color{red}{1} & \color{red}{0} & \color{red}{0} & \color{red}{1} & \color{red}{0} & \color{red}{0} & \color{red}{1} & \color{red}{\cdots}\\ \color{blue}{1} & \color{green}{1} & \color{red}{0} & \color{orange}{1} & \color{orange}{0} & \color{orange}{0} & \color{orange}{0} & \color{orange}{1} & \color{orange}{0} & \color{orange}{\cdots}\\ \color{blue}{1} & \color{green}{0} & \color{red}{0} & \color{orange}{0} & \color{magenta}{1} & \color{magenta}{0} & \color{magenta}{0} & \color{magenta}{0} & \color{magenta}{0} & \color{magenta}{\cdots}\\ \color{blue}{1} & \color{green}{1} & \color{red}{1} & \color{orange}{0} & \color{magenta}{0} & \color{brown}{1} & \color{brown}{0} & \color{brown}{0} & \color{brown}{0} & \color{brown}{\cdots}\\ \color{blue}{1} & \color{green}{0} & \color{red}{0} & \color{orange}{0} & \color{magenta}{0} & \color{brown}{0} & \color{gray}{1} & \color{gray}{0} & \color{gray}{0} & \color{gray}{\cdots}\\ \color{blue}{1} & \color{green}{1} & \color{red}{0} & \color{orange}{1} & \color{magenta}{0} & \color{brown}{0} & \color{gray}{0} & \color{cyan}{1} & \color{cyan}{0} & \color{cyan}{\cdots}\\ \color{blue}{1} & \color{green}{0} & \color{red}{1} & \color{orange}{0} & \color{magenta}{0} & \color{brown}{0} & \color{gray}{0} & \color{cyan}{0} & \color{teal}{1} & \color{teal}{\cdots}\\ \color{blue}{\vdots} & \color{green}{\vdots} & \color{red}{\vdots} & \color{orange}{\vdots} & \color{magenta}{\vdots} & \color{brown}{\vdots} & \color{gray}{\vdots} & \color{cyan}{\vdots} & \color{teal}{\vdots} & \ddots \end{bmatrix}$$


Once we have this matrix, the problem can be reformulated as:

  • what is the number of row-permutations (or column-permutations) that keep the diagonal full of 'ones'?

Which I believe is equivalent to what Andrew Szymczak said in the comments: "we need to count the number of cycle partitions of the undirected divisibility graph (edge if i|j or j|i). This is equivalent to computing the permanent of the adjacency matrix, which is in general NP-hard."


As a small development to the problem, we might define an upper bound for the number of valid sequences.

Note that any prime number $p$ such that $\frac{N}{2} < p \leq N$ has only two possible positions ($i=1$ and $i=p$). And that, if one of these prime numbers is used as the first term, then the $p$-th term must be $1$.

Therefore, if $m$ is the number of prime numbers in $\left]\frac{N}{2},N\right]$, the number of valid sequences can be, at most, $\boxed{[N-m]! + m\,[N-m-1]!}$.

For $N$ ranging from $2$ to $10$, this upper bound is $\{2,3,8,10,144,168,960,6\,480,403\,200\}$. It corresponds to the exact number of valid sequences only for $N\leq 5$, after that, it rapidly becomes much larger than the exact number. Evidently, to have lower upper bounds, more terms must be considered in the analysis (not only a few prime numbers).

Daniel Cunha
  • 1,842