#include <stdio.h> #include <stdlib.h> #include <stdint.h> int main(int argc, char **argv) { if (argc == 2) { uint64_t max = strtoull(argv[1], NULL, 10); uint64_t *terms = calloc((((max + 1) >> 6) + 1), sizeof(*terms)); for (uint64_t i = 1; i <= max; i++) { if (!((terms[i >> 6] >> (i & 0x3F)) & 1)) { printf("%llu ", i); uint64_t total = i; for (uint64_t j = i - 1; j >= 1; j--) { if (!((terms[j >> 6] >> (j & 0x3F)) & 1)) { total += j; if (total > max) { break; } terms[total >> 6] |= (1ULL << (total & 0x3F)); } } } } free(terms); } printf("\n"); return 0; }