Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,990 questions

51,935 answers

573 users

How to print the first 25 abundant odd numbers in C++

1 Answer

0 votes
#include <iostream>
#include <cmath>

// abundant odd number = sum of proper divisors > number

unsigned SumOddNumberProperDivisors(const unsigned num) {
    unsigned sum = 1;
     
    for (unsigned i = 3, j; i < sqrt(num) + 1; i += 2) 
        if (num % i == 0) 
            sum += i + (i == (j = num / i) ? 0 : j);
     
    return sum;
}

int main() {
    for (unsigned num = 1, i = 0; i < 25; num += 2) {
        if (SumOddNumberProperDivisors(num) > num) {
            std::cout << ++i << " " << num << "\n";
        }
    }
}




/*
run:

1 945
2 1575
3 2205
4 2835
5 3465
6 4095
7 4725
8 5355
9 5775
10 5985
11 6435
12 6615
13 6825
14 7245
15 7425
16 7875
17 8085
18 8415
19 8505
20 8925
21 9135
22 9555
23 9765
24 10395
25 11025

*/

 



answered Oct 23, 2022 by avibootz

Related questions

1 answer 85 views
1 answer 89 views
1 answer 79 views
2 answers 95 views
1 answer 85 views
1 answer 94 views
...