alexjercan/bugnet huggingface dataset:
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int gcd(int &a, int &b, int &c) {
  int g;
  for (int i = 1; i <= a; i++) {
    if (a % i == 0 && b % i == 0 && c % i == 0)
      g = i;
  }
  return g;
}

int main() {
  int k;
  cin >> k;
  int sum = 0;

  for (int a = 1; a <= k; a++) {
    for (int b = 1; b < a; b++) {
      for (int c = 1; c < b; c++) {
        sum += 6 * gcd(a, b, c);
      }
    }
  }
  for (int a = 1; a <= k; a++) {
    sum += a;
  }
  for (int a = 1; a <= k; a++) {
    for (int b = 1; b < a; b++) {
      sum += 6 * gcd(a, a, b);
    }
  }
  cout << sum << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int gcd(int &a, int &b, int &c) {
  int g;
  for (int i = 1; i <= a; i++) {
    if (a % i == 0 && b % i == 0 && c % i == 0)
      g = i;
  }
  return g;
}

int main() {
  int k;
  cin >> k;
  int sum = 0;

  for (int a = 1; a <= k; a++) {
    for (int b = 1; b <= k; b++) {
      for (int c = 1; c <= k; c++) {
        sum += gcd(a, b, c);
      }
    }
  }

  cout << sum << endl;
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {
  int r;
  do {
    r = a % b;
    a = b;
    b = r;
  } while (r != 0);
  return a;
}
int main() {
  int k, i, j, q, sum;
  sum = 0;
  cin >> k;
  for (i = 1; i <= k; i++)
    for (j = 1; j <= k; j++)
      for (q = 1; q <= k; q++)
        sum += gcd(i, gcd(j, q));
  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b, int c) {
  int i, M, g;
  M = max(a, max(b, c));
  for (i = 1; i <= M; i++) {
    if (a % i == 0 && b % i == 0 && c % i == 0)
      g = i;
  }
  return g;
}
int main() {
  int k, i, j, q, sum;
  sum = 0;
  cin >> k;
  for (i = 1; i <= k; i++)
    for (j = 1; j <= k; j++)
      for (q = 1; q <= k; q++)
        sum += gcd(i, j, q);
  cout << sum << endl;
  return 0;
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a, b, c, i, j, k, l, m, n, ans, tmp, hoge, fuga, piyo;
ll x[10010], y[10010];
string s, str;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        ans += gcd(i, gcd(j, k));
      }
    }
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a, b, c, i, j, k, l, m, n, ans, tmp, hoge, fuga, piyo;
ll x[10010], y[10010];
string s, str;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; i++) {
      m = gcd(i, j);
      for (int k = 1; k <= n; i++) {
        ans += gcd(m, k);
      }
    }
  }
  cout << ans;
  return 0;
}
Problem p02713 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int gcd(int x, int y) {
  if (x % y == 0)
    return y;
  else
    return gcd(y, x % y);
}
int gcd2(int x, int y, int z) { return gcd(x, gcd(y, z)); }

int main() {
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++)
        ans += gcd2(i, j, k);
  cout << ans << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int gcd(int x, int y) {
  if (x % y == 0)
    return y;
  else
    return gcd(y, x % y);
}
int gcd2(int x, int y, int z) { return gcd(x, gcd(y, z)); }

int main() {
  int n;
  cin >> n;
  long long ans = 0;
  for (int i; i < n; i++)
    for (int j; j < n; j++)
      for (int k; k < n; k++)
        ans += gcd2(i, j, k);
  cout << ans << endl;
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, i, ans = 0, count = 0, j, in[100], m, low2, low1, k, l;

  cin >> n;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      for (k = 1; k <= n; k++) {
        low1 = min(i, j);
        low2 = min(low1, k);
        for (l = low2; l > 0; l--) {
          if (i % l == 0 && j % l == 0 && k % l == 0) {
            ans = ans + l;
            break;
          }
        }
      }
    }
  }
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
  int k;
  while (cin >> k) {
    int a, b, c;
    int gcd = 0;
    for (a = 1; a <= k; a++) {
      for (b = 1; b <= k; b++) {
        for (c = 1; c <= k; c++) {
          int s = 0;
          for (int i = 1; i <= a; i++) {
            if (a % i == 0 && b % i == 0 && c % i == 0) {
              if (s < i) {
                s = i;
              }
            }
          }
          gcd = gcd + s;
        }
      }
    }
    cout << gcd << endl;
  }
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

