prithivMLmods/Coder-Stat huggingface dataset:
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
/* [Template].cpp
Example code to use when starting new code. This particular problem was problem
977A_Wrong_Subtraction from CodeForces

Compile: g++  -o D.exe D.cpp
Execute: ./D
*/

#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
using namespace std;

int main() {
  int n, a[200000];
  bool dp[1000001] = {false};
  int a_max = 1000000;
  int result = 0;
  int dummy;

  // Input
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  // Sort array
  sort(a, a + n);

  // Sieve for elements in list
  for (int i = 0; i < n; i++) {
    for (int dummy = a[i] * 2; dummy <= a_max; dummy += a[i]) {
      if (!dp[dummy])
        dp[dummy] = true;
    }
    if (i > 0)
      if (a[i] == a[i - 1])
        dp[a[i]] = true;
    if (i < n - 1)
      if (a[i] == a[i + 1])
        dp[a[i]] = true;
  }

  // Search through list to see if elements are safe
  for (int i = 0; i < n; i++) {
    // cout << "testing: " << a[i] << " " << dp[a[i]] << endl;
    if (!dp[a[i]]) {
      result++;
    }
  }

  cout << result << endl;

  return 0;
}


Fixed submission:
/* [Template].cpp
Example code to use when starting new code. This particular problem was problem
977A_Wrong_Subtraction from CodeForces

Compile: g++  -o D.exe D.cpp
Execute: ./D
*/

#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
using namespace std;

