MatPowModM compute matrix B = A^n % m ; works even if A = B
function MatPowModM input Real[3, 3] A; output Real[3, 3] B; input Real m; input Real n; end MatPowModM;