*/
public static BigInteger orderOfPermutation(short[] permutation) {
//we shall decompose this permutation into product of cycles and calculate l.c.m. of their sizes
//to mark viewed points
BitArray used = new BitArray(permutation.length);
//lcm
BigInteger lcm = BigInteger.ONE, temp;
int start, pointer, currentSize, counter = 0;
//while not all points are seen
//loop over cycles
while (counter < permutation.length) {
//get first point that was not already traversed
start = pointer = used.nextZeroBit(0);
currentSize = 0;
//processing current cycle
//loop over current cycle
do {
assert !used.get(pointer);
used.set(pointer);
pointer = permutation[pointer];
++currentSize;
} while (pointer != start);
counter += currentSize;
temp = BigInteger.valueOf(currentSize);