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

#include <bits/stdc++.h>
using namespace std;
int gcd(int, int);
vector<int> waru(vector<int>);

int main() {
  int K;
  int sum = 0;
  cin >> K;
  for (int a = 1; a <= K; a++) {
    for (int b = 1; b <= K; b++) {
      for (int c = 1; c <= K; c++) {
        sum += gcd(gcd(a, b), c);
      }
    }
  }
  cout << sum << endl;
}

int gcd(int a, int b) {
  vector<int> vec = {a, b};
  if (a < b)
    swap(vec.at(0), vec.at(1));
  while (vec.at(1) != 0) {
    vec = waru(vec);
  }
  return vec.at(0);
}

vector<int> waru(vector<int> i) {
  vector<int> vec(2);
  int syou;
  vec.at(0) = i.at(1);
  syou = i.at(0) / i.at(1);
  vec.at(1) = i.at(0) - syou * i.at(1);
  return vec;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int gcd(int, int);
vector<int> waru(vector<int>);

int main() {
  int K;
  int sum = 0;
  cin >> K;
  for (int a = 1; a <= K; a++) {
    for (int b = 1; b <= K; b++) {
      for (int c = 1; c <= K; c++) {
        sum += gcd(gcd(a, b), c);
      }
    }
  }
  cout << sum << endl;
}

int gcd(int a, int b) {
  vector<int> vec = {a, b};
  while (vec.at(1) != 0) {
    vec = waru(vec);
  }
  return vec.at(0);
}

vector<int> waru(vector<int> i) {
  vector<int> vec(2);
  int syou;
  vec.at(0) = i.at(1);
  syou = i.at(0) / i.at(1);
  vec.at(1) = i.at(0) - syou * i.at(1);
  return vec;
}
Problem p02713 (C++) — buggy submission, verdict: Runtime Error

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

int gcd(int p, int q) {
  if (!(p % q))
    return q;
  else
    return gcd(q, p % q);
}

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(gcd(a, b), c);
      }
    }
  }
  cout << sum << endl;
}


Error: -8

Fixed submission:

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

int gcd(int p, int q) {
  if (!(p % q))
    return q;
  else
    return gcd(q, p % q);
}

int main() {
  int k;
  cin >> k;
  int sum = 0;
  for (int a = 0; a < k; a++) {
    for (int b = 0; b < k; b++) {
      for (int c = 0; c < k; c++) {
        sum += gcd(gcd(a, b), c);
      }
    }
  }
  cout << sum << endl;
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
int gcd(int x, int y);
int main(void) {
  int k;
  int sum = 0;
  cin >> k;
  for (int i = 1; i < k + 1; i++) {
    for (int j = 1; j < k + 1; j++) {
      for (int f = 1; f < k + 1; f++) {
        sum = sum + gcd(i, gcd(j, f));
      }
    }
  }
  cout << sum;
}
int gcd(int x, int y) {
  int z = y;
  while (x % y != 0) {
    z = x % y;
    x = y;
    y = z;
  }
  return z;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int gcd(int a, int b, int c);
int main(void) {
  int k;
  int sum = 0;
  cin >> k;
  for (int i = 1; i < k + 1; i++) {
    for (int j = 1; j < k + 1; j++) {
      for (int f = 1; f < k + 1; f++) {
        sum = sum + gcd(i, j, f);
      }
    }
  }
  cout << sum;
}

int gcd(int a, int b, int c) {
  int min, max_div;
  min = a;
  if (min < b)
    min = b;
  if (min > c)
    min = c; // 找到3个数中最小的那个数
  for (max_div = min; max_div > 1;
       max_div--) // 以1为下限知，3个数中最小数为上限，递减，直到能全部整除
  {
    if (a % max_div == 0 && b % max_div == 0 && c % max_div == 0)
      break;
  }
  return max_div;
}
Problem p02713 (C++) — buggy submission, verdict: Runtime Error

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

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

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

Error: -8

Fixed submission:

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

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

int main() {
  int k;
  cin >> k;
  int sum = 0;
  rep(h, k) {
    rep(i, k) {
      rep(j, k) { sum += gcd(h, gcd(i, j)); }
    }
  }
  cout << sum << endl;
}
Problem p02713 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int gcd(int p, int q) {
  while (q != 0) {
    int r = p % q;
    p = q;
    q = r;
  }
  return p;
}
int main() {
  int K;
  cin >> K;
  long long S = 0;
  for (int a = 1; a <= K; a++) {
    for (int b = 1; b <= K; b++) {
      for (int c = 1; c <= K; c++) {
        S = S + gcd(a, gcd(b, c));
      }
    }
  }
  cout << S << endl;
}

Error: -8

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int K;
  cin >> K;
  int S = 0;
  for (int a = 0; a < K; a++) {
    for (int b = 0; b < K; b++) {
      for (int c = 0; c < K; c++) {
        for (int i = 0; i < K; i++) {
          int n = 1;
          if (a % i == 0 and b % i == 0 and c % i == 0) {
            n = i;
          }
          S = S + n;
        }
      }
    }
  }
  return S;
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// int gcd(int x,int y,int z){
//     for(int i=min(min(x,y),z);i>0;i=i-1){
//         int n=x%i;
//         int m=y%i;
//         int l=z%i;

//         if((n==0&&m==0)&&l==0){
//             return i;
//         }
//     }
//     return 1;
// }

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(gcd(a, b), c);
      }
    }
  }

  cout << sum << endl;
}

