I am trying to solve a problem on Sphere Online Judge (SPOJ) link to which is: http://www.spoj.com/problems/TRANSP/
The matrix can be thought of as a permutation and its transposition as another permutation. I need to convert the first one into another. I have found a relation between the Cycles in the Permutation and the number of swaps required as:
Minimum Swaps = Total Elements in Permutation - Number of Cycles
However, I don't know how to calculate the matrix of size $2^a 2^b$ where $a+b \leq 500000$.