This is a follow up on my previous [question][1]. [JS1's answer][2] suggested that I should use a precomputed table containing all permutations of the lowest valid number for each number between 1 and MAX. It was well described how to implement the precomputed table but somewhere I seem to have miserably failed since the code runs much slower than my previous versions of the code. I don't believe there's anything wrong with my lookup table but if that's for any use [here][3] is the code I wrote to obtain all permutations for numbers between 1 and MAX. Something with my code seems off because for larger calculations (the example found in my previous question) the code runs terribly slow. #include <stdio.h> int lookup[] = { #include "table.h" }; #define LENGTH(x) (sizeof(x) / sizeof((x)[0])) #define MAX 1000000 int main(void) { int n[100]; int x, i, j, k, l, m, N; scanf("%d", &N); for(i=0;i<N;i++) scanf("%d", &n[i]); for(x=1;x<MAX;x++) { j=x-1; i=-x; while((unsigned int)(j) < LENGTH(lookup) && lookup[j] != i) ++j; for(l=0;l<N;l++) { m = j; while((k = lookup[++m]) > 0) { if(k%n[l]==0)break; } if(k<0) goto outer; } break; outer: continue; } fprintf(stdout, "%d\n", x); } Perhaps the access time on the array is affecting the speed? [1]: http://codereview.stackexchange.com/questions/107974/optimize-program-to-test-for-divisibility-of-numbers-2-0 [2]: http://codereview.stackexchange.com/questions/107974/optimize-program-to-test-for-divisibility-of-numbers-2-0/107987#107987 [3]: https://gist.github.com/Linkaan/0deb3237648f5982149d