diff options
| author | E. Choroba <choroba@matfyz.cz> | 2024-01-15 18:32:09 +0100 |
|---|---|---|
| committer | E. Choroba <choroba@matfyz.cz> | 2024-01-15 18:32:09 +0100 |
| commit | 9282ab98cbd52bace35f36e5cff3e6366a85b6fb (patch) | |
| tree | 7927e8584c8e75ce81bcf54743c7f81a69f85044 /challenge-252/e-choroba/cpp/ch-1.cpp | |
| parent | 04368ad24f28250401393f1096c9f6a323e9ef7a (diff) | |
| download | perlweeklychallenge-club-9282ab98cbd52bace35f36e5cff3e6366a85b6fb.tar.gz perlweeklychallenge-club-9282ab98cbd52bace35f36e5cff3e6366a85b6fb.tar.bz2 perlweeklychallenge-club-9282ab98cbd52bace35f36e5cff3e6366a85b6fb.zip | |
Add C++ solutions
Diffstat (limited to 'challenge-252/e-choroba/cpp/ch-1.cpp')
| -rw-r--r-- | challenge-252/e-choroba/cpp/ch-1.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/challenge-252/e-choroba/cpp/ch-1.cpp b/challenge-252/e-choroba/cpp/ch-1.cpp new file mode 100644 index 0000000000..ec85e36bf0 --- /dev/null +++ b/challenge-252/e-choroba/cpp/ch-1.cpp @@ -0,0 +1,21 @@ +#include <cassert> +#include <cmath> +#include <iostream> +#include <vector> + +long special_numbers(std::vector<long> ints) { + size_t s = ints.size(); + long r = 0; + for (size_t i = 0; i <= s; ++i) { + if (s % (i + 1) == 0) { + r += std::pow(ints[i], 2); + } + } + return r; +} + +int main(int argc, char* argv[]) { + assert(special_numbers({1, 2, 3, 4}) == 21); + assert(special_numbers({2, 7, 1, 19, 18, 3}) == 63); + std::cout << "Ok." << std::endl; +} |