Error: TLE

Fixed submission:

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

int gcd(int x, int y, int z) {
  for (int i = min(min(x, y), z); i > 0; i = i - 1) {
    int n = x % i;
    int m = y % i;
    int l = z % i;

    if ((n == 0 && m == 0) && l == 0) {
      return i;
    }
  }
  return 1;
}

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 <bits/stdc++.h>
using namespace std;

int main() {
  int k;
  cin >> k;
  int x = 0, s = 0;
  for (int l = 1; l <= k; l++) {
    for (int m = 1; m <= k; m++) {
      for (int n = 1; n <= k; n++) {
        for (int i = 1; i <= min(l, min(m, n)); i++) {
          if (l % i == 0 && m % i == 0 && n % i == 0) {
            x = i;
          }
        }
        s += x;
        x = 0;
      }
    }
  }
  cout << s << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int k;
  cin >> k;
  int x = 0, s = 0;
  for (int l = 1; l <= k; l++) {
    for (int m = 1; m <= k; m++) {
      for (int n = 1; n <= k; n++) {
        for (int i = 1; i <= max(l, max(m, n)); i++) {
          if (l % i == 0 && m % i == 0 && n % i == 0) {
            x = i;
          }
        }
        s += x;
        x = 0;
      }
    }
  }
  cout << s << endl;
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
void fast() {
  cin.tie(0);
  cin.sync_with_stdio(0);
}
long long gcd(long long a, long long b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
long long gcd_t(long long a, long long b, long long c) {
  return gcd(a, gcd(b, c));
}
int main() {
  fast();
  int n;
  long long s = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {

        s += gcd_t(i, j, k);
      }
    }
  }
  cout << s;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
void fast() {
  cin.tie(0);
  cin.sync_with_stdio(0);
}
int main() {
  fast();
  int n;
  long long s = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        long long d = 1, ii = min(min(i, j), k);
        while (true) {
          if (i % ii == 0 && j % ii == 0 && k % ii == 0) {
            d = ii;
            break;
          }
          ii--;
        }
        s += d;
      }
    }
  }
  cout << s;
  return 0;
}
Problem p02713 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll, ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll, ll>>>
#define PL pair<ll, ll>
#define ALL(v) (v).begin(), (v).end()
ll K;
ll ans = 0;
// ユークリッドの互除法, 再帰
ll gcd(ll p, ll r) {
  ll tmp;
  if (p < r) {
    tmp = p;
    p = r;
    r = tmp;
  }
  if (p % r == 0) {
    return r;
  }
  return gcd(r, p % r);
}

int main() {
  cin >> K;
  rep(i, 1, K + 1) {
    rep(j, 1, K + 1) {
      rep(k, 1, K + 1) { ans += gcd(gcd(i, j), k); }
    }
  }
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll, ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll, ll>>>
#define PL pair<ll, ll>
#define ALL(v) (v).begin(), (v).end()

ll K;
ll ans = 0;
// ユークリッドの互除法, 再帰
ll gcd(ll p, ll r) {
  ll tmp;
  if (p < r) {
    tmp = p;
    p = r;
    r = tmp;
  }
  if (p % r == 0) {
    return r;
  }
  gcd(r, p % r);
}

int main() {
  cin >> K;
  rep(i, 1, K + 1) {
    rep(j, 1, K + 1) {
      rep(k, 1, K + 1) { ans += gcd(gcd(i, j), k); }
    }
  }
  cout << ans;
  return 0;
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int k;
long long sum;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  cin >> k;
  for (int a = 1; a <= k; a++) {
    for (int b = 1; b <= k; b++) {
      for (int c = 1; c <= k; c++) {
        int d = gcd(a, b);
        d = gcd(d, c);
        sum += d;
      }
    }
  }
  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int K;
long long sum;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  cin >> K;
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= K; i++) {
      for (int k = 1; k <= K; k++) {
        int mid = gcd(i, j);
        mid = gcd(mid, k);
        sum += mid;
      }
    }
  }
  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++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int e(int x, int y) {
  if (x < y)
    swap(x, y);
  int r;
  while (true) {
    r = x % y;
    if (r == 0)
      return y;
    x = y;
    y = r;
  }
  return 0;
}
int main() {
  int k;
  cin >> k;
  int sum = 0;
  rep(i, k) {
    rep(j, k) {
      rep(l, k) {
        int a = e(i, j);
        int b = e(a, l);
        sum += b;
      }
    }
  }
  cout << sum << endl;
}