int main() {
  int n, a[200000];
  bool dp[1000001] = {false};
  int a_max = 1000000;
  int result = 0;
  int dummy;

  // Input
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  // Sort array
  sort(a, a + n);

  // Edge cases related to 1
  if (n == 1 && a[0] == 1) {
    cout << 1 << endl;
    return 0;
  }
  if (n > 1 && a[0] == 1 && a[1] == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (n > 1 && a[0] == 1 && a[1] != 1) {
    cout << 1 << endl;
    return 0;
  }

  // Sieve for elements in list
  for (int i = 0; i < n; i++) {
    for (int dummy = a[i] * 2; dummy <= a_max; dummy += a[i]) {
      if (!dp[dummy])
        dp[dummy] = true;
    }
    if (i > 0)
      if (a[i] == a[i - 1])
        dp[a[i]] = true;
    if (i < n - 1)
      if (a[i] == a[i + 1])
        dp[a[i]] = true;
  }

  // Search through list to see if elements are safe
  for (int i = 0; i < n; i++) {
    // cout << "testing: " << a[i] << " " << dp[a[i]] << endl;
    if (!dp[a[i]]) {
      result++;
    }
  }

  cout << result << endl;

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
//   Rishabh Agarwal
#include <bits/stdc++.h>
#define F first
#define S second
#define MAX 10000003
using namespace std;

typedef long long int ll;
const ll mod = 1e9 + 7;
const ll INF = 1e18;
long double PI = 3.1415926;

map<ll, ll> mp;

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

#ifndef ONLINE_JUDGE
  freopen("inp.txt", "r", stdin);
  freopen("out.tex", "w", stdout);
#endif

  ll n;
  cin >> n;
  ll a[n];
  for (ll x = 0; x < n; x++) {
    cin >> a[x];
  }
  sort(a, a + n);
  ll sum = 0;
  for (ll x = 0; x < n; x++) {
    ll p = sqrtl(a[x]);
    ll ans = 0;
    for (ll y = 1; y <= p; y++) {
      if (a[x] % y == 0) {
        if (mp[y] != 0 || mp[a[x] / y] != 0) {
          ans++;
        }
      }
    }
    mp[a[x]]++;
    ll r = sum;
    if (ans == 0) {
      sum++;
    }
    if (x < n - 1 && a[x] == a[x + 1] && sum - r == 1) {
      sum--;
    }
  }
  cout << sum << "\n";
  mp.clear();
  return 0;
}


Fixed submission:
//   Rishabh Agarwal
#include <bits/stdc++.h>
#define F first
#define S second
#define MAX 10000003
using namespace std;

typedef long long int ll;
const ll mod = 1e9 + 7;
const ll INF = 1e18;
long double PI = 3.1415926;

map<ll, ll> mp;

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

#ifndef ONLINE_JUDGE
  freopen("inp.txt", "r", stdin);
  freopen("out.tex", "w", stdout);
#endif

  ll n;
  cin >> n;
  ll a[n];
  for (ll x = 0; x < n; x++) {
    cin >> a[x];
  }
  sort(a, a + n);
  ll sum = 0;
  for (ll x = 0; x < n; x++) {
    ll p = sqrt(a[x]);
    ll ans = 0;
    for (ll y = 1; y <= p; y++) {
      if (a[x] % y == 0) {
        if (mp[y] != 0 || mp[a[x] / y] != 0) {
          ans++;
        }
      }
    }
    mp[a[x]]++;
    ll r = sum;
    if (ans == 0) {
      sum++;
    }
    if (x < n - 1 && a[x] == a[x + 1] && sum - r == 1) {
      sum--;
    }
  }
  cout << sum << "\n";
  mp.clear();
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline void dump(vector<T> v) {
  for (auto &x : v)
    cerr << x << " ";
  cerr << endl;
}
template <class T> inline void dump(vector<pair<T, T>> v) {
  for (auto &p : v)
    cerr << p.first << " " << p.second << endl;
}
template <class T> inline void dump(vector<vector<T>> vv) {
  for (auto &v : vv) {
    for (auto &x : v)
      cerr << x << " ";
    cerr << endl;
  }
}
constexpr int INF = 1001001001;
constexpr long long INFL = (1LL << 60);
constexpr double eps = (1e-9);

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }

  sort(ALL(a));

  vector<int> v(1000001, 0);
  for (auto &x : a) {
    v[x]++;
    for (int i = x * 2; i <= 1000000; i += x) {
      v[i]++;
    }
  }

  int ans = 0;

  for (auto &x : a) {
    if (v[x] == 1)
      ans++;
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline void dump(vector<T> v) {
  for (auto &x : v)
    cerr << x << " ";
  cerr << endl;
}
template <class T> inline void dump(vector<pair<T, T>> v) {
  for (auto &p : v)
    cerr << p.first << " " << p.second << endl;
}
template <class T> inline void dump(vector<vector<T>> vv) {
  for (auto &v : vv) {
    for (auto &x : v)
      cerr << x << " ";
    cerr << endl;
  }
}
constexpr int INF = 1001001001;
constexpr long long INFL = (1LL << 60);
constexpr double eps = (1e-9);

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }

  sort(ALL(a));

  vector<int> v(1000001, 0);
  for (auto &x : a) {
    if (v[x] != 0) {
      v[x]++;
      continue;
    }
    for (int i = x; i <= 1000000; i += x) {
      v[i]++;
    }
  }

  int ans = 0;

  for (auto &x : a) {
    if (v[x] == 1)
      ans++;
  }

  cout << ans << endl;

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a)                                                               \
  rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define ia(n, a) rp(ia_i, 0, n) cin >> a[ia_i]
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
vector<long long> divisor(long long n) {
  vector<long long> res;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i)
        res.push_back(n / i);
    }
  }
  return res;
}
int main() {
  ll n;
  cin >> n;
  vl a(n);
  rp(i, 0, n) cin >> a[i];
  sort(be(a));
  map<ll, ll> all;
  rp(i, 0, n - 1) {
    if (a[i] == a[i + 1])
      all[a[i]]++;
  }
  ll ans = 0;
  rp(i, 0, n) {
    bool sig = true;
    vl now = divisor(a[i]);
    rp(j, 0, now.size()) {
      if (all[now[j]] > 0) {
        sig = false;
      }
    }
    all[a[i]]++;
    if (sig)
      ans++;
  }
  ce(ans);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a)                                                               \
  rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define ia(n, a) rp(ia_i, 0, n) cin >> a[ia_i]
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
vector<long long> divisor(long long n) {
  vector<long long> res;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i)
        res.push_back(n / i);
    }
  }
  return res;
}
int main() {
  ll n;
  cin >> n;
  vl a(n);
  rp(i, 0, n) cin >> a[i];
  sort(be(a));
  ll all[1111111];
  za(1111111, all);
  rp(i, 0, n - 1) {
    if (a[i] == a[i + 1])
      all[a[i]]++;
  }
  ll ans = 0;
  rp(i, 0, n) {
    bool sig = true;
    vl now = divisor(a[i]);
    rp(j, 0, now.size()) {
      if (all[now[j]] > 0) {
        sig = false;
      }
    }
    all[a[i]]++;
    if (sig)
      ans++;
  }
  ce(ans);
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#include <cstdlib>

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

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

  vector<int> a(n);
  rep(i, n) cin >> a.at(i);

  sort(a.begin(), a.end());

  vector<int> yakusuu(1000005, 0);
  rep(i, n) {
    int x = a.at(i);
    for (int j = x; j < 1000005; j += x) {
      yakusuu.at(j)++;
    }
  }

  int ans = 0;
  rep(i, n) {
    int x = a.at(i);
    if (yakusuu.at(x) == 1)
      ans++;
  }

  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#include <cstdlib>

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

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

  vector<int> a(n);
  rep(i, n) cin >> a.at(i);

  sort(a.begin(), a.end());

  vector<int> yakusuu(1000005, 0);
  rep(i, n) {
    int x = a.at(i);
    if (yakusuu.at(x) != 0) {
      yakusuu.at(x) = 2;
      continue;
    }
    for (int j = x; j < 1000005; j += x) {
      yakusuu.at(j)++;
    }
  }

  int ans = 0;
  rep(i, n) {
    int x = a.at(i);
    if (yakusuu.at(x) == 1)
      ans++;
  }

  cout << ans;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> xs(n);
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    xs[i] = x;
    mp[x]++;
  }

  int bound = 1000010;
  vector<bool> table(bound);
  sort(xs.begin(), xs.end());
  int ans = 0;
  for (int i = 0; i < xs.size(); i++) {
    int v = xs[i];
    if (!table[v] && mp[v] == 1) {
      ans++;
    }
    for (int j = v; j < bound; j += v) {
      table[j] = true;
    }
  }

  if (n == 1) {
    cout << 1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> xs(n);
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    xs[i] = x;
    mp[x]++;
  }

  int bound = 1000010;
  vector<bool> table(bound);
  sort(xs.begin(), xs.end());
  int ans = 0;
  for (int i = 0; i < xs.size(); i++) {
    int v = xs[i];
    if (!table[v] && mp[v] == 1) {
      ans++;
    }
    if (!table[v]) {
      for (int j = v; j < bound; j += v) {
        table[j] = true;
      }
    }
  }

  if (n == 1) {
    cout << 1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a), i##_len = (b); i < i##_len; ++i)