int main() {
  int a, s = 0;
  cin >> a;
  for (int i = 1; i <= a; i++) {
    for (int j = i; j <= a; j++) {
      for (int z = j; z <= a; z++) {
        for (int k = max(max(i, j), z); k >= 1; k--) {
          if (i % k == 0 and j % k == 0 and z % k == 0) {
            if (i == j and i == z and j == z) {
              s += k;
              break;
            } else if (i != j and z != j and i != z) {
              s += k * 6;
              break;
            } else {
              s += k * 3;
              break;
            }
          }
        }
      }
    }
  }
  cout << s;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

int main() {
  int a, s = 0;
  cin >> a;
  for (int i = 1; i <= a; i++) {
    for (int j = 1; j <= a; j++) {
      for (int z = 1; z <= a; z++) {
        for (int k = max(max(i, j), z); k >= 1; k--) {
          if (i % k == 0 and j % k == 0 and z % k == 0) {
            s += k;
            break;
          }
        }
      }
    }
  }
  cout << s;
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) {
  if (a == 0)
    return b;
  if (b == 0)
    return a;
  if (a == b)
    return a;
  if (a > b)
    return gcd(a - b, b);
  return gcd(a, b - a);
}
int main() {
  ll k, st, sum = 0;
  cin >> k;
  for (ll i = 1; i <= k; i++) {
    for (ll j = 1; j <= k; j++) {
      for (ll h = 1; h <= k; h++) {
        sum = sum + gcd(gcd(i, j), h);
        ;
      }
    }
  }
  cout << sum;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int gcd(ll a, ll b, ll c) {
  ll st, hcf;
  st = a < b ? (a < c ? a : c) : (b < c ? b : c);

  for (hcf = st; hcf >= 1; hcf--) {
    if (a % hcf == 0 && b % hcf == 0 && c % hcf == 0)
      break;
  }

  return hcf;
}
int main() {
  ll k, st, sum = 0;
  cin >> k;
  for (ll i = 1; i <= k; i++) {
    for (ll j = 1; j <= k; j++) {
      for (ll h = 1; h <= k; h++) {
        sum = sum + gcd(i, j, h);
      }
    }
  }
  cout << sum;
  return 0;
}
Problem p02713 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, n) for (int i = 1; i <= (n); ++i)
#define Sort(x) sort((x).begin(), (x).end())
#define Sort2(x) sort((x).begin(), (x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int, int>;

int gcd(int a, int b) {
  //    return a ? gcd(b, a%b) : a;
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }

  return b;
}

int main() {
  int k;
  cin >> k;
  ll sum = 0;
  rep2(a, k) {
    rep2(b, k) {
      rep2(c, k) { sum += gcd(gcd(a, b), c); }
    }
  }
  cout << sum << endl;
}

/*
Ctrl+@ でコンソールを開け、以下で実行。
g++ code3.cpp
./a.out
*/

Error: -8

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, n) for (int i = 1; i <= (n); ++i)
#define Sort(x) sort((x).begin(), (x).end())
#define Sort2(x) sort((x).begin(), (x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int, int>;

int gcd(int a, int b) { return a ? gcd(b, a % b) : a; }

int main() {
  int k;
  cin >> k;
  ll sum = 0;
  rep2(i, k) {
    rep2(j, k) {
      rep2(l, k) { sum += gcd(gcd(i, j), l); }
    }
  }
}

/*
Ctrl+@ でコンソールを開け、以下で実行。
g++ code3.cpp
./a.out
*/
Problem p02713 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

/* vector<int> A(N);
    vector<pair<int, int> > tasks; ＃ソートした場合、１つ目でソート
　tie(b, a) = p.at(i); #pairを分割
    tasks.emplace_back(b, a)  ＃配列tasksの最後に(b,a)を追加
　xの二乗:  pow(x, 2.0)
    小さい順: sort(v.begin(), v.end());
    大きい順: reverse(v.begin(), v.end());
    int: -2,147,483,648 ～ 2,147,483,647
    ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807
    // int型の2次元配列(3×4要素の)の宣言
    vector<vector<int>> data(3, vector<int>(4));
*/

/* xとyの最大公約数を求める */