Error: -8

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int e(int x, int y) {
  if (x < y)
    swap(x, y);
  int r;
  while (true) {
    r = x % y;
    if (r == 0)
      return y;
    x = y;
    y = r;
  }
  return 0;
}
int main() {
  int k;
  cin >> k;
  int sum = 0;
  rep(i, k) {
    rep(j, k) {
      rep(l, k) {
        int a = e(i, j);
        int b = e(a, l);
        sum += b;
      }
    }
  }
  cout << sum << endl;
}
Problem p02713 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int k;
  cin >> k;

  int64_t s = 0;

  for (int a = 1; a <= k; a++) {
    for (int b = 1; b <= k; b++) {
      for (int c = 1; c <= k; c++) {

        int d = a;
        int e = b;
        int f = c;
        int p;
        while (d % e != 0) {
          p = d;
          d = e;
          e = p % e;
        }

        while (f % e != 0) {
          p = f;
          f = e;
          e = p % e;
        }

        s += e;
      }
    }
  }

  cout << s << endl;
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int k;
  cin >> k;

  int64_t s = 0;

  for (int a = 1; a <= k; a++) {
    for (int b = 1; b <= k; b++) {
      for (int c = 1; c <= k; c++) {

        int d = a;
        int e = b;
        int f = c;
        while (d % e != 0) {
          d = e;
          e = d % e;
        }

        while (f % e != 0) {
          f = e;
          e = f % e;
        }

        s += e;
      }
    }
  }

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

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

// 整数i,j,kに対しそれらの最大公約数を返す
int gcd(int &i, int &j, int &k) {

  int max_divisor = 1;
  for (int l = 2; l < min(i, min(j, k)) + 1; l++) {
    if ((i % l == 0) && (j % l == 0) && (k % l == 0))
      max_divisor = l;
  }
  return max_divisor;
}

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

Error: TLE

Fixed submission:

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

// 整数i,j,kに対しそれらの最大公約数を返す
int gcd(int &i, int &j, int &k) {
  int max_divisor = 1;
  for (int l = 2; l < i + 1; l++) {
    if ((i % l == 0) && (j % l == 0) && (k % l == 0))
      max_divisor = l;
  }
  return max_divisor;
}

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

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

int gcd(int a, int b) {
  if (a < b) {
    swap(a, b);
  }
  if (a % b == 0) {
    return b;
  }

  return gcd(a % b, b);
}

int main() {
  int K;
  cin >> K;

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

  cout << ans << endl;
}

Error: -8

Fixed submission:

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

int gcd(int a, int b) {
  if (a < b) {
    swap(a, b);
  }
  if (a % b == 0) {
    return b;
  }

  return gcd(a % b, b);
}

int main() {
  int K;
  cin >> K;

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

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

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <map>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int euclid(int i, int j) {
  if (i % j == 0)
    return j;
  return euclid(j, i % j);
}

int main() {
  int K;
  cin >> K;
  long long sum = 0;

  for (int a = 1; a <= K; a++) {
    for (int b = 1; b <= K; b++) {
      for (int c = 1; c <= K; c++) {
        int tmp = euclid(max(a, b), min(a, b));
        sum += euclid(max(tmp, c), min(tmp, c));
      }
    }
  }

  cout << sum << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <map>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int euclid(int i, int j) {
  if (i % j == 0)
    return j;
  euclid(j, i % j);
}

int main() {
  int K;
  cin >> K;
  long long sum = 0;

  for (int a = 1; a <= K; a++) {
    for (int b = 1; b <= K; b++) {
      for (int c = 1; c <= K; c++) {
        int tmp = euclid(max(a, b), min(a, b));
        sum += euclid(max(tmp, c), min(tmp, c));
      }
    }
  }

  cout << sum << endl;

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

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

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

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

Error: TLE

Fixed submission:

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

int main() {
  int k;
  cin >> k;
  ll sum = 0;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; i < j <= k; j++) {
      for (int l = 1; i < j < l <= k; l++) {
        int b = 1;
        for (int a = 1; a < i < k; a++) {
          if (i % a == 0 && j % a == 0 && l % a == 0 && b < a) {
            b = a;
          }
        }
        sum += b;
      }
    }
  }
  cout << sum * 3 << endl;
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// Made with <3 by MinumCoklatPanas
typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int k;
  cin >> k;
  int ans = 0;
  for (int i = 1; i <= k; i++)
    for (int j = 1; j <= k; j++)
      for (int l = 1; l <= k; l++) {
        ans += __gcd(__gcd(i, j), l);
      }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, j, l, k, s = 0, x;
  cin >> n;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      for (k = 1; k <= n; k++) {
        x = i;
        if (x > j) {
          x = j;
        }
        if (x > k) {
          x = k;
        }
        for (l = x; l >= 1; l--) {
          if (i % l == 0 && j % l == 0 && k % l == 0) {
            break;
          }
        }
        s = s + l;
      }
    }
  }

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

