diff options
| author | drbaggy <js5@sanger.ac.uk> | 2022-06-30 22:44:10 +0100 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2022-06-30 22:44:10 +0100 |
| commit | f70fdfee84f602971a4c6c144635883960f2c54f (patch) | |
| tree | 4884421464be2b25e10dfac958d9fafc39e1b319 /challenge-171/ulrich-rieke/cpp/ch-1.cpp | |
| parent | 58f5e220ae958fe48453e45fedc079df6b466d54 (diff) | |
| parent | 7755a024f5e0ed7581cce5bdaf7d1156e83fe076 (diff) | |
| download | perlweeklychallenge-club-f70fdfee84f602971a4c6c144635883960f2c54f.tar.gz perlweeklychallenge-club-f70fdfee84f602971a4c6c144635883960f2c54f.tar.bz2 perlweeklychallenge-club-f70fdfee84f602971a4c6c144635883960f2c54f.zip | |
Merge remote-tracking branch 'upstream/master'
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 ; +} |
