aboutsummaryrefslogtreecommitdiff
path: root/challenge-089/ash/cpp/ch-1.cpp
blob: b2500a463042331219bba5cdc9acdef235f9bbe3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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;
}