main.c (828B)
1 #include<stdio.h> 2 #include<stdbool.h> 3 #include<stdlib.h> 4 5 // bruteforce https://oeis.org/A213918 6 7 int res[10]; 8 int num = 0; 9 10 bool ok(int i, int found) { 11 for (int j = 0; j < found; j++) { 12 if (res[j] % (i - res[j])) 13 return false; 14 } 15 return true; 16 } 17 18 bool search(int ci, int maxi, int found, int tofind) { 19 if (found == tofind) 20 return true; 21 for (int i = ci+1; i < maxi; i++) { 22 if (!ok(i, found)) 23 continue; 24 res[found] = i; 25 if (search(i, maxi, found+1, tofind)) 26 return true; 27 } 28 return false; 29 } 30 31 int main(int argc, char **argv) { 32 int k = atoi(argv[1]); 33 int n = atoi(argv[2]); 34 res[0] = 0; 35 if (search(0, k, 1, n)) { 36 printf("solution found:\n"); 37 for (int i = 0; i < n; i++) 38 printf("%d ", res[i]); 39 printf("\n"); 40 } else { 41 printf("nothing found :(\n"); 42 } 43 } 44