#include <bits/stdc++.h>
#include <math.h>

#define PI 3.14159265358979323846264338327950L
#define ll long long

using namespace std;

int solve(int i, int j) {
  int result = 1;
  for (int k = 2; k <= min(i, j); k++) {
    if (i % k == 0 && j % k == 0) {
      result = k;
    }
  }
  return result;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int k;
  cin >> k;
  ll sum = 0;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      for (int m = 1; m <= k; m++) {
        sum += solve(solve(i, j), m);
      }
    }
  }
  cout << sum << "\\n";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>

#define PI 3.14159265358979323846264338327950L
#define ll long long

using namespace std;

int solve(int i, int j) {
  int result = 1;
  for (int k = 2; k <= min(i, j); k++) {
    if (i % k == 0 && j % k == 0) {
      result = k;
    }
  }
  return result;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int k;
  cin >> k;
  ll sum = 0;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      for (int k = 1; k <= k; k++) {
        sum += solve(solve(i, j), k);
      }
    }
  }
  cout << sum << "\\n";
}
Problem p02713 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long N;
  cin >> N;
  long i;
  long j;
  long k;
  long a;
  long b;
  long c;
  long r;
  long sum = 0;
  long tmp;
  for (i = 1; i < N + 1; i++) {
    for (j = 1; j < N + 1; j++) {

      for (k = 1; k < N + 1; k++) {
        a = i;
        b = j;
        if (a < b) {
          tmp = a;
          a = b;
          b = tmp;
        }
        r = a % b;
        while (r != 0) {
          a = b;
          b = r;
          r = a % b;
        }
        // cout << "b:" << b << endl;
        c = k;
        if (b < c) {
          tmp = b;
          b = c;
          c = tmp;
        }
        r = b % c;
        while (r != 0) {
          b = c;
          c = r;
          r = b % c;
        }
        // cout << "c:" << c << endl;
        sum = sum + c;
        // cout << "i:" << i << " j" << j << " k:" << k << " c:" << c << endl;
        // cout << "i:" << i << " j" << j << " k:" << k << " sum:" << sum <<
        // endl;
      }
    }
  }
  cout << sum << endl;
}


Error: -8

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  int i;
  int j;
  int k;
  int a;
  int b;
  int c;
  long r;
  long r2;
  long sum;
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      a = i;
      b = j;
      r = a % b;
      while (r != 0) {
        a = b;
        b = r;
        r = a % b;
      }

      for (k = 0; k < N; k++) {
        c = k;
        r2 = r % k;
        while (r != 0) {
          r = k;
          k = r2;
          r2 = r % k;
        }
        sum += r2;
      }
    }
  }
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>

// 最大公約数を求める関数
int GCD(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return (GCD(b, a % b));
  }
}

int main() {

  int a, b, c;
  int fgcd;
  int total;
  total = 0;
  int K;
  scanf("%d", &K);

  for (a = 1; a < K + 1; a++) {     // a
    for (b = 1; b < K + 1; b++) {   // b
      for (c = 1; c < K + 1; c++) { // c
        fgcd = GCD(a, b);
        total += GCD(fgcd, c);
      }
    }
  }
  printf("%d\\n", total);
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>

// 最大公約数を求める関数
int GCD(int a, int b, int c) {
  int i, gcd;
  gcd = 200;
  int max;
  max = a;
  if (max < b)
    max = b;
  if (max < c)
    max = c;
  for (i = max; i > 0; i--) {
    if (a % i == 0 && b % i == 0 && c % i == 0) {
      gcd = i;
      break;
    }
  }
  return gcd;
}

int main() {

  int a, b, c;
  int total;
  total = 0;
  int K;
  scanf("%d", &K);

  for (a = 1; a < K + 1; a++) {     // a
    for (b = 1; b < K + 1; b++) {   // b
      for (c = 1; c < K + 1; c++) { // c
        total += GCD(a, b, c);
      }
    }
  }
  printf("%d\\n", total);
  return 0;
}