typedef unsigned int I; static int xx = 0, xy = 0; I mul (I ier, I icand, I mod){ I q = 1, ac = 0; ier %= mod; icand %= mod; while(q <= ier) q <<= 1; // ier might be too big for this. while(q >>= 1) {ac <<= 1; if (q & ier) ac += icand; while(ac >= mod) {ac -= mod; ++xx;} ++xy;} return ac;} #include int main(){int m = 72; while(--m) { {int j = 55; while(j--) {int k=42; while(k--) if(j*k%m != mul(j, k, m)) printf("i = %d, j = %d, m = %d, i*j%%m = %d, mul(i, j, m) = %d\n", j, k, m, j*k%m, mul(j, k, m));}}} printf("%d reductions in %d steps\n", xx, xy); return 0;} // Yields: 271227 reductions in 609336 steps