int main(void) { unsigned abus[10000] = {0}; unsigned abuidx = 0; unsigned i; for (i=12;i<20162;i++) { if (i < sum_of_divisors(i)) abus[abuidx++] = i; } unsigned numnums[20161] = {0}; for (i=0;i<20161;i++) numnums[i] = (i+1); unsigned j; unsigned asum = 0; for (i=0;i<abuidx;i++) { for (j=0;j<abuidx;j++) { asum = (abus[i] + abus[j]); if (asum <= 20161) numnums[asum-1] = 0; } } unsigned tsum = 0; for (i=0;i<20161;i++) tsum += numnums[i]; printf("%u\n",tsum); return 0; }
int solve() { int abundant_map[LIMIT] = {0}; int map[LIMIT] = {0}; /* whether a num can be written as sum of abundant */ int i, j, ret; /* prepare abundant-map */ for (i = 1; i < LIMIT; i++) { if (sum_of_divisors(i) > 2*i) { abundant_map[i] = 1; } } for (i = 1; i < LIMIT / 2; i++) { if (!abundant_map[i]) continue; for (j = i; j < LIMIT && i + j < LIMIT; j++) if (abundant_map[j]) map[i + j] = 1; } ret = 0; for (i = 1; i < LIMIT; i++) if (!map[i]) ret += i; return ret; }
int main(void) { clock_t start, end; start = clock(); unsigned count=0, num_of_abundants=0, abundant_nums[LIMIT]; for(int n=1; n<LIMIT+1; n++){ if(sum_of_divisors(n) > n){ abundant_nums[num_of_abundants++] = n; } } long unsigned total_sum = 0; // by changing value at index i I mark the numbers not to count int all_nums[LIMIT]; memset(all_nums, '\0', LIMIT); for(int i=0; i<num_of_abundants; i++){ count = i; while(abundant_nums[i] + abundant_nums[count] < LIMIT){ all_nums[abundant_nums[i] + abundant_nums[count]] = 1; count++; } } for (int j = 0; j < LIMIT; j++) { if(all_nums[j] != 1) total_sum += j; } end = clock(); printf("Found: %lu \n", total_sum); printf("Took me %f seconds to come up with a solution\n", ((end-start)/CLOCKS_PER_SEC)*1.0); // 0s :D return 0; }
int main() { int i, j; unsigned long long total = 0; int* abundants = malloc(sizeof(int) * SIZE); for (i = 0; i < SIZE; i++) abundants[i] = 0; for (i=0;i<=SIZE;++i) { if (sum_of_divisors(i) > i) { abundants[i] = 1; } for (j=1;j<=i/2;++j) { if (abundants[j] > 0 && abundants[i-j] > 0) { total -= i; break; } } total += i; } free(abundants); printf("%llu\n", total); }
int main() { short chain[SIZE]; int used[SIZE]; int used_length = 0, i, j, v, length, max_length, max_length_member; for (i = 0; i < SIZE; i++) { chain[i] = 0; } for (i = 1; i < SIZE; i++) { for (j = 0; j < used_length; j++) { //chain[used[j]] = 0; } used_length = 0; v = i; while (chain[v] == 0) { chain[v] = 1; used[used_length++] = v; v = sum_of_divisors(v); if (v > SIZE) { used_length = 0; break; } } for (j = 0; j < used_length; j++) { if (used[j] == v) { length = used_length - j; if (length > max_length) { max_length = length; max_length_member = used[j]; for (j = j + 1;j < used_length; j++) { max_length_member = MIN(max_length_member, used[j]); } } break; } } } printf("%d %d\n", max_length_member, max_length); }
int main() { //printf("%d\n", solve()); printf("sum of divisors 12: %d\n", sum_of_divisors(12)); return 0; }