#define MSVC_UNKO(x) x
#define rep(...)                                                               \
  MSVC_UNKO(_overload3(__VA_ARGS__, repi, _rep, _rep)(__VA_ARGS__))
#define all(c) c.begin(), c.end()
#define write(x) cout << (x) << '\n'
using namespace std;
using ll = long long;
template <class T> using vv = vector<vector<T>>;
template <class T> auto vvec(int n, int m, T v) {
  return vv<T>(n, vector<T>(m, v));
}
constexpr int INF = 1 << 29, MOD = int(1e9) + 7;
constexpr ll LINF = 1LL << 60;
struct aaa {
  aaa() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(10);
  };
} aaaa;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];

  sort(all(A));

  constexpr int Amax = 1e6;
  vector<bool> isDiv(Amax + 1);

  int ans = 0;
  rep(i, N) {
    if ((i == N - 1 || A[i] != A[i + 1]) && !isDiv[A[i]])
      ans++;
    for (int n = A[i]; n <= Amax; n += A[i]) {
      isDiv[n] = true;
    }
  }

  write(ans);
}


Fixed submission:
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a), i##_len = (b); i < i##_len; ++i)
#define MSVC_UNKO(x) x
#define rep(...)                                                               \
  MSVC_UNKO(_overload3(__VA_ARGS__, repi, _rep, _rep)(__VA_ARGS__))
