diff options
Diffstat (limited to 'challenge-171/ulrich-rieke/cpp/ch-1.cpp')
| -rw-r--r-- | challenge-171/ulrich-rieke/cpp/ch-1.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-171/ulrich-rieke/cpp/ch-1.cpp b/challenge-171/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..64182ec9a4 --- /dev/null +++ b/challenge-171/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,32 @@ +#include <iostream> +#include <vector> +#include <numeric> + +std::vector<int> findDivisors( int n ) { + std::vector<int> divisors ; + for ( int i = 1 ; i < (n / 2 ) + 1 ; i++ ) { + if ( n % i == 0 ) + divisors.push_back( i ) ; + } + return divisors ; +} + +bool isAbundant( int n ) { + std::vector<int> divisors = findDivisors( n ) ; + int sum = std::accumulate( divisors.begin( ) , divisors.end( ) , 0 ) ; + return sum > n ; +} + +int main( ) { + std::vector<int> oddAbundant ; + int current = 3 ; + while ( oddAbundant.size( ) != 20 ) { + if ( isAbundant( current ) ) + oddAbundant.push_back( current ) ; + current += 2 ; + } + for ( int n : oddAbundant ) + std::cout << n << ' ' ; + std::cout << std::endl ; + return 0 ; +} |
