← Complete problem index

PROJECT EULER · #0913

Row-major vs Column-major

Statement only · UnsolvedOriginal problem ↗

The numbers from 1 to 12 can be arranged into a 3×4 matrix in either row-major or column-major order: R=(123456789101112),C=(147102581136912) By swapping two entries at a time, at least 8 swaps are needed to transform R to C.

Let S(n,m) be the minimal number of swaps needed to transform an n×m matrix of 1 to nm from row-major order to column-major order. Thus S(3,4)=8.

You are given that the sum of S(n,m) for 2nm100 is 12578833.

Find the sum of S(n4,m4) for 2nm100.

Write-up coming later

The complete problem is available here. An approach, code, and answer will be added later.