#define all(c) c.begin(), c.end()
#define write(x) cout << (x) << '\n'
using namespace std;
using ll = long long;
template <class T> using vv = vector<vector<T>>;
template <class T> auto vvec(int n, int m, T v) {
  return vv<T>(n, vector<T>(m, v));
}
constexpr int INF = 1 << 29, MOD = int(1e9) + 7;
constexpr ll LINF = 1LL << 60;
struct aaa {
  aaa() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(10);
  };
} aaaa;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];

  sort(all(A));

  constexpr int Amax = 1e6;
  vector<bool> isDiv(Amax + 1);

  int ans = 0;
  for (int i = 0, j; i < N; i = j) {
    for (j = i + 1; j < N; ++j) {
      if (A[j] != A[i])
        break;
    }
    if (isDiv[A[i]])
      continue;
    else {
      if (j - i == 1)
        ans++;
      for (int n = A[i]; n <= Amax; n += A[i]) {
        isDiv[n] = true;
      }
    }
  }

  write(ans);
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
bool good[1000005];
int a[200005], rep[1000005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> v;
  memset(rep, 0, sizeof rep);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    rep[a[i]]++;
    v.push_back(a[i]);
  }
  memset(good, 0, sizeof good);
  for (int i = 0; i < n; i++) {
    if (i > 0)
      if (v[i] == v[i - 1])
        continue;
    for (int j = v[i] * 2; j <= 1000000; j += v[i]) {
      good[j] = true;
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (!good[a[i]] && rep[a[i]] == 1) {
      cnt++;
    }
  }
  cout << cnt;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
bool good[1000005];
int a[200005], rep[1000005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> v;
  memset(rep, 0, sizeof rep);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    rep[a[i]]++;
    v.push_back(a[i]);
  }
  sort(v.begin(), v.end());
  memset(good, 0, sizeof good);
  for (int i = 0; i < n; i++) {
    if (i > 0)
      if (v[i] == v[i - 1])
        continue;
    for (int j = v[i] * 2; j <= 1000000; j += v[i]) {
      good[j] = true;
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (!good[a[i]] && rep[a[i]] == 1) {
      cnt++;
    }
  }
  cout << cnt;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {
  int N;
  cin >> N;
  int A[N];
  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    mp[A[i]]++;
  }
  for (int i = 0; i < N; i++) {
    auto yaku = divisor(A[i]);
    for (auto j : yaku) {
      if (j == A[i])
        continue;
      if (mp[j] >= 1) {
        mp[A[i]]++;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (mp[A[i]] == 1) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

vector<int> divisor(int n) {
  vector<int> ret;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {
  int N;
  cin >> N;
  int A[N];
  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    mp[A[i]]++;
  }
  for (int i = 0; i < N; i++) {
    auto yaku = divisor(A[i]);
    for (auto j : yaku) {
      if (j == A[i])
        continue;
      if (mp[j] >= 1) {
        mp[A[i]]++;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (mp[A[i]] == 1) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

int main() {
  int N;
  const int MAX_VAL = 200100;

  cin >> N;
  vector<int> cnt(MAX_VAL);
  vector<int> val(N, 0);

  int t;
  rep(i, N) cin >> val.at(i);

  for (int x : val) {
    if (cnt.at(x) != 0) {
      cnt.at(x) = 2;
      continue;
    }
    for (int i = x; i < MAX_VAL; i += x)
      cnt.at(i)++;
  }

  int ans = 0;
  for (int x : val) {
    if (cnt.at(x) == 1)
      ans++;
  }

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

int main() {
  int N;
  const int MAX_VAL = 1000005;

  cin >> N;
  vector<int> cnt(MAX_VAL);
  vector<int> val(N, 0);

  int t;
  rep(i, N) cin >> val.at(i);

  for (int x : val) {
    if (cnt.at(x) != 0) {
      cnt.at(x) = 2;
      continue;
    }
    for (int i = x; i < MAX_VAL; i += x)
      cnt.at(i)++;
  }

  int ans = 0;
  for (int x : val) {
    if (cnt.at(x) == 1)
      ans++;
  }

  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int a[200001], v[100001];
bool b[1000001];

int main() {
  int n, maxn;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    v[a[i]]++;
    maxn = max(maxn, a[i]);
  }

  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }

  for (int now = 1; now <= n; now++) {
    int i = a[now];
    bool f = true;
    v[i]--;

    for (int j = 1; j * j <= i; j++) {
      if (i % j != 0)
        continue;

      if (v[j] > 0 || v[i / j] > 0) {
        f = false;
        break;
      }
    }
    if (f)
      b[i] = 1;

    v[i]++;
  }

  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (b[a[i]])
      cnt++;
  cout << cnt << endl;
  return 0;
}

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

int a[200001], v[1000001];
bool b[1000001];

int main() {
  int n, maxn;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    v[a[i]]++;
    maxn = max(maxn, a[i]);
  }

  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }

  for (int now = 1; now <= n; now++) {
    int i = a[now];
    bool f = true;
    v[i]--;

    for (int j = 1; j * j <= i; j++) {
      if (i % j != 0)
        continue;

      if (v[j] > 0 || v[i / j] > 0) {
        f = false;
        break;
      }
    }
    if (f)
      b[i] = 1;

    v[i]++;
  }

  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (b[a[i]])
      cnt++;
  cout << cnt << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A.at(i);
  }
  vector<int> X(100001);
  for (int a : A) {
    X[a] += 1;
  }
  int c = 0;
  for (int a : A) {
    X[a] -= 1;
    int q, r;
    bool f = true;
    for (int i = 1; i < int(sqrt(a)) + 1; i++) {
      q = a / i;
      r = a % i;
      if (r == 0) {
        if (X[i] != 0 || X[q] != 0) {
          f = false;
          break;
        }
      }
    }
    c += int(f);
    X[a] += 1;
  }
  cout << c << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A.at(i);
  }
  vector<int> X(1000001);
  for (int a : A) {
    X[a] += 1;
  }
  int c = 0;
  for (int a : A) {
    X[a] -= 1;
    int q, r;
    bool f = true;
    for (int i = 1; i < int(sqrt(a)) + 1; i++) {
      q = a / i;
      r = a % i;
      if (r == 0) {
        if (X[i] != 0 || X[q] != 0) {
          f = false;
          break;
        }
      }
    }
    c += int(f);
    X[a] += 1;
  }
  cout << c << endl;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
/// in the name of Allah the most beneficent the most merciful.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
// #define mod2 20071027
// #define MOD 998244353
#define base 139
// #define mod 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case #%lld: ", ++c)
#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define FILE                                                                   \
  freopen("input.txt", "r", stdin);                                            \
  freopen("out.txt", "w", stdout);
#define out(x) cout << #x << " -> " << x << endl;
using namespace std;
const ll N = 300010, M = 2000005;
ll a[N], n, res;
bool vis[M], freq[M];
int solve() {
  in1(n);
  for (int i = 0; i < n; i++) {
    in1(a[i]);
    if (freq[a[i]] > 0)
      vis[a[i]] = 1;
    freq[a[i]] = 1;
    for (int j = 2 * a[i]; j <= 1000000; j += a[i]) {
      vis[j] = 1;
    }
  }
  for (int i = 0; i < n; i++)
    if (vis[a[i]] == 0)
      res++;
  printf("%lld\n", res);
  return 0;
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int ret = solve();
  return 0;
}
/*

*/


Fixed submission:
/// in the name of Allah the most beneficent the most merciful.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
// #define mod2 20071027
// #define MOD 998244353
#define base 139
// #define mod 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case #%lld: ", ++c)
#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define FILE                                                                   \
  freopen("input.txt", "r", stdin);                                            \
  freopen("out.txt", "w", stdout);
#define out(x) cout << #x << " -> " << x << endl;
using namespace std;
const ll N = 300010, M = 2000005;
ll a[N], n, res;
bool vis[M], freq[M];
int solve() {
  in1(n);
  for (int i = 0; i < n; i++) {
    in1(a[i]);
    if (freq[a[i]] > 0)
      vis[a[i]] = 1;
    freq[a[i]] = 1;
    if (vis[a[i]] == 0) {
      for (int j = 2 * a[i]; j <= 1000000; j += a[i]) {
        vis[j] = 1;
      }
    }
  }
  for (int i = 0; i < n; i++)
    if (vis[a[i]] == 0)
      res++;
  printf("%lld\n", res);
  return 0;
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int ret = solve();
  return 0;
}
/*

*/
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int N = 2e5 + 5;

int f[N], dp[N];

void compute() {
  for (int i = 1; i < N; ++i) {
    if (f[i] > 0) {
      if (f[i] > 1)
        dp[i] = 1;

      for (int j = 2; i * j < N; ++j)
        dp[i * j] = 1;
    }
  }

  return;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int n, res = 0;
  cin >> n;

  int a[N];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ++f[a[i]];
  }

  compute();

  for (int i = 0; i < n; ++i)
    res += !dp[a[i]];

  cout << res;

  return 0;
}

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

#define int long long

const int N = 1e6 + 5;

int f[N], dp[N];

void compute() {
  for (int i = 1; i < N; ++i) {
    if (f[i] > 0) {
      if (f[i] > 1)
        dp[i] = 1;

      for (int j = 2; i * j < N; ++j)
        dp[i * j] = 1;
    }
  }

  return;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int n, res = 0;
  cin >> n;

  int a[N];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ++f[a[i]];
  }

  compute();

  for (int i = 0; i < n; ++i)
    res += !dp[a[i]];

  cout << res;

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
// Author: pankaj_m05

#include <bits/stdc++.h>
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define f_in(file) freopen(file, "r", stdin)
#define f_out(file) freopen(file, "w", stdout)
#define sz(a) int((a).size())
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) c.begin(), c.end()
#define tr(c, i) for (typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c, x) (c.find(x) != c.end())      // Set and Maps
#define cpresent(c, x) (find(allc, x) != c.end()) // Vectors
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const int mxN = 2 * 1e5;
const int mxA = 1e6;
int n, a[mxN];
int cnt[mxA + 1];

void testcase() {
  cin >> n;
  int mx = -1;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  for (int i = 0; i < n; ++i) {
    int t = a[i];
    if (cnt[t] >= 1) {
      ++cnt[t];
      continue;
    }
    while (t <= mx) {
      ++cnt[t];
      t += a[i];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (cnt[a[i]] <= 1)
      ++ans;
  }
  cout << ans << '\n';
}

int main(void) {
  fast int t;
  cin >> t;
  while (t--) {
    testcase();
  }
  return 0;
}

Fixed submission:
// Author: pankaj_m05

#include <bits/stdc++.h>
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define f_in(file) freopen(file, "r", stdin)
#define f_out(file) freopen(file, "w", stdout)
#define sz(a) int((a).size())
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) c.begin(), c.end()
#define tr(c, i) for (typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c, x) (c.find(x) != c.end())      // Set and Maps
#define cpresent(c, x) (find(allc, x) != c.end()) // Vectors
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const int mxN = 2 * 1e5;
const int mxA = 1e6;
int n, a[mxN];
int cnt[mxA + 1];

void testcase() {
  cin >> n;
  int mx = -1;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  for (int i = 0; i < n; ++i) {
    int t = a[i];
    if (cnt[t] >= 1) {
      ++cnt[t];
      continue;
    }
    while (t <= mx) {
      ++cnt[t];
      t += a[i];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (cnt[a[i]] <= 1)
      ++ans;
  }
  cout << ans << '\n';
}

int main(void) {
  fast testcase();
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, bool> m;
  set<int> s;
  rep(i, n) {
    cin >> a[i];
    if (s.count(a[i])) {
      m[a[i]] = true;
    } else {
      s.insert(a[i]);
    }
  }
  vector<bool> b(1000001, true);
  for (int x : a) {
    for (int i = x + x; i <= 1000000; i += x) {
      b[i] = false;
    }
  }
  int cnt = 0;
  rep(i, n) {
    if (m[a[i]]) {
      continue;
    }
    if (b[a[i]]) {
      cnt++;
    }
  }
  cout << cnt << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, bool> m;
  set<int> s;
  rep(i, n) {
    cin >> a[i];
    if (s.count(a[i])) {
      m[a[i]] = true;
    } else {
      s.insert(a[i]);
    }
  }
  vector<bool> b(1000001, true);
  for (int x : s) {
    for (int i = x + x; i <= 1000000; i += x) {
      b[i] = false;
    }
  }
  int cnt = 0;
  rep(i, n) {
    if (m[a[i]]) {
      continue;
    }
    if (b[a[i]]) {
      cnt++;
    }
  }
  cout << cnt << endl;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

ll gcd(ll n, ll m) {
  ll tmp;
  while (m != 0) {
    tmp = n % m;
    n = m;
    m = tmp;
  }
  return n;
}

ll lcm(ll n, ll m) {
  return abs(n) / gcd(n, m) * abs(m); // gl=xy
}

using namespace std;

void solve() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<bool> b(1e6 + 5);
  vector<int> ng(1e6 + 5);
  sort(all(a));
  rep(i, n) {
    ng[a[i]]++;
    if (b[a[i]])
      continue;
    for (int j = a[i] + a[i];; j += a[i]) {
      if (j > 1e6)
        break;
      b[j] = true;
    }
  }
  int ans = 0;
  rep(i, n) {
    if (ng[a[i]] >= 2)
      continue;
    if (b[a[i]])
      continue;
    ++ans;
  }
  cout << ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

ll gcd(ll n, ll m) {
  ll tmp;
  while (m != 0) {
    tmp = n % m;
    n = m;
    m = tmp;
  }
  return n;
}

ll lcm(ll n, ll m) {
  return abs(n) / gcd(n, m) * abs(m); // gl=xy
}

using namespace std;

void solve() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<bool> b(1e6 + 5);
  vector<int> ng(1e6 + 5);
  sort(all(a));
  rep(i, n) {
    if (ng[a[i]]) {
      ng[a[i]]++;
      continue;
    }
    ng[a[i]]++;
    if (b[a[i]])
      continue;
    for (int j = a[i] + a[i];; j += a[i]) {
      if (j > 1e6)
        break;
      b[j] = true;
    }
  }
  int ans = 0;
  rep(i, n) {
    if (ng[a[i]] >= 2)
      continue;
    if (b[a[i]])
      continue;
    ++ans;
  }
  cout << ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define REP(i, j, n) for (int i = j; i < n; i++)
#define rep(i, n) REP(i, 0, n)

vector<int64_t> divisor(int64_t n) {
  vector<int64_t> ret;
  for (int64_t i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int64_t> vec(n);
  rep(i, n) cin >> vec[i];
  sort(vec.begin(), vec.end());

  int cnt = 0;
  rep(i, n) {
    vector<int64_t> div = divisor(vec[i]);
    div.push_back(vec[i]);
    // bool flag = false;
    for (int j = 0; j < div.size(); j++) {
      int d = upper_bound(vec.begin(), vec.end(), div[j]) -
              lower_bound(vec.begin(), vec.end(), div[j]);
      // cout << vec[i] << " " << div[j] << " " << d << endl;
      if (d == 1 && div[j] != vec[i]) {
        cnt++;
        // flag = true;
        break;
      } else if (d > 1) {
        cnt++;
        break;
      }
    }
  }
  cout << n - cnt << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define REP(i, j, n) for (int i = j; i < n; i++)
#define rep(i, n) REP(i, 0, n)

vector<int64_t> divisor(int64_t n) {
  vector<int64_t> ret;
  for (int64_t i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  //   sort(begin(ret), end(ret));
  return (ret);
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int64_t> vec(n);
  rep(i, n) cin >> vec[i];
  sort(vec.begin(), vec.end());

  int cnt = 0;
  rep(i, n) {
    vector<int64_t> div = divisor(vec[i]);
    div.push_back(vec[i]);
    // bool flag = false;
    for (int j = 0; j < div.size(); j++) {
      int d = upper_bound(vec.begin(), vec.end(), div[j]) -
              lower_bound(vec.begin(), vec.end(), div[j]);
      // cout << vec[i] << " " << div[j] << " " << d << endl;
      if (d == 1 && div[j] != vec[i]) {
        cnt++;
        // flag = true;
        break;
      } else if (d > 1) {
        cnt++;
        break;
      }
    }
  }
  cout << n - cnt << endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;
typedef long long LL;

int n, a[N], ans, vis[N];

int main() {
  cin >> n;
  ans = n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    vis[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    int ok = 0;
    for (int j = 2; j <= sqrt(a[i]); j++)
      if (a[i] % j == 0)
        if (vis[a[i] / j] || vis[j]) {
          ans--;
          ok = 1;
          break;
        }
    if (!ok && (vis[a[i]] > 1 || (vis[1] && a[i] != 1)))
      ans--;
  }
  cout << ans << endl;
  return 0;
}

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

const int N = 2e6 + 5;
typedef long long LL;

int n, a[N], ans, vis[N];

int main() {
  cin >> n;
  ans = n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    vis[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    int ok = 0;
    for (int j = 2; j <= sqrt(a[i]); j++)
      if (a[i] % j == 0)
        if (vis[a[i] / j] || vis[j]) {
          ans--;
          ok = 1;
          break;
        }
    if (!ok && (vis[a[i]] > 1 || (vis[1] && a[i] != 1)))
      ans--;
  }
  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<Int, Int> P;

int main() {
  int N;
  cin >> N;
  set<int> A;
  vector<int> kosuu(100010, 0);

  rep(i, N) {
    int a;
    cin >> a;
    A.insert(a);
    kosuu[a]++;
  }

  vector<bool> flag(1000010, true);

  int ans = 0;
  for (int x : A) {
    if (!flag[x]) {
      continue;
    } else {
      int now = x;
      while (now < 1000010) {
        flag[now] = false;
        now += x;
      }
      if (kosuu[x] <= 1)
        ans++;
    }
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<Int, Int> P;

int main() {
  int N;
  cin >> N;
  set<int> A;
  vector<int> kosuu(1000010, 0);

  rep(i, N) {
    int a;
    cin >> a;
    A.insert(a);
    kosuu[a]++;
  }

  vector<bool> flag(1000010, true);

  int ans = 0;
  for (int x : A) {
    if (!flag[x]) {
      continue;
    } else {
      int now = x;
      while (now < 1000010) {
        flag[now] = false;
        now += x;
      }
      if (kosuu[x] <= 1)
        ans++;
    }
  }

  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using pint = pair<int, int>;

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

  vector<bool> era(200001, false);
  vector<int> a(n);
  vector<int> check;
  rep(i, n) {
    cin >> a[i];
    if (era[a[i]])
      check.emplace_back(a[i]);
    era[a[i]] = true;
  }
  sort(a.begin(), a.end());
  for (int i : check)
    era[i] = false;

  int ans = 0;
  for (int t : a) {
    if (era[t])
      ++ans;
    for (int i = t + t; i <= a[n - 1]; i += t)
      era[i] = false;
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using pint = pair<int, int>;

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

  vector<bool> era(1000001, false);
  vector<int> a(n);
  vector<int> check;
  rep(i, n) {
    cin >> a[i];
    if (era[a[i]])
      check.emplace_back(a[i]);
    era[a[i]] = true;
  }
  sort(a.begin(), a.end());
  for (int i : check)
    era[i] = false;

  int ans = 0;
  for (int t : a) {
    if (era[t])
      ++ans;
    for (int i = t + t; i <= a[n - 1]; i += t)
      era[i] = false;
  }

  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
#define pb push_back
#define sc(n) scanf("%d", &n)
#define lsc(n) scanf("%lld", &n)
#define all(x) x.begin(), x.end()
#define rep(i, n) for (i = 0; i < n; i++)
#define rep1(i, n) for (i = 1; i <= n; i++)
#define rev(i, n) for (i = n - 1; i >= 0; i--)
#define rev1(i, n) for (i = n; i > 0; i--)
#define in insert
#define pr(n) printf("%d\n", n)
#define lpr(n) printf("%lld\n", n);

int main() {
  ll n, i, j;
  cin >> n;
  vector<ll> v, vv;
  map<ll, ll> mp;
  map<ll, ll>::iterator it;
  ll mx = 0, mn = 1e9;
  rep(i, n) {
    ll m;
    lsc(m);
    mp[m]++;
    vv.pb(m);
    mx = max(mx, m);
    mn = min(mn, m);
  }

  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  if (mn == mx) {
    cout << 0 << endl;
    return 0;
  }
  for (it = mp.begin(); it != mp.end(); it++) {
    if ((it->second) == 1) {
      v.pb(it->first);
    }
  }
  ll sz = v.size();
  for (i = 0; i < n; i++) {
    ll k = v[i];
    for (j = (2LL * k); j <= mx; j += k) {
      if (mp[j] == 1) {
        sz--;
        mp[j] = 0;
      }
    }
  }
  cout << sz << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
#define pb push_back
#define sc(n) scanf("%d", &n)
#define lsc(n) scanf("%lld", &n)
#define all(x) x.begin(), x.end()
#define rep(i, n) for (i = 0; i < n; i++)
#define rep1(i, n) for (i = 1; i <= n; i++)
#define rev(i, n) for (i = n - 1; i >= 0; i--)
#define rev1(i, n) for (i = n; i > 0; i--)
#define in insert
#define pr(n) printf("%d\n", n)
#define lpr(n) printf("%lld\n", n);

int main() {
  ll n, i, j;
  cin >> n;
  vector<ll> v, vv;
  map<ll, ll> mp;
  map<ll, ll>::iterator it;
  ll mx = 0, mn = 1e9;
  rep(i, n) {
    ll m;
    lsc(m);
    mp[m]++;
    vv.pb(m);
    mx = max(mx, m);
    mn = min(mn, m);
  }

  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  if (mn == mx) {
    cout << 0 << endl;
    return 0;
  }
  for (it = mp.begin(); it != mp.end(); it++) {
    if ((it->second) == 1) {
      v.pb(it->first);
    }
  }
  ll sz = v.size();
  for (i = 0; i < n; i++) {
    ll k = vv[i];
    for (j = (2LL * k); j <= mx; j += k) {
      if (mp[j] == 1) {
        sz--;
        mp[j] = 0;
      }
    }
  }
  cout << sz << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

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

void solve(ll N, vector<ll> A) {
  sort(A.begin(), A.end());

  vector<bool> prime(A.back(), false);
  REP(i, N)
  prime[A[i]] = true;

  REP(i, N) {

    if (!prime[A[i]])
      continue;

    if (i < N - 1 && A[i] == A[i + 1])
      prime[A[i]] = false;

    FOR(j, 2, A.back() / A[i] + 1)
    prime[A[i] * j] = false;
  }

  ll ans(0);
  REP(i, N) {
    if (prime[A[i]])
      ans++;
  }
  cout << ans << endl;
}

int main() {
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) { cin >> A[i]; }

  solve(N, move(A));

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

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

void solve(ll N, vector<ll> A) {
  sort(A.begin(), A.end());

  vector<bool> prime(A.back() + 1, false);
  REP(i, N)
  prime[A[i]] = true;

  REP(i, N) {

    if (!prime[A[i]])
      continue;

    if (i < N - 1 && A[i] == A[i + 1])
      prime[A[i]] = false;

    FOR(j, 2, A.back() / A[i] + 1)
    prime[A[i] * j] = false;
  }

  ll ans(0);
  REP(i, N) {
    if (prime[A[i]])
      ans++;
  }
  cout << ans << endl;
}

int main() {
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) { cin >> A[i]; }

  solve(N, move(A));

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define ll long long
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define f first
#define s second
using namespace std;
const int N = 1e3 + 2;
const int M = 1e8;
int cnt[N];
int a[N];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    x = a[i];
    cnt[x]++;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ll how = 0;
    cnt[a[i]]--;
    for (int j = 1; j * j <= a[i]; j++) {
      if (a[i] % j)
        continue;
      if (j * j == x) {
        how += cnt[j];
      } else {
        how += cnt[j];
        how += cnt[a[i] / j];
      }
    }
    ans += (how == 0);
    cnt[a[i]]++;
    // cout<<how<<" ";
  }
  //    ll ans1=0;
  //    for(int i=0;i<n;i++){
  //        bool ok=1;
  //        for(int j=0;j<n;j++){
  //            if(i==j) continue;
  //            if(a[j]%a[i]==0){
  //                ok=0;
  //                break;
  //            }
  //        }
  //        ans1+=ok;
  //    }
  cout << ans;
  return 0;
}
// abcd


Fixed submission:
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define ll long long
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define f first
#define s second
using namespace std;
const int N = 1e6 + 2;
const int M = 1e8;
int cnt[N];
int a[N];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    x = a[i];
    cnt[x]++;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ll how = 0;
    cnt[a[i]]--;
    for (int j = 1; j * j <= a[i]; j++) {
      if (a[i] % j)
        continue;
      if (j * j == x) {
        how += cnt[j];
      } else {
        how += cnt[j];
        how += cnt[a[i] / j];
      }
    }
    ans += (how == 0);
    cnt[a[i]]++;
    // cout<<how<<" ";
  }
  //    ll ans1=0;
  //    for(int i=0;i<n;i++){
  //        bool ok=1;
  //        for(int j=0;j<n;j++){
  //            if(i==j) continue;
  //            if(a[j]%a[i]==0){
  //                ok=0;
  //                break;
  //            }
  //        }
  //        ans1+=ok;
  //    }
  cout << ans;
  return 0;
}
// abcd