Official

C - Blindfolded Cubing Editorial by evima


Let \(a=N(N+1)/2\) and \(b=N(N-1)/2\). Then \(a^2-b^2=N^3\) and \(a+b=N^2\). Therefore, it suffices to make \(a\), obtain \(b\) as \(b=N^2-a\), and take the difference of their squares.

Pair up the terms of \(a=1+2+\cdots+N\) two at a time from the largest. If \(1\) is left over at the end, treat it as \((1+0)\); then the sums of the pairs are \(2N-1,2N-5,2N-9,\ldots\). Adding up all the positive terms among these gives \(a\).

Since addition is not available, we will subtract these from \(N^4\) one by one to make \(N^4-a\).

First, from the initial state \((N,1,0,0)\), make \((2N-1,4,N^4,N^2)\) with the following \(10\) operations in total.

  • Make \(A_4=N^2\), and make \(N^2-2N\) in \(A_3\): \(3\) operations.
  • Set \(A_1=A_4-A_3=2N\), and subtract \(A_2=1\) from it: \(2\) operations.
  • Make \(A_3=A_1-1-1\), set \(A_2=A_1-A_3=2\), and square it: \(4\) operations.
  • Assign \(A_4^2=N^4\) to \(A_3\): \(1\) operation.

Next, repeat - 3 3 1 and - 1 1 2 in this order \(1000\) times. The value subtracted from \(A_3\) starts at \(2N-1\) and decreases by \(4\) each time, becoming \(0\) when it would be negative. There are \(\lceil N/2\rceil\le1000\) positive terms, so for every \(N\), we have \(A_3=N^4-a\) at the end.

After that, make \(A_1=A_4^2=N^4\), and set \(A_3=A_1-A_3=a\) and \(A_4=A_4-A_3=b\). Finally, square each of \(A_3\) and \(A_4\) and set \(A_1=A_3-A_4\) to obtain \(N^3\).

The total is \(10+2\cdot1000+6=2016\) operations, which satisfies the condition.

(Challenge: try to get AC with as few operations as possible.)