int gcd(int x, int y) {
  if (x < y)
    return gcd(y, x);
  else {
    ll r = x % y;
    if (r != 0)
      return gcd(y, r);
    else
      return y;
  }
}

int main() {

  ll A, B, C, count = 0, ans = 0;
  string D, E;
  cin >> A;

  rep(x, A) {
    rep(y, A) {
      rep(z, A) { count += gcd(x + 1, gcd(y + 1, z + 1)); }
    }
  }

  cout << count << endl;
}

Error: -8

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

/* vector<int> A(N);
    vector<pair<int, int> > tasks; ＃ソートした場合、１つ目でソート
　tie(b, a) = p.at(i); #pairを分割
    tasks.emplace_back(b, a)  ＃配列tasksの最後に(b,a)を追加
　xの二乗:  pow(x, 2.0)
    小さい順: sort(v.begin(), v.end());
    大きい順: reverse(v.begin(), v.end());
    int: -2,147,483,648 ～ 2,147,483,647
    ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807
    // int型の2次元配列(3×4要素の)の宣言
    vector<vector<int>> data(3, vector<int>(4));
*/

/* xとyの最大公約数を求める */

int gcd(ll x, ll y) {
  if (x < y)
    return gcd(y, x);
  else {
    ll r = x % y;
    if (r != 0)
      return gcd(y, r);
    else
      return y;
  }
}

int gcd3(ll x, ll y, ll z) {
  int a = gcd(x, y);
  int b = gcd(a, z);
  return b;
}

int main() {

  ll A, B, C, count = 0, ans = 0;
  string D, E;
  cin >> A;

  rep(x, A) {
    rep(y, A) {
      rep(z, A) { count += gcd3(x, y, z); }
    }
  }

  cout << count << endl;
}
Problem p02713 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"

#define rep(i, N) for (int i = 0; i < N; i++)
#define int long long

#define INF 1e10

using namespace std;

int gcd(int p, int q) {
  if (p % q == 0)
    return q;
  return gcd(q, p % q);
}

signed main(void) {
  int K;
  int ans = 0;

  cin >> K;

  rep(a, K) {
    rep(b, K) {
      rep(c, K) { ans += gcd(gcd(a + 1, b + 1), c + 1); }
    }
  }

  cout << ans << endl;

  return 0;
}

Error: -8

Fixed submission:

#include "bits/stdc++.h"

#define rep(i, N) for (int i = 0; i < N; i++)
#define int long long

#define INF 1e10

using namespace std;

int gcd(int p, int q) {
  if (p % q == 0)
    return q;
  return gcd(q, p % q);
}

