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

#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, b, sizeof(a))
#define pii pair<int, int>
#define int long long
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9 + 7;
int n, m, k, ok;

signed main() {
  cin >> n;
  ok = 0;
  while (n) {
    if (n % 10 == 7) {
      ok = 1;
    }
    n /= 10;
  }
  if (ok)
    puts("Yes");
  else
    puts("No");
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, b, sizeof(a))
#define pii pair<int, int>
#define int long long
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9 + 7;
int n, m, k, ok;

signed main() {
#ifdef ONLINE_JUDGE
#else
  freopen("data.in", "r", stdin);
#endif
  cin >> n;
  ok = 0;
  while (n) {
    if (n % 10 == 7) {
      ok = 1;
    }
  }
  if (ok)
    puts("Yes");
  else
    puts("No");
  return 0;
}
Problem p02711 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string N;
  cin >> N;

  if (N[0] == '7' || N[1] == '7' || N[2] == '7') {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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


Fixed submission:

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

int main() {
  string N;
  for (int i = 0; i < 3; i++) {
    if (N.at(i) == 7) {
      cout << "Yes" << endl;
      break;
    } else {
      cout << "No" << endl;
    }
  }
}
Problem p02711 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define IOFAST                                                                 \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
#define ll long long
#define for(i, n) for (int i = 0; i < n; i++)

#define vec vector<int>

#define pb push_back
#define f first
#define s second

int main() {
  int n;
  cin >> n;
  int flag = 0;
  while (n != 0) {
    int d = n % 10;
    if (d == 7) {
      flag = 1;
      break;
    }
    n /= 10;
    if (n == 0) {
      break;
    }
  }

  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Error: 1

Fixed submission:

#include <bits/stdc++.h>
#define IOFAST                                                                 \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
#define ll long long
#define for(i, n) for (int i = 0; i < n; i++)

#define vec vector<int>

#define pb push_back
#define f first
#define s second

int main() {
  int n;
  cin >> n;
  int flag = 0;
  while (n != 0) {
    int d = n % 10;
    if (d == 7) {
      flag = 1;
      break;
    }
    n /= 10;
  }

  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 1;
}
Problem p02711 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;

  while (n > 0) {
    if (n % 10 == 7) {
      cout << "Yes";
      break;
    }
    n = n / 10;
  }
  if (n == 0) {
    cout << "No";
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;

  while (n > 0) {
    if (n % 10 == 7) {
      cout << "Yes";
      break;
      n = n / 10;
    }
  }
  if (n == 0) {
    cout << "No";
  }
}
Problem p02711 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define in freopen("in.txt","r",stdin)
// #define out freopen("out.txt","w",stdout)
#define N 1e9 + 10;
ll n, m, i, j, k, t, l, r;
ll a, b, c, d;
char A, C, X, Y, Z;
ll ans, MAX, MIN, sum;
ll ax[2000500];
char cx[500];
ll dx[12];
ll bx[500];

int main() {
  t = 1;
  // scanf("%lld",&t);
  while (t--) {
    cin >> n;
    int flag = 0;
    if (n % 10 == 7)
      flag = 1;
    n = n / 10;
    if (n % 10 == 7)
      flag = 1;
    n = n / 10;
    if (n % 10 == 7)
      flag = 1;
    if (flag)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define in freopen("in.txt","r",stdin)
// #define out freopen("out.txt","w",stdout)
#define N 1e9 + 10;
ll n, m, i, j, k, t, l, r;
ll a, b, c, d;
char A, C, X, Y, Z;
ll ans, MAX, MIN, sum;
ll ax[2000500];
char cx[500];
ll dx[12];
ll bx[500];

int main() {
  t = 1;
  // scanf("%lld",&t);
  while (t--) {
    cin >> n;
    int flag = 0;
    while (n / 10) {
      if (n % 10 == 7) {
        flag = 1;
        break;
      }
    }
    if (flag)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}
Problem p02711 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string s;
  cin >> s;
  if (s.at(0) == '7' || s.at(1) == '7' || s.at(2) == '7')
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Error: 0

Fixed submission:

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

int main() {
  string s;
  cin >> s;
  if (s.at(1) == '7' || s.at(2) == '7' || s.at(3) == '7')
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02711 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string s;
  cin >> s;
  if (s.find("7") != string::npos)
    cout << "Yes";
  else
    cout << "No";

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a;
  cin >> a;
  int counter = 0;
  while (a > 0) {
    if (a % 10 == 7)
      counter++;
    a = (a - a % 10);
  }
  if (counter == 0) {
    cout << "No";
  } else
    cout << "Yes";

  return 0;
}
Problem p02711 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  for (int i = 0; i < 3; i++)
    if (a[i] == '7') {
      cout << "Yes" << endl;
      return 0;
    }
  cout << "No" << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int a[100001];
  for (int i = 1; i <= 100000001; i++) {
    cin >> a[i];
    if (a[i] == 7) {
      cout << "YES" << endl;
    } else if (a[i] != 7) {
      cout << "NO" << endl;
    }
  }
  return 0;
}
Problem p02711 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  int number;
  cin >> number;
  int numb = number;
  int p;
  while (numb != 0) {
    p = numb % 10;
    numb = numb / 10;
    if (p == 7) {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
}

Error: WA

Fixed submission:

#include <iostream>
int main() {
  int x;
  std::cin >> x;
  while (x != 0) {
    if (x % 10 == 7) {
      std::cout << "YES";
      return 0;
    }

    x /= 10;
  }
  std::cout << "NO";
  return 1;
}
Problem p02711 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n;
  cin >> n;
  int k;
  bool hasSev = false;

  do {
    k = n % 10;
    if (k == 7) {
      hasSev = true;
      break;
    }
    n = n / 10;
  } while (n > 0);

  if (hasSev) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  bool hasSev;

  int n;
  int r;
  cin >> n;

  while (n >= 0) {
    r = n % 10;
    if (r == 7) {
      hasSev = true;
      break;
    } else {
      n /= 10;
    }
  }

  if (hasSev) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}
Problem p02712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  long long int n;
  scanf("%lld", &n);

  long long int sum = 0;

  for (int i = 1; i <= n; i++) {
    if (i % 15 && i % 3 && i % 5) {
      sum += i;
    }
  }

  printf("%lld\\n", sum);

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  long long int input, sum = 0;
  scanf("%d", &input);
  for (int i = 0; i < input; i++) {
    if (i % 3 != 0 && i % 5 != 0) {
      sum = sum + i;
    }
  }
  printf("%lld", sum);

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

#include <stdio.h>
#include <stdlib.h>

int main() {
  unsigned long N, i, M, sum;

  scanf("%ld", &N);

  sum = N * (double)(N + 1) / 2.0;
  M = 0;
  for (i = 0; i <= N; i += 3) {
    M += i;
  }
  for (i = 0; i <= N; i += 5) {
    if (i % 3 == 0) {
      continue;
    }
    M += i;
  }

  printf("%ld", sum - M);

  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>
#include <stdlib.h>

int main() {
  unsigned long N, i, M, sum;

  scanf("%d", &N);

  sum = N * (double)(N + 1) / 2.0;
  M = 0;
  for (i = 0; i <= N; i += 3) {
    M += i;
  }
  for (i = 0; i <= N; i += 5) {
    if (i % 3 == 0) {
      continue;
    }
    M += i;
  }

  printf("%ld\\n", sum - M);

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

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stdio.h>
#include <unordered_set>
#include <utility>
#include <vector>
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define pf printf
#define ff first
#define ss second
#define sef second.first
#define ses second.second
#define ms(a, b) memset(a, b, sizeof(a))
#define loop(i, a) for (int i = 1; i <= a; i++)
#define pii pair<int, int>
#define sl(a) scanf("%I64d", &a)
#define sll(a, b) scanf("%I64d %I64d", &a, &b)
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d %d", &a, &b)
using namespace std;
typedef long long ll;
const int maxx = 8e4 + 10;
// typedef pair < int , pii > node ;
// node tree[4*maxx],lazy[4*maxx];
int tree[4 * maxx], lazy[4 * maxx];
int main() {
  long long sum = 0, n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (i % 3 != 0 && i % 5 != 0) {
      sum += i;
    }
  }
  cout << sum << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stdio.h>
#include <unordered_set>
#include <utility>
#include <vector>
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define pf printf
#define ff first
#define ss second
#define sef second.first
#define ses second.second
#define ms(a, b) memset(a, b, sizeof(a))
#define loop(i, a) for (int i = 1; i <= a; i++)
#define pii pair<int, int>
#define sl(a) scanf("%I64d", &a)
#define sll(a, b) scanf("%I64d %I64d", &a, &b)
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d %d", &a, &b)
using namespace std;
typedef long long ll;
const int maxx = 8e4 + 10;
// typedef pair < int , pii > node ;
// node tree[4*maxx],lazy[4*maxx];
int tree[4 * maxx], lazy[4 * maxx];
int main() {
  ll n, sum = 0, i = 1, k = 0;
  sl(n);
  loop(i, n) {
    if (i % 3 != 0 && i % 5 != 0) {
      sum += i;
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p02712 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  long long int a, b = 0;
  cin >> a;
  rep(i, a + 1) {
    if (i % 3 != 0 && i % 5 != 0)
      b += i;
  }
  cout << b;
}


Error: -8

Fixed submission:

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

int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int main() {
  long int a, b = 0;
  cin >> a;
  rep(i, a++) {
    rep(o, a++) { rep(j, a++) b += gcd(i, gcd(o, j)); }
  }
  cout << b;
}
Problem p02712 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#define ll long long
using namespace std;

int main() {
  ll k = 0;
  ll ans = 0;
  scanf("%lld", &k);

  for (ll i = 1; i <= k; i++) {
    if (i % 5 != 0 && i % 3 != 0) {
      ans = ans + i;
    }
  }
  printf("%lld", ans);
  return 0;
}

Error: WA

Fixed submission:

#include <cstdio>
#define ll long long
using namespace std;

int main() {
  ll k = 0;
  ll ans = 0;
  scanf("%d", &k);
  for (ll i = 1; i < k; i++) {
    if (k % 5 == 0 || k % 3 == 0) {
      continue;
    } else {
      ans += i;
    }
  }
  return ans;
}
Problem p02712 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!(i % 3 == 0 || i % 5 == 0)) {
      ans += ll(i);
    }
  }
  cout << ans << endl;
}

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


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < 3; i++) {
    if (s.at(i) == '7') {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}
Problem p02712 (C++) — buggy submission, verdict: Runtime Error

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }

int main() {
  ll N;
  cin >> N;
  vector<ll> ans(N + 1);

  ans[0] = 0;
  for (ll i = 1; i <= N; ++i) {
    if (i % 3 == 0 && i % 5 == 0) {
      ans[i] = 0;
    } else if (i % 3 == 0) {
      ans[i] = 0;
    } else if (i % 5 == 0) {
      ans[i] = 0;
    } else {
      ans[i] = i;
    }
  }

  ll tmp = 0;
  for (int i = 0; i <= N; ++i) {
    tmp += ans[i];
  }
  cout << tmp << endl;
}

Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }

int main() {
  ll N;
  cin >> N;
  vector<ll> ans(N);

  ans[0] = 0;
  for (ll i = 1; i <= N; ++i) {
    if (i % 3 == 0 && i % 5 == 0) {
      ans[i] = 0;
    } else if (i % 3 == 0) {
      ans[i] = 0;
    } else if (i % 5 == 0) {
      ans[i] = 0;
    } else {
      ans[i] = i;
    }
  }

  ll tmp = 0;
  REP(i, N + 1) { tmp += ans[i]; }
  cout << tmp << endl;
}
Problem p02712 (C++) — buggy submission, verdict: Time Limit Exceeded


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

int main() {

  int N;
  cin >> N;
  int64_t sum = 0;

  for (int i = 0; i < N; i++) {
    if ((i + 1) % 3 != 0 && (i + 1) % 5 != 0) {
      sum += (i + 1);
    }
  }
  cout << sum << endl;
}

Error: TLE

Fixed submission:

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

int main() {

  int N;
  cin >> N;

  int A = N / 3;
  int B = N / 5;
  int C = N / 15;
  int sumA = 0;
  int sumB = 0;
  int sumC = 0;
  int sum = 0;

  int i = 0;
  while (i <= A) {
    sumA += 3 * i;
    i++;
  }

  int j = 0;
  while (j <= B) {
    sumB += 5 * j;
    j++;
  }

  int k = 0;
  while (k <= C) {
    sumC += 15 * k;
    k++;
  }

  int l = 0;
  while (l <= N) {
    sum++;
  }

  cout << sum - sumA - sumB + sumC << endl;
}
Problem p02712 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x, i = 2, sum = 1;
  cin >> x;
  for (; i <= x; i++) {
    if (i % 3 == 0 || i % 5 == 0)
      ;
    else
      sum = sum + i;
  }
  cout << sum;
  cout << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x, i = 2, sum = 1;
  scanf("%lld", x);
  for (i = 2; i <= x; i++) {
    if (i % 3 == 0 || i % 5 == 0)
      ;
    else
      sum += i;
  }
  cout << sum;
  cout << endl;
  return 0;
}
Problem p02712 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long int a, b, c, d;
  long int e = 0;
  vector<int> x = {1, 2, 0, 4, 0, 0, 7, 8, 0, 0, 11, 0, 13, 14};
  cin >> a;
  b = a / 15;
  c = a % 15;
  d = b * b * 60;
  for (int i = 0; i < c; i++) {
    if (x.at(i) != 0) {
      e += x.at(i) + (b * 15);
    }
  }
  cout << d + e;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long int a, b, c, d;
  long int e = 0;
  vector<int> x = {1, 2, 3, 7, 8, 11, 13, 14};
  cin >> a;
  b = a / 15;
  c = a % 15;
  d = b * b * 60;
  for (int i = 0; i < c; i++) {
    e += x.at(i) + (b * 15);
  }
  cout << d + e;
}
Problem p02712 (C++) — buggy submission, verdict: Runtime Error

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

#define int long long
#define ll long long
#define f(i, l, n) for (int i = l; i < n; i++)
#define E "\\n"
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define MAX 1e18
#define float long double

const int N = 1e5 + 3;
int sum(int n) { return (n * (n + 1)) / 2; }
int sol() {
  int n;
  cin >> n;

  int tot = n * (n + 1);
  tot /= 2;
  int th = n / 3, fi = n / 5, com = n / 15;

  cout << sum(n) - sum(th) * 3 - sum(fi) * 5 + sum(com) * 15;
  return 0;
}

int32_t main() { int t = sol(); }

Error: WA

Fixed submission:

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

#define int long long
#define ll long long
#define f(i, l, n) for (int i = l; i < n; i++)
#define E "\\n"
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define MAX 1e18
#define float long double

const int N = 1e5 + 3;
int sum(int n) { return (n * (n + 1)) / 2; }
int sol() {
  int n;
  cin >> n;

  int tot = n * (n + 1);
  tot /= 2;
  int th = n / 3, fi = n / 5, com = n / 15;

  cout << sum(n) - sum(th) * 3 - sum(fi) * 5 + sum(com) * 15;
}

int32_t main() { sol(); }
Problem p02712 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long N;
  scanf("%ld", &N);
  long ans = 0;
  for (long i = 1; i <= N; i++) {
    if (i % 3 != 0 && i % 5 != 0)
      ans += i;
  }
  printf("%ld", ans);
}


