• + 0 comments

    We have to get an average, which is sum(entries)/num(entries). So, ostensibly, we need sum(f(each permutation))/nPn. But the key is to realize that the operations are commutative, associative, and distributive.

    So we'll always get the same value S. That means that means our expression reduces to nPn*f(one permutation)/nPn = f(one permutation)

    We may as well choose the original permutation. The other thing to help speed up runtime is (a+b)%m = (a%m + b%m)%m