signed main(void) {
  int K;
  int ans = 0;

  cin >> K;

  rep(a, K) {
    rep(b, K) {
      rep(c, K) { ans += gcd(gcd(a, b), c); }
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int64_t gcd(int a, int b) {
  if (a > b) {
    return gcd(b, a);
  } else if (a == 0) {
    return b;
  } else {
    return gcd(b % a, a);
  }
}

int main() {
  int K;
  cin >> K;
  int64_t ans = 0;
  for (int i = 1; i <= K; ++i) {
    for (int j = i; j <= K; ++j) {
      for (int k = j; k <= K; ++k) {
        if (i == j && j == k) {
          ans += gcd(gcd(i, j), k);
        } else if (i != j && j != k && k != i) {
          ans += 6 * gcd(gcd(i, j), k);
        } else {
          ans += 3 * gcd(gcd(i, j), k);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int gcd(int a, int b) {
  if (a == b) {
    return a;
  } else if (a > b) {
    return gcd(a - b, b);
  } else {
    return gcd(a, a - b);
  }
}

int main() {
  int K;
  cin >> K;
  int64_t ans = 0;
  for (int i = 1; i <= K; ++i) {
    for (int j = i; j <= K; ++j) {
      for (int k = j; k <= K; ++k) {
        if (i == j && j == k) {
          ans += gcd(gcd(i, j), k);
        } else if (i != j && j != k && k != i) {
          ans += 6 * gcd(gcd(i, j), k);
        } else {
          ans += 3 * gcd(gcd(i, j), k);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02713 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int gcd(int x, int y) {

  if ((x % y) == 0) {
    return y;
  } else {
    return gcd(y, x % y);
  }
}

int main() {

  int n, i, j, k, ans, A;
  ans = 0;
  cin >> n;

  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      for (k = 1; k <= n; k++) {
        A = gcd(i, j);
        ans += gcd(A, k);
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Error: -8

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int gcd(int x, int y) {

  if ((x % y) == 0) {
    return y;
  } else if (!((x % y) == 0)) {
    return gcd(y, x % y);
  }
}

int main() {
  int n, i, j, k, ans;
  ans = 0;
  cin >> n;

  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      for (k = 0; k < n; k++) {
        ans += gcd(n, gcd(j, k));
      }
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int K;
  cin >> K;
  int sum = 0;
  for (int i = 0; i < K; i++) {
    for (int j = 0; j < K; j++) {
      for (int k = 0; k < K; k++) {
        sum += __gcd(__gcd(i + 1, j + 1), k + 1);
      }
    }
  }
  cout << sum << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <tuple>
using namespace std;

int main() {
  int K;
  cin >> K;
  int g;
  int sum = 0;
  tuple<int, int, int> gcd;
  for (int i = 0; i < K; i++) {
    for (int j = 0; j < K; j++) {
      for (int k = 0; k < K; k++) {
        gcd = make_tuple(i + 1, j + 1, k + 1);
        g = 1;
        for (int l = 2; l <= min(min(i + 1, j + 1), k + 1) + 1; l++) {
          if (get<0>(gcd) % l == 0 && get<1>(gcd) % l == 0 &&
              get<2>(gcd) % l == 0) {
            g *= l;
            l--;
          }
        }
        sum += g;
      }
    }
  }
  cout << sum << endl;
}
Problem p02713 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define ll long long int

using namespace std;

ll gcd2(int a, int b) {
  if (a % b == 0)
    return b;
  return gcd2(b, a % b);
}

ll gcd3(int a, int b, int c) { return gcd2(gcd2(a, b), c); }

int main(void) {
  ll K, sum = 0;
  cin >> K;
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= K; j++) {
      for (int k = 1; k <= K; k++) {
        sum += gcd3(i, j, k);
      }
    }
  }
  cout << sum << endl;
  return 0;
}


Error: -8

Fixed submission:

#include <iostream>
#define ll long long int

using namespace std;

ll gcd2(int a, int b) {
  if (a % b == 0)
    return b;
  if (a < b) {
    int tmp = a;
    a = b;
    b = tmp;
  }
  return gcd2(b, a % b);
}

ll gcd3(int a, int b, int c) { return gcd2(gcd2(a, b), c); }

int main(void) {
  ll K, sum = 0;
  cin >> K;
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= K; j++) {
      for (int k = 1; k <= K; k++) {
        sum += gcd3(i, j, k);
      }
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p02713 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
typedef long long ll;
int gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
int main() {
  ll k;
  cin >> k;
  ll s = 0;
  rep(i, k) {
    rep(j, k) {
      rep(m, k) { s += gcd(i, gcd(j, m)); }
    }
  }
  cout << s;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

int main() {
  long long K;
  cin >> K;
  long long cnt = 0;
  vector<vector<long long>> gcd(K, vector<long long>(K));
  for (int a = 1; a <= K; a++) {
    for (int b = 1; b <= K; b++) {
      long long res = GCD(a, b);
      gcd.at(a).at(b) = res;
    }
  }
  for (int c = 1; c <= K; c++) {
    for (int d = 1; d <= K; d++) {
      cnt += GCD(gcd.at(c).at(d), c);
    }
  }

  cout << cnt << endl;
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
  int k;
  cin >> k;
  int ans = 0;
  for (int a = 1; a <= k; a++)
    for (int b = 1; b <= k; b++)
      for (int c = 1; c <= k; c++) {
        int mx = 0;
        mx = min(a, b);
        mx = min(mx, c);
        for (int i = mx; i >= 1; i--) {
          if (a % i == 0 && b % i == 0 & c % i == 0) {
            ans += i;
            break;
          }
        }
      }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
  int k;
  cin >> k;
  int ans = 0;
  for (int a = 1; a <= k; a++)
    for (int b = 1; b <= k; b++)
      for (int c = 1; c <= k; c++) {
        int mx = 0;
        mx = max(a, b);
        mx = max(mx, c);
        for (int i = mx; i >= 1; i--) {
          if (a % i == 0 && b % i == 0 & c % i == 0) {
            ans += i;
            break;
          }
        }
      }
  cout << ans << endl;
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 1000000009
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
#define REP(i, a, b) for (int i = a; i <= b; i++)

int main(int argc, char const *argv[]) {
  map<pair<int, pair<int, int>>, int> mp;
  int n;
  cin >> n;
  int gcd = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {

        gcd += __gcd(i, __gcd(j, k));
      }
    }
  }
  cout << gcd << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 1000000009
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
#define REP(i, a, b) for (int i = a; i <= b; i++)

int main(int argc, char const *argv[]) {
  map<pair<int, pair<int, int>>, int> mp;
  int n;
  cin >> n;
  int gcd = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        if (!mp[{i, {j, k}}]) {
          mp[{i, {j, k}}] = 1;
          // mp[{j,{i,k}}]=1;
          // mp[{k,{i,j}}]=1;
          // cout<<i<<' '<<j<<' '<<k<<endl;
          gcd += __gcd(i, __gcd(j, k));
        }
      }
    }
  }
  cout << gcd << endl;
  return 0;
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
  while (x != 0 && y != 0) {
    if (x >= y)
      x = x % y;
    else if (y > x)
      y = y % x;
  }
  if (x >= y)
    return x;
  else
    return y;
}
int main() {
  long long k;
  cin >> k;
  long long a, b, c;
  long long sum;
  if (k >= 1 && k <= 200) {
    sum = 0;
    for (a = 1; a <= k; a++) {
      for (b = 1; b <= k; b++) {
        for (c = 1; c <= k; c++) {
          sum += gcd(gcd(a, b), c);
        }
      }
    }
    cout << sum << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long k;
  cin >> k;
  long long a, b, c;
  long long sum;
  long long gcd, i;
  if (k >= 1 && k <= 200) {
    sum = 0;
    for (a = 1; a <= k; a++) {
      for (b = 1; b <= k; b++) {
        for (c = 1; c <= k; c++) {
          gcd = 1;
          i = 1;
          while (i <= a && i <= b && i <= c) {
            if (a % i == 0 && b % i == 0 && c % i == 0) {
              gcd = i;
              i++;
            }
          }
          sum += gcd;
        }
      }
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

unsigned long long sum1(unsigned long long a) { return (a * (a + 1) / 2); }

// Sample
int main() {
  unsigned long long K;
  unsigned long long buf1 = 0; // aaa
  unsigned long long buf2 = 0; // aab & abc
  cin >> K;

  buf1 = sum1(K);

  for (int i = 1; i < K; i++) {
    for (int j = i + 1; j <= K; j++) {
      unsigned long long bufbuf = __gcd(i, j);
      buf2 += bufbuf;
      for (unsigned long long ii = j + 1; ii <= K; ii++) {
        buf2 += __gcd(bufbuf, ii);
      }
    }
  }

  cout << (buf1 + buf2 * 6) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

unsigned long long sum1(unsigned long long a) { return (a * (a + 1) / 2); }

// Sample
int main() {
  unsigned long long K;
  unsigned long long buf1 = 0; // aaa
  unsigned long long buf2 = 0; // aab
  unsigned long long buf3 = 0; // abc
  cin >> K;

  buf1 = sum1(K);

  for (int i = 1; i < K; i++) {
    for (int j = i + 1; j <= K; j++) {
      buf2 += __gcd(i, j);
    }
  }

  for (int i = 1; i <= K - 2; i++) {
    for (int j = i + 1; j <= K - 1; j++) {
      for (int ii = j + 1; ii <= K; ii++) {
        buf3 += __gcd(__gcd(i, j), ii);
      }
    }
  }

  cout << (buf1 + buf2 * 6 + buf3 * 6) << endl;
  return 0;
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long int

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  ll k;
  cin >> k;
  ll sum = 0;
  for (ll i = 1; i <= k; i++) {
    for (ll j = 1; j <= k; j++) {
      for (ll p = 1; p <= k; p++) {
        sum += gcd(i, gcd(j, p));
      }
    }
  }

  cout << sum;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  long long K;
  cin >> K;
  long long ans = 0;
  for (long long i = 1; i < K + 1; i++) {
    for (long long j = 1; j < K + 1; i++) {
      for (long long p = 1; p < K + 1; i++) {
        ans += gcd(i, gcd(j, p));
      }
    }
  }

  cout << ans;
}