int sum_amicables(int n) { int sum = 0; for (int i = 1; i <= n; ++i) { if (is_amicable(i)) { sum += i; } } return sum; }
int main(){ int i; int amicableSum = 0; for(i=1; i<10000; i++){ if(is_amicable(i,divisor_sum(i))) amicableSum += divisor_sum(i); } printf("%d\n",amicableSum); }
int main() { auto start = std::chrono::steady_clock::now(); typedef long type; std::vector<type> r; type b; for (type a{1}; a<10000; ++a) if (is_amicable(a, b)) { r.push_back(a); r.push_back(b); } std::cout << "Sum: " << std::accumulate(r.begin(), r.end(), type{0}) << "\n"; std::cout << std::chrono::duration<double, std::milli> (std::chrono::steady_clock::now() - start).count() << " ms\n"; }
int print_properties_num(longnum num) { printf("%llu:\nprime factors: ", num); print_prime_factors(num); printf("\n"); if ( is_abundant(num) ) printf(" abundant"); if ( is_amicable(num) ) printf(" amicable"); if ( is_apocalyptic_power(num) ) printf(" apocalyptic_power"); if ( is_aspiring(num) ) printf(" aspiring"); if ( is_automorphic(num) ) printf(" automorphic"); if ( is_cake(num) ) printf(" cake"); if ( is_carmichael(num) ) printf(" carmichael"); if ( is_catalan(num) ) printf(" catalan"); if ( is_composite(num) ) printf(" composite"); if ( is_compositorial(num) ) printf(" compositorial"); if ( is_cube(num) ) printf(" cube"); if ( is_deficient(num) ) printf(" deficient"); if ( is_easy_to_remember(num) ) printf(" easy_to_remember"); if ( is_ecci1(num) ) printf(" ecci1"); if ( is_ecci2(num) ) printf(" ecci2"); if ( is_even(num) ) printf(" even"); if ( is_evil(num) ) printf(" evil"); if ( is_factorial(num) ) printf(" factorial"); if ( is_fermat(num) ) printf(" fermat"); if ( is_fibonacci(num) ) printf(" fibonacci"); if ( is_google(num) ) printf(" google"); if ( is_happy(num) ) printf(" happy"); if ( is_hungry(num) ) printf(" hungry"); if ( is_hypotenuse(num) ) printf(" hypotenuse"); if ( is_lazy_caterer(num) ) printf(" lazy_caterer"); if ( is_lucky(num) ) printf(" lucky"); if ( is_mersenne_prime(num) ) printf(" mersenne_prime"); if ( is_mersenne(num) ) printf(" mersenne"); if ( is_narcissistic(num) ) printf(" narcissistic"); if ( is_odd(num) ) printf(" odd"); if ( is_odious(num) ) printf(" odious"); if ( is_palindrome(num) ) printf(" palindrome"); if ( is_palindromic_prime(num) ) printf(" palindromic_prime"); if ( is_parasite(num) ) printf(" parasite"); if ( is_pentagonal(num) ) printf(" pentagonal"); if ( is_perfect(num) ) printf(" perfect"); if ( is_persistent(num) ) printf(" persistent"); if ( is_power_of_2(num) ) printf(" power_of_2"); if ( is_powerful(num) ) printf(" powerful"); if ( is_practical(num) ) printf(" practical"); if ( is_prime(num) ) printf(" prime"); if ( is_primorial(num) ) printf(" primorial"); if ( is_product_perfect(num) ) printf(" product_perfect"); if ( is_pronic(num) ) printf(" pronic"); if ( is_repdigit(num) ) printf(" repdigit"); if ( is_repunit(num) ) printf(" repunit"); if ( is_smith(num) ) printf(" smith"); if ( is_sociable(num) ) printf(" sociable"); if ( is_square_free(num) ) printf(" square_free"); if ( is_square(num) ) printf(" square"); if ( is_tetrahedral(num) ) printf(" tetrahedral"); if ( is_triangular(num) ) printf(" triangular"); if ( is_twin(num) ) printf(" twin"); if ( is_ulam(num) ) printf(" ulam"); if ( is_undulating(num) ) printf(" undulating"); if ( is_untouchable(num) ) printf(" untouchable"); if ( is_vampire(num) ) printf(" vampire"); if ( is_weird(num) ) printf(" weird"); printf("\n\n"); return 0; }