#include static const unsigned int divtab[244] = { [1] = 0xffff + 1l, [3] = 0x5555 + 1l, [9] = 0x1c71 + 1l, [27] = 0x097b + 1l, [81] = 0x0329 + 1l, [243] = 0x010d + 1l }; #define FASTDIV(n, C) (((n) * (C)) >> 16) #define FASTMOD(n, d, C) ((n) - (d) * FASTDIV((n), (C))) int new32(int i, int x, int y) { int A, B, C; A = FASTDIV(i, divtab[y]); B = FASTMOD(A, 3, divtab[3]); C = FASTMOD(A + x, 3, divtab[3]); return i + (C - B) * y; }