int main(){ int i; int total = 0; clock_t t0 = clock(); for (i = 2; i < LIMIT; i++){ int temp = i, max = 0; while (temp % 9 == 0) { max += 9; temp /= 9; } if (temp > 1){ int localMax = DIGROOT(temp); int * factors; int j = 0; do { factors = twoFactors(temp, j++); localMax = MAX(localMax, arr[factors[0]] + arr[factors[1]]); } while (factors[0] != 0 && j < 9); max += MAX(DIGROOT(temp), localMax); } arr[i] = max; total += max; } printf("Time: %d\tTotal: %d\n", (clock()-t0)/CLOCKS_PER_SEC, total); }
int main(int argc, char** argv) { int tot(0); for (int i = 1; i< 300000; ++i){ if (twoFactors(i)) ++tot; } cout << tot << endl; return 0; }