Error: -11

Fixed submission:

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

int main() {
  long N;
  scanf("%ld", N);
  long ans = 0;
  for (long i = 1; i <= N; i++) {
    if (i % 3 != 0 && i % 5 != 0)
      ans += i;
  }
  printf("%ld", ans);
}
Problem p02712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  long ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 != 0 && i % 5 != 0) {
      ans = ans + i;
    }
  }
  cout << ans << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  long ans;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 != 0 && i % 5 != 0) {
      ans += i;
    }
  }
  cout << ans << "\\n";
  return 0;
}
Problem p02712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

int main() {

  int N;
  std::cin >> N;

  long long Sum = 0;
  while (N > 0) {
    if (N % 5 != 0 && N % 3 != 0) {
      Sum += N;
    }
    N--;
  }

  std::cout << Sum << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

int main() {

  int N;
  std::cin >> N;

  long long Sum = 0;
  while (N > 0) {
    if (N % 3 != 0 && N % 5 != 0) {
      Sum += N--;
    }
  }

  std::cout << Sum << std::endl;

  return 0;
}
Problem p02712 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  long long int n;
  scanf("%lld", &n);
  long long int total = 0;

  for (int i = 0; i <= n; i++) {
    if (i % 3 == 0 && i % 5 == 0) {
      continue;
    } else if (i % 3 == 0) {
      continue;
    } else if (i % 5 == 0) {
      continue;
    } else {
      total += i;
    }
  }
  printf("%lld", total);
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>

int main() {
  int n;
  scanf("%lld", &n);
  int total = 0;

  for (int i = 0; i <= n; i++) {
    if (i % 3 == 0 && i % 5 == 0) {
      continue;
    } else if (i % 3 == 0) {
      continue;
    } else if (i % 5 == 0) {
      continue;
    } else {
      total += i;
    }
  }
  printf("%lld", total);
  return 0;
}
Problem p02712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  long long int max, sum = 0;
  scanf("%lld", &max);
  for (int i = 0; i <= max; i++) {
    if (i % 3 != 0 && i % 5 != 0) {
      sum = sum + i;
    }
  }
  printf("%lld", sum);
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  // jika 3 dan 5 membagi == fixxbuzz
  // jika dibagi 3 doang ==fizz
  // jika dibagi 5 doang == buzz
  // jika ttidak a =i
  // pakai long long int katanya warning overflow?
  long long int n, sum = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    if (i % 3 == 0 || i % 5 == 0) {
      continue;
    } else {
      sum += i;
    }
  }
  printf("%lld", sum);
  return 0;
}
Problem p02712 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  int N;
  long long int result = 0;
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    if (i % 3 != 0 && i % 5 != 0) {
      result += i;
    }
  }
  if (result > 266666333332) {
    printf("266666333332");
  } else {
    printf("%lld", result);
  }

  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>

int main() {
  int N;
  int ctr = 0;
  scanf("%lld", &N);
  for (int i = 1; i <= N; i++) {
    if (i % 3 == 0) {
      continue;
    } else if (i % 5 == 0) {
      continue;
    } else if (i % 3 && i % 5 == 0) {
      continue;
    } else {
      ctr += i;
    }
  }
  printf("%lld", ctr);
  return 0;
}
Problem p02712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  int test;
  scanf("%d", &test);
  int fizzbuzz;
  long long int jumlah = 0;
  for (int i = 1; i <= test; i++) {
    if (i % 3 == 0 && i % 5 == 0) {
      fizzbuzz += i;
    } else if (i % 3 == 0 || i % 5 == 0) {
      fizzbuzz += i;
    } else {
      jumlah += i;
    }
  }
  printf("%lld\\n", jumlah);
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  long int n;
  scanf("%d", &n);
  int sum = 0;
  for (long int i = 1; i <= n; i++) {
    if (i % 3 == 0 && i % 5 == 0) {
      continue;
    } else if (i % 3 == 0) {
      continue;
    } else if (i % 5 == 0) {
      continue;
    } else {
      sum += i;
    }
  }
  printf("%d\\n", sum);
  return 0;
}
Problem p02712 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  unsigned long int n, i = 0;
  unsigned long int sum = 0;
  cin >> n;

  while (n != 0) {
    i++;
    if (i % 3 != 0 && i % 5 != 0)
      sum += i;
    n--;
  }

  cout << sum;
}


Error: TLE

Fixed submission:

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

int main() {
  unsigned long int n, i;
  unsigned long int sum = 0;
  cin >> n;

  while (n != 0) {
    i++;
    if (i % 3 != 0 || i % 5 != 0)
      sum += 1;
    n++;
  }

  cout << sum;
}