aboutsummaryrefslogtreecommitdiff
path: root/challenge-089/ash/cpp
diff options
context:
space:
mode:
authorAndrew Shitov <andy@shitov.ru>2020-12-04 09:17:37 +0100
committerAndrew Shitov <andy@shitov.ru>2020-12-04 09:17:37 +0100
commitfdd800775ca52e7600d78f38e5345a5197cc086c (patch)
tree83e6da7d9535c716d29a57bab98f2a91cdcf4994 /challenge-089/ash/cpp
parentd19b0f983bbefca06f6139624711c079ac18eb6e (diff)
downloadperlweeklychallenge-club-fdd800775ca52e7600d78f38e5345a5197cc086c.tar.gz
perlweeklychallenge-club-fdd800775ca52e7600d78f38e5345a5197cc086c.tar.bz2
perlweeklychallenge-club-fdd800775ca52e7600d78f38e5345a5197cc086c.zip
Week 89 Issue 1
Diffstat (limited to 'challenge-089/ash/cpp')
-rw-r--r--challenge-089/ash/cpp/ch-1.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-089/ash/cpp/ch-1.cpp b/challenge-089/ash/cpp/ch-1.cpp
new file mode 100644
index 0000000000..b2500a4630
--- /dev/null
+++ b/challenge-089/ash/cpp/ch-1.cpp
@@ -0,0 +1,29 @@
+// Compile as:
+// $ g++ -std=c++17 ch-1.cpp
+
+// Test run:
+// $ ./a.out 100
+// 13015
+
+#include <iostream>
+#include <numeric>
+#include <sstream>
+
+using namespace std;
+
+int main(int argc, char** argv) {
+ int n = 3;
+ if (argc != 1) {
+ stringstream input(argv[1]);
+ input >> n;
+ }
+
+ int s = 0;
+ for (int x = 1; x <= n; x++) {
+ for (int y = x + 1; y <= n; y++) {
+ s += gcd(x, y);
+ }
+ }
+
+ cout << s << endl;
+}