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

#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int s;
    cin >> s;
    bool flag = false;
    for (int x = 1; x * x <= s && flag == false; x++) {
      if ((s - x) % (2 * x + 1) == 0) {
        flag = true;
      }
    }
    if (flag == false) {
      ans++;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int s;
    cin >> s;
    bool flag = false;
    for (int x = 1; x < s && flag == false; x++) {
      if ((s - x) % (2 * x + 1) == 0) {
        flag = true;
      }
    }
    if (flag == false) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p00513 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll calc(ll x, ll y) { return 2 * x * y + x + y; }
int main() {
  int n;
  cin >> n;
  int ans = n;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    bool ok = false;
    for (int x = 1; calc(x, x) <= k; x++) {
      if (k % (2 * x + 1) == x)
        ok = true;
    }
    if (ok)
      ans--;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  static bool input[1 << 24];
  int maxk;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    assert(k < (1 << 24));
    input[k] = true;
    if (i == n - 1)
      maxk = k;
  }
  int ans = n;
  for (int x = 1; x <= maxk; x++) {
    for (int y = 1; y <= x && (long long)2 * x * y + x + y <= maxk; y++) {
      if (input[2 * x * y + x + y]) {
        input[2 * x * y + x + y] = false;
        ans--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p00513 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const ull B = 100000007;
const int INF = 1e9;
int main() {
  int n, a, ans = 0;
  cin >> n;
  REP(i, n) {
    cin >> a;
    bool f = false;
    for (int x = 1; x * x < a; x++)
      if ((a + x + 1) % (2 * x + 1) == 0)
        f = true;
    if (!f)
      ans++;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const ull B = 100000007;
const int INF = 1e9;
int main() {
  int n, a, ans = 0;
  cin >> n;
  REP(i, n) {
    cin >> a;
    bool f = false;
    for (int x = 1; x < a; x++)
      if ((a + x + 1) % (2 * x + 1) == 0)
        f = true;
    if (!f)
      ans++;
  }
  cout << ans << endl;
}
Problem p00513 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

bool check(int a) {
  for (int x = 1; x * x <= a; x++)
    if ((a - x) % (2 * x + 1) == 0)
      return true;

  return false;
}

int main() {
  int n, ans;

  cin >> n;
  ans = 0;
  while (n--) {
    int area;

    cin >> area;
    if (!check(area)) {
      //  cout << area << " " << x << endl;
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int x;

bool check(int a) {
  for (int i = x; a - i >= 2 * i + 1; i++)
    if ((a - i) % (2 * i + 1) == 0)
      return true;
  x++;
  return false;
}

int main() {
  int n, ans;

  cin >> n;
  ans = 0;
  x = 1;
  while (n--) {
    int area;

    cin >> area;
    if (!check(area))
      ans++;
  }
  cout << ans << endl;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

const int SIZE = 1E6;
vector<int> primes;
vector<bool> bits(SIZE);

void sieve() {
  for (int i = 3; i < SIZE; i += 2) {
    if (!bits[i]) {
      primes.push_back(i);
      for (ll j = (ll)i * i; j < SIZE; j += i) {
        bits[(int)j] = true;
      }
    }
  }
}

int main() {
  sieve();
  int N;
  scanf("%d", &N);
  ll S;
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%lld", &S);
    S = S * 2 + 1;
    bool res = false;
    if (S < SIZE) {
      res = bits[(int)S];
    } else {
      for (int j = 0;; ++j) {
        ll p = primes[j];
        if (p * p > S)
          break;
        if (S % p == 0) {
          res = true;
          break;
        }
      }
    }
    if (!res)
      ++ans;
  }
  printf("%d\\n", ans);
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

const int SIZE = 1E6;
vector<int> primes;
vector<bool> bits(SIZE);

void sieve() {
  for (int i = 3; i < SIZE; i += 2) {
    if (!bits[i]) {
      primes.push_back(i);
      for (ll j = (ll)i * i; j < SIZE; j += i) {
        bits[(int)j] = true;
      }
    }
  }
}

int main() {
  sieve();
  int N;
  scanf("%d", &N);
  ll S;
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%lld", &S);
    S = S * 2 + 1;
    bool res = false;
    if (S < SIZE) {
      res = bits[(int)S];
    } else {
      for (int j = 0;; ++j) {
        int p = primes[j];
        if (p * p > S)
          break;
        if (S % p == 0) {
          res = true;
          break;
        }
      }
    }
    if (!res)
      ++ans;
  }
  printf("%d\\n", ans);
}
Problem p00513 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool judge(long long int x, int n) {
  if ((n - x) % (2 * x + 1) == 0) {
    return true;
  }
  return false;
}

int main() {
  int count = 0;
  int m;
  cin >> m;
  for (int t = 0; t < m; t++) {

    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    bool j = true;
    for (int x = 1; x * x <= n; x++) {
      if (judge(x, n)) {
        j = false;
        break;
      }
    }
    if (j) {
      count++;
    }
  }

  cout << count << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

bool judge(long long int x, int n) {
  if ((n - x) % (2 * x + 1) == 0) {
    return true;
  }
  return false;
}

int main() {
  int count = 0;
  int m;
  cin >> m;
  for (int t = 0; t < m; t++) {

    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    bool j = true;
    for (int x = 1; x < n / 2; x++) {
      if (judge(x, n)) {
        j = false;
        break;
      }
    }
    if (j) {
      count++;
    }
  }

  cout << count << endl;

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

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

  int ret = 0;
  for (int i = 0; i < n; ++i) {
    long long a;
    cin >> a;
    a = 2 * a + 1;

    bool ng = true;
    for (long long j = 2; j * j <= a; ++j) {
      if (a % j == 0) {
        ng = false;
        break;
      }
    }

    if (ng)
      ++ret;
  }

  cout << ret << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

  int ret = 0;
  for (int i = 0; i < n; ++i) {
    long long a;
    cin >> a;
    a = 2 * a + 1;

    bool ng = true;
    for (int j = 2; j * j <= a; ++j) {
      if (a % j == 0) {
        ng = false;
        break;
      }
    }

    if (ng)
      ++ret;
  }

  cout << ret << endl;

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)

#include <cstdio>
inline int getInt() {
  int s;
  scanf("%d", &s);
  return s;
}

#include <set>

using namespace std;

bool check(int s) {
  for (int i = 1; i * i <= s; i++)
    if ((s - i) % (2 * i + 1) == 0)
      return true;
  return false;
}

int main() {
  const int n = getInt();
  int cnt = 0;

  REP(i, n)
  if (!check(getInt()))
    cnt++;

  printf("%d\\n", cnt);

  return 0;
}

Error: TLE

Fixed submission:

#define REP(i, n) for (int i = 0; i < (int)(n); i++)

#include <cstdio>
inline int getInt() {
  int s;
  scanf("%d", &s);
  return s;
}

#include <set>

using namespace std;

bool check(int s) {
  for (int i = 1; s - i >= 2 * i + 1; i++)
    if ((s - i) % (2 * i + 1) == 0)
      return true;
  return false;
}

int main() {
  const int n = getInt();
  int cnt = 0;

  REP(i, n)
  if (!check(getInt()))
    cnt++;

  printf("%d\\n", cnt);

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

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int ans = 0;
  rep(i, n) {
    int a;
    cin >> a;

    bool flag = false;
    for (int y = 1; 2 * y * y + 2 * y <= a; y++) {
      if ((a - y) % (2 * y + 1) == 0) {
        flag = true;
      }
    }

    if (flag)
      ans++;
  }

  cout << n - ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int ans = 0;
  rep(i, n) {
    int a;
    cin >> a;

    bool flag = false;
    REP(y, 1, sqrt(a) + 1) {
      if ((a - y) % (2 * y + 1) == 0) {
        flag = true;
      }
    }

    if (flag)
      ans++;
  }

  cout << n - ans << endl;

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

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF (1 << 29)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
const int dx[] = {-1, 0, 0, 1}, dy[] = {0, 1, -1, 0};

typedef long long int ll;

using namespace std;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  REP(i, n) {
    int a;
    cin >> a;
    bool flg = false;
    for (int j = 1; 2 * j * j + 2 * j <= a; j++) {
      if ((a - j) % (2 * j + 1) == 0) {
        if ((a - j) / (2 * j + 1) >= j) {
          flg = true;
          break;
        }
      } else {
      }
    }
    if (!flg)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF (1 << 29)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
const int dx[] = {-1, 0, 0, 1}, dy[] = {0, 1, -1, 0};

typedef long long int ll;

using namespace std;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  REP(i, n) {
    int a;
    cin >> a;
    bool flg = false;
    FOR(j, 1, a) {
      if ((a - j) % (2 * j + 1) == 0) {
        flg = true;
        break;
      } else {
      }
    }
    if (!flg)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p00513 (C++) — buggy submission, verdict: Runtime Error

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

int n, x, sum;

int hantei(int p) {
  int v = max((int)sqrt(p) * 5, p);
  for (int i = 1; i <= sqrt(p); i++) {
    int a = p - i;
    if (a % (2 * i + 1) == 0 && a >= 1) {
      return 0;
    }
  }
  return 1;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    sum += hantei(x);
  }
  cout << sum << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int n, c, x[10000000], sum;
int main() {
  for (int i = 1; i <= 500000; i++) {
    for (int j = 1; j <= 1000000 / i; j++) {
      x[2 * i * j + i + j] = 1;
    }
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> c;
    if (x[c] == 0) {
      sum++;
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p00513 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

const int MAX = 1 << 17;
bool ifnprime[MAX + 1];
long long int p[MAX];
long long int ind = 0;

void set() {
  ifnprime[0] = ifnprime[1] = true;
  long long int n, m;
  for (n = 2; n <= MAX; n++) {
    if (!ifnprime[n]) {
      p[ind] = n;
      ind++;
      for (m = n * n; m <= MAX; m += n)
        ifnprime[m] = true;
    }
  }
}

int main() {
  set();
  int n, fault = 0;
  for (cin >> n; n--;) {
    long long int a, x;
    bool ok = false;
    cin >> a;
    a = 2 * a + 1;
    for (x = 0; p[x] * p[x] <= a; x++) {
      if (a % p[x] == 0) {
        ok = true;
        break;
      }
    }
    if (!ok)
      fault++;
  }
  cout << fault << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

const int MAX = 1 << 16;
bool ifnprime[MAX + 1];
long long int p[MAX];

void set() {
  ifnprime[0] = ifnprime[1] = true;
  int n, m, ind = 0;
  for (n = 2; n * n <= MAX; n++) {
    if (!ifnprime[n]) {
      p[ind++] = n;
      for (m = n * n; m <= MAX; m += n)
        ifnprime[m] = true;
    }
  }
}

int main() {
  set();
  int n, fault = 0;
  for (cin >> n; n--;) {
    long long int a, x;
    bool ok = false;
    cin >> a;
    a = 2 * a + 1;
    for (x = 0; p[x] * p[x] <= a; x++) {
      if (a % p[x] == 0) {
        ok = true;
        break;
      }
    }
    if (!ok)
      fault++;
  }
  cout << fault << endl;
  return 0;
}
Problem p00513 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#define int long long
using namespace std;

signed main() {
  int n, s;
  int ans = 0;

  cin >> n;
  while (cin >> s) {
    for (int x = 1; x * x <= s; x++) {
      if ((s - x) % (2 * x + 1) == 0 && (s - x) >= (2 * x + 1)) {
        ans++;
        break;
      }
    }
  }
  ans = n - ans;
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#define int long long
using namespace std;

signed main() {
  int n, s;
  int ans = 0;

  cin >> n;
  while (cin >> s) {
    for (int x = 1; x * x <= s; x++) {
      for (int y = 1; 2 * x * y <= s; y++) {
        if (2 * x * y + x + y == s) {
          ans++;
          x = s + 1;
          y = s + 1;
        }
      }
    }
  }
  ans = n - ans;
  cout << ans << endl;
  return 0;
}
Problem p00513 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

typedef long long ll;

const ll MAX = (1 << 31) - 1;

bool invalid(ll n) {

  for (ll x = 1; 2 * x * x <= n; x++)
    if ((n - x) % (2 * x + 1) == 0)
      return false;

  return true;
}

int main() {

  ll ans = 0;
  ll n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll area;
    cin >> area;

    if (invalid(area))
      ans++;
  }
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

typedef long long ll;

const ll MAX = (1 << 31) - 1;

bool invalid(ll n) {

  for (ll x = 1; 3 * x <= n; x++)
    if ((n - x) % (2 * x + 1) == 0)
      return false;

  return true;
}

int main() {
  ll ans = 0;
  ll n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll area;
    cin >> area;
    if (invalid(area))
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p00513 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
using namespace std;

int main() {
  int N[100000];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> N[i];
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < sqrt(N[i]); j++) {
      if (N[i] % (2 * j + 1) == j) {
        // cout << "N[i] % ( 2 * j +1 ) == j" << " " << N[i] << " " << j <<
        // endl;
        cnt++;
        break;
      }
    }
  }
  // cout << "cnt" << " " << cnt << endl;
  // cout << "n-cnt" << " " << n-cnt << endl;
  cout << n - cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int N[100000];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> N[i];
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < N[i]; j++) {
      if (N[i] % (2 * j + 1) == j) {
        // cout << "N[i] % ( 2 * j +1 ) == j" << " " << N[i] << " " << j <<
        // endl;
        cnt++;
        break;
      }
    }
  }
  // cout << "cnt" << " " << cnt << endl;
  // cout << "n-cnt" << " " << n-cnt << endl;
  cout << n - cnt << endl;
  return 0;
}
Problem p00513 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
using namespace std;
long long int powint(long long int a, int b) {
  if (b == 0)
    return 1;
  if (b == 1)
    return a;
  else {
    long long int ans = 1;
    long long int c = powint(a, b / 2);
    ans *= c * c;
    ans *= (b % 2) ? a : 1;
    return ans;
  }
}
vector<int> primes;
void hurui(const int amax) {
  static bool flag = false;
  if (flag)
    return;
  vector<int> sos;
  sos = vector<int>(amax + 1, true);
  sos[0] = false;
  sos[1] = false;
  for (int i = 2; i <= amax; ++i) {
    if (sos[i]) {
      for (int j = 2 * i; j <= amax; j += i)
        sos[j] = false;
    }
  }
  for (int i = 0; i <= amax; ++i) {
    if (sos[i]) {
      primes.push_back(i);
    }
  }
  flag = true;
}
vector<long long int> divisor(map<long long int, int> s) {
  vector<long long int> res;
  int num = 1;
  for (auto it = s.begin(); it != s.end(); ++it) {
    num *= (*it).second + 1;
  }
  for (int i = 0; i < num; ++i) {
    int bs = i;
    long long int p = 1;
    for (auto it = s.begin(); it != s.end(); ++it) {
      int a = bs % ((*it).second + 1);
      p *= powint((*it).first, a);
      bs /= ((*it).second + 1);
    }
    res.push_back(p);
  }
  return res;
}
map<long long int, int> soinnsuu(long long int a) {
  hurui(1e5);
  map<long long int, int> ans;
  for (auto km : primes) {
    int i = km;
    if (i > a)
      break;
    while (a % i == 0) {
      ans[i]++;
      a /= i;
    }
  }
  if (a != 1)
    ans[a]++;
  return ans;
}

bool check(const long long int a) {
  if (a >= 3) {
    return a % 2;
  } else {
    return false;
  }
}

int main() {
  int ans = 0;
  int N;
  cin >> N;
  while (N--) {
    long long int a;
    cin >> a;
    a = 2 * a + 1;
    auto vs = divisor(soinnsuu(a));
    bool ok = false;
    for (int i = 0; i < vs.size() / 2 + 1; ++i) {
      long long int a = vs[i];
      long long int b = vs[vs.size() - i - 1];
      if (check(a) && check(b))
        ok = true;
    }
    ans += !ok;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

vector<long long int> divisor(long long int n) {
  vector<long long int> res;
  for (long long int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      res.push_back(i);
      if (i * i != n)
        res.push_back(n / i);
    }
  }
  sort(begin(res), end(res));
  return res;
}
bool check(const long long int a) {
  if (a >= 3) {
    return a % 2;
  } else {
    return false;
  }
}

int main() {
  int ans = 0;
  int N;
  cin >> N;
  while (N--) {
    long long int a;
    cin >> a;
    a = 2 * a + 1;
    auto vs = divisor(a);
    bool ok = false;
    for (int i = 0; i < vs.size() / 2 + 1; ++i) {
      long long int a = vs[i];
      long long int b = vs[vs.size() - i - 1];
      if (check(a) && check(b))
        ok = true;
    }
    ans += !ok;
  }
  cout << ans << endl;
  return 0;
}
Problem p00513 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>

using namespace std;

bool check(int S) {
  int x = 1;
  while (2 * (x * x + x) <= S) {
    if ((S - x) % (2 * x + 1) == 0)
      return false;
    x++;
  }
  return true;
}

int main() {

  int N;
  cin >> N;
  int found = 0;
  for (int i = 1; i <= N; i++) {
    int S;
    cin >> S;
    if (check(S))
      found++;
  }
  cout << found << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

bool check(double a) {
  for (int i = 1; 1 <= (a - i) / (2 * i + 1) && a >= 3 * i + 1; i++) {
    double val = (a - i) / (2 * i + 1);
    int ival = val;
    if (val == ival)
      return true;
  }
  return false;
}

int main() {

  int N;
  cin >> N;
  int found = 0;
  for (int i = 1; i <= N; i++) {
    int num;
    cin >> num;
    if (!check(num))
      found++;
  }
  cout << found << endl;
  return 0;
}
Problem p00513 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> Pi;

bool judge(int area) {
  // 式変形だね!!
  // area - y = (2y + 1)x
  //(area - y) % (2y + 1)
  for (int y = 1; y < min<int>(100000, area); y++) {
    if ((area - y) % (2 * y + 1) == 0)
      return true;
  }
  return false;
}

int main() {
  int N, room[100000];

  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &room[i]);
  }
  int ret = 0;
  for (int i = 0; i < N; i++) {
    ret += !judge(room[i]);
  }
  printf("%d\\n", ret);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> Pi;

bool judge(int area) {
  // 式変形だね!!
  // area - y = (2y + 1)x
  //(area - y) % (2y + 1)x
  //(area - y) % (2y + 1)

  for (int y = 1; y < area; y++) {
    if ((area - y) % (2 * y + 1) == 0)
      return true;
  }
  return false;
}

int main() {
  int N, room[100000];

  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &room[i]);
  }
  int ret = 0;
  for (int i = 0; i < N; i++) {
    ret += !judge(room[i]);
  }
  printf("%d\\n", ret);
}