prithivMLmods/Coder-Stat huggingface dataset:
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 < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  long n;
  cin >> n;
  vector<long> a(n);
  map<long, long> b;
  vector<long> c[1001001];
  rep(i, n) {
    cin >> a.at(i);
    b[a.at(i)]++;
    for (long j = 1; j * j <= a.at(i); j++) {
      if (a.at(i) % j == 0) {
        c[i].push_back(j);
        c[i].push_back(a.at(i) / j);
      }
    }
  }
  int ans = 0;
  rep(i, n) {
    bool ex = true;
    rep(j, c[i].size()) {
      if ((c[i].at(j) != a.at(i) && b[c[i].at(j)] > 0) ||
          (c[i].at(j) == a.at(i) && b[c[i].at(j)] > 1)) {
        ex = false;
      }
    }
    if (ex) {
      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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  long n;
  cin >> n;
  vector<long> a(n);
  vector<long> b(1001001);
  vector<long> c[1001001];
  rep(i, n) {
    cin >> a.at(i);
    b[a.at(i)]++;
    for (long j = 1; j * j <= a.at(i); j++) {
      if (a.at(i) % j == 0) {
        c[i].push_back(j);
        c[i].push_back(a.at(i) / j);
      }
    }
  }
  int ans = 0;
  rep(i, n) {
    bool ex = true;
    rep(j, c[i].size()) {
      if ((c[i].at(j) != a.at(i) && b[c[i].at(j)] > 0) ||
          (c[i].at(j) == a.at(i) && b[c[i].at(j)] > 1)) {
        ex = false;
      }
    }
    if (ex) {
      ans++;
    }
  }

  cout << ans << endl;
}
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++)
typedef long long int ll;
typedef pair<int, int> P;

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

  int max_a = 202020;
  vector<int> s(max_a * 2, 0);

  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  rep(i, n) s[a[i]] = 1;
  rep(i, n - 1) if (a[i] == a[i + 1]) s[a[i]] = 2;

  for (int i = 1; i <= max_a; i++) {
    if (s[i] == 0)
      continue;
    for (int j = i + i; j <= max_a; j += i) {
      if (s[j] == 1)
        s[j] = 2;
    }
  }

  int ans = 0;
  for (int i = 0; i <= max_a; i++) {
    if (s[i] == 1)
      ans++;
  }

  cout << ans << endl;

  return 0;
}

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

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

  int max_a = 2020202;
  vector<int> s(max_a * 2, 0);

  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  rep(i, n) s[a[i]] = 1;
  rep(i, n - 1) if (a[i] == a[i + 1]) s[a[i]] = 2;

  for (int i = 1; i <= max_a; i++) {
    if (s[i] == 0)
      continue;
    for (int j = i + i; j <= max_a; j += i) {
      if (s[j] == 1)
        s[j] = 2;
    }
  }

  int ans = 0;
  for (int i = 0; i <= max_a; i++) {
    if (s[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++)
typedef long long int ll;
typedef pair<int, int> P;

int main() {
  int n;
  cin >> n;
  int MAX_A = 202020;
  vector<int> a(MAX_A + 1, 0);
  rep(i, n) {
    int t;
    cin >> t;
    a[t]++;
  }
  for (int i = 1; i <= MAX_A; i++) {
    if (a[i] == 0)
      continue;
    for (int j = i + i; j <= MAX_A; j += i) {
      a[j] = 2;
    }
  }
  int ans = 0;
  for (int i = 1; i <= MAX_A; i++) {
    if (a[i] == 1)
      ans++;
  }
  cout << ans << endl;

  return 0;
}

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

int main() {
  int n;
  cin >> n;
  int MAX_A = 2020202;
  vector<int> a(MAX_A + 1, 0);
  rep(i, n) {
    int t;
    cin >> t;
    a[t]++;
  }
  for (int i = 1; i <= MAX_A; i++) {
    if (a[i] == 0)
      continue;
    for (int j = i + i; j <= MAX_A; j += i) {
      a[j] = 2;
    }
  }
  int ans = 0;
  for (int i = 1; i <= MAX_A; i++) {
    if (a[i] == 1)
      ans++;
  }
  cout << ans << endl;

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define join(a, d)                                                             \
  accumulate(a.begin() + 1, a.end(), a[0],                                     \
             [](string s, string t) { return s + d + t; })
#define all(a) a.begin(), a.end()
// #define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, 0, N) cin >> A[i];
  vector<int> nums(1000001, 0);
  rep(i, 0, N) {
    int j = 1;
    int n = A[i];
    while (n <= 1000000) {
      nums[n] += j;
      ++j;
      n = A[i] * j;
    }
  }
  int ans = 0;
  rep(i, 0, N) {
    if (nums[A[i]] < 2) {
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define join(a, d)                                                             \
  accumulate(a.begin() + 1, a.end(), a[0],                                     \
             [](string s, string t) { return s + d + t; })
#define all(a) a.begin(), a.end()
// #define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, 0, N) cin >> A[i];
  vector<int> nums(1000001, 0);
  rep(i, 0, N) {
    int j = 1;
    int n = A[i];
    while (n <= 1000000) {
      nums[n] += 1;
      if (j == 1 && nums[n] > 1)
        break;
      ++j;
      n = A[i] * j;
    }
  }
  int ans = 0;
  rep(i, 0, N) {
    if (nums[A[i]] < 2) {
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

int main() {

  int N;
  cin >> N;
  vector<int> a(N);

  vector<int> cnt(212345);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  int ans = N;

  for (int i = 0; i < N; i++) {
    if (cnt[a[i]] > 1 || (a[i] != 1 && cnt[1] > 0)) {
      ans--;
      continue;
    }
    for (int j = 2; j * j <= a[i]; j++) {
      if (a[i] % j == 0 && (cnt[a[i] / j] > 0 || cnt[j] > 0)) {
        ans--;
        break;
      }
    }
  }

  cout << ans << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

int main() {

  int N;
  cin >> N;
  vector<int> a(N);

  vector<int> cnt(2123456);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  int ans = N;

  for (int i = 0; i < N; i++) {
    if (cnt[a[i]] > 1 || (a[i] != 1 && cnt[1] > 0)) {
      ans--;
      continue;
    }
    for (int j = 2; j * j <= a[i]; j++) {
      if (a[i] % j == 0 && (cnt[a[i] / j] > 0 || cnt[j] > 0)) {
        ans--;
        break;
      }
    }
  }

  cout << ans << "\n";
}
Problem p02642 (C++)

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define EPS (1e-9)
#define equals(a, b) (fabs((a) - (b)) < EPS)

using namespace std;

bool LT(double a, double b) { return !equals(a, b) && a < b; }
bool LTE(double a, double b) { return equals(a, b) || a < b; }

const string YES = "";
const string NO = "";

typedef long long ll;
typedef pair<int, int> ii;

int n;
vector<ll> A;

const int MAX = 2000000;

vector<int> prime;
bool isntprime[MAX + 1];

void solve() {
  map<int, int> mp;
  rep(i, n) mp[A[i]]++;
  set<int> BAN;
  for (auto tmp : mp) {
    if (tmp.snd != 1) {
      BAN.insert(tmp.fst);
    }
  }
  sort(ALL(A));
  int cnt = 0;
  int j;
  rep(id, (int)A.size()) {
    int i = A[id];
    if (!isntprime[i]) {
      if (!BAN.count(i)) {
        ++cnt;
      }
      for (j = 2 * i; j <= MAX; j += i)
        isntprime[j] = true;
    }
  }
  cout << cnt << endl;
}

int main() {
  cin >> n;
  A.resize(n);
  rep(i, n) cin >> A[i];
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define EPS (1e-9)
#define equals(a, b) (fabs((a) - (b)) < EPS)

using namespace std;

bool LT(double a, double b) { return !equals(a, b) && a < b; }
bool LTE(double a, double b) { return equals(a, b) || a < b; }

const string YES = "";
const string NO = "";

typedef long long ll;
typedef pair<int, int> ii;

int n;
vector<ll> A;

const int MAX = 2000000;

vector<int> prime;
bool isntprime[MAX + 1];

void solve() {
  map<int, int> mp;
  rep(i, n) mp[A[i]]++;
  set<int> BAN;
  for (auto tmp : mp) {
    if (tmp.snd != 1) {
      BAN.insert(tmp.fst);
    }
  }
  sort(ALL(A));
  A.erase(unique(ALL(A)), A.end());
  int cnt = 0;
  int j;
  rep(id, (int)A.size()) {
    int i = A[id];
    if (!isntprime[i]) {
      if (!BAN.count(i)) {
        ++cnt;
      }
      for (j = 2 * i; j <= MAX; j += i)
        isntprime[j] = true;
    }
  }
  cout << cnt << endl;
}

int main() {
  cin >> n;
  A.resize(n);
  rep(i, n) cin >> A[i];
  solve();
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main(void) {
  int n;
  int A[200002];
  bool B[1000002] = {
      0,
  };
  bool check[1000002] = {
      0,
  };

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    if (check[A[i]] == false)
      check[A[i]] = true;
    else
      B[A[i]] = true;
    for (int j = 2; j <= 1000002 / A[i]; j++)
      B[j * A[i]] = true;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (B[A[i]] == false)
      cnt++;

  cout << cnt;

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main(void) {
  int n;
  int A[200002];
  bool B[1000002] = {
      0,
  };
  bool check[1000002] = {
      0,
  };

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    if (check[A[i]] == false)
      check[A[i]] = true;
    else
      B[A[i]] = true;
    if (B[A[i]] != true)
      for (int j = 2; j <= 1000002 / A[i]; j++)
        B[j * A[i]] = true;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (B[A[i]] == false)
      cnt++;

  cout << cnt;

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < n; i++)
#define Rep(i, n) for (long long i = 1; i < n; i++)
#define ll long long
#include <cmath>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define PI acos(-1)
using P = pair<int, int>;

ll ketasu(ll a) {
  ll num = 1;
  while (a / 10) {
    num++;
    a /= 10;
  }
  return num;
}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

ll kosuu(ll a) {
  ll sum = 0;
  for (ll i = 1; i * i <= a; i++) {
    if (a % i == 0) {
      if (a != 1 && i * i != a) {
        sum += 2;
      } else {
        sum++;
      }
    }
  }
  return sum;
}
ll M = 1000005;

int main() {
  ll n;
  cin >> n;
  vector<ll> cnt(M);
  vector<ll> s(n);
  rep(i, n) { cin >> s[i]; }
  for (ll x : s) {
    if (cnt[x] != 0) {
      cnt[x] = 2;
    }
    for (ll i = x; i < M; i += x)
      cnt[i]++;
  }

  ll ans = 0;
  for (ll x : s) {
    if (cnt[x] == 1)
      ans++;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < n; i++)
#define Rep(i, n) for (long long i = 1; i < n; i++)
#define ll long long
#include <cmath>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define PI acos(-1)
using P = pair<int, int>;

ll ketasu(ll a) {
  ll num = 1;
  while (a / 10) {
    num++;
    a /= 10;
  }
  return num;
}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

ll kosuu(ll a) {
  ll sum = 0;
  for (ll i = 1; i * i <= a; i++) {
    if (a % i == 0) {
      if (a != 1 && i * i != a) {
        sum += 2;
      } else {
        sum++;
      }
    }
  }
  return sum;
}
ll M = 1000005;

int main() {
  ll n;
  cin >> n;
  vector<ll> cnt(M);
  vector<ll> s(n);
  rep(i, n) { cin >> s[i]; }
  for (ll x : s) {
    if (cnt[x] != 0) {
      cnt[x] = 2;
      continue;
    }
    for (ll i = x; i < M; i += x)
      cnt[i]++;
  }

  ll ans = 0;
  for (ll x : s) {
    if (cnt[x] == 1)
      ans++;
  }
  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MAX = 200100;
int main() {
  ll N;
  cin >> N;
  vector<int> A(N);
  for (ll i = 0; i < N; i++)
    cin >> A[i];
  vector<int> M(MAX, 0);
  for (auto a : A) {
    if (M[a] != 0) {
      M[a] = 2;
      continue;
    }
    for (ll i = a; i <= MAX; i += a)
      M[i]++;
  }
  ll ans = 0;
  for (auto a : A) {
    if (M[a] == 1)
      ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MAX = 2001000;
int main() {
  ll N;
  cin >> N;
  vector<int> A(N);
  for (ll i = 0; i < N; i++)
    cin >> A[i];
  vector<int> M(MAX, 0);
  for (auto a : A) {
    if (M[a] != 0) {
      M[a] = 2;
      continue;
    }
    for (ll i = a; i <= MAX; i += a)
      M[i]++;
  }
  ll ans = 0;
  for (auto a : A) {
    if (M[a] == 1)
      ans++;
  }
  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <vector>

typedef long long ll;

int main() {
  ll N;
  std::cin >> N;
  std::vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  std::vector<ll> B(1000010);
  for (auto r : A) {
    for (int x = r; x < 1000010; x += r) {
      B[x]++;
    }
  }
  ll resa = 0;
  for (auto it = A.begin(); it != A.end(); it++) {
    if (B[*it] == 1)
      resa++;
  }
  std::cout << resa << std::endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>

typedef long long ll;

int main() {
  ll N;
  std::cin >> N;
  std::vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  std::vector<ll> B(1000010);
  for (auto r : A) {
    if (B[r] != 0) {
      B[r] = 2;
      continue;
    }
    for (int x = r; x < 1000010; x += r) {
      B[x]++;
    }
  }
  ll resa = 0;
  for (auto it = A.begin(); it != A.end(); it++) {
    if (B[*it] == 1)
      resa++;
  }
  std::cout << resa << std::endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
// constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T> void remove(std::vector<T> &vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll, ll, ll>>>;

// MOD確認

ll N;
ll A[200010];
bool B[200010];

int main() {
  cin >> N;
  rep(i, N) cin >> A[i];
  sort(A, A + N);
  ll ans = 0;
  rep(i, N) {
    if (!B[A[i]] && A[i + 1] != A[i])
      ans++;
    for (ll j = 1; j * A[i] <= A[N - 1]; j++) {
      B[A[i] * j] = 1;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
// constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T> void remove(std::vector<T> &vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll, ll, ll>>>;

// MOD確認

ll N;
ll A[200010];
bool B[2000010];

int main() {
  cin >> N;
  rep(i, N) cin >> A[i];
  sort(A, A + N);
  ll ans = 0;
  rep(i, N) {
    if (!B[A[i]] && A[i + 1] != A[i])
      ans++;
    for (ll j = 1; j * A[i] <= A[N - 1]; j++) {
      B[A[i] * j] = 1;
    }
  }
  cout << ans << endl;
}
Problem p02642 (C++)

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

const int maxn = 1e6 + 10;
int vis[maxn];

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 1; j * a[i] < maxn; j++) {
      vis[a[i] * j]++;
    }
  }

  int res = 0;
  for (int i = 0; i < n; i++) {
    if (vis[a[i]] == 1) {
      res++;
    }
  }
  cout << res << endl;
}

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

const int maxn = 1e6 + 10;
int vis[maxn];

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (vis[a[i]]) {
      vis[a[i]]++;
      continue;
    }
    for (int j = 1; j * a[i] < maxn; j++) {
      vis[a[i] * j]++;
    }
  }

  int res = 0;
  for (int i = 0; i < n; i++) {
    if (vis[a[i]] == 1) {
      res++;
    }
  }
  cout << res << endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <time.h>
#define F(i, a, b) for (long long i = a; i <= (b); ++i)
#define dF(i, a, b) for (long long i = a; i >= (b); --i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
const int mods = 1e9 + 7;
const int maxn = 2e5 + 10;
const int N = 1e5 + 10;
const int E = 1e6 + 10;
int x, n;
int vis[maxn];
int a[maxn];

int main() {
  cin >> n;
  F(i, 1, n) {
    scanf("%d", &a[i]);
    vis[a[i]]++;
  }
  int ans = n;
  F(i, 1, n) {
    if (vis[a[i]] > 1) {
      ans--;
      continue;
    } else {
      vis[a[i]]--;
      F(j, 1, floor((double)sqrt(a[i]))) {
        if (a[i] % j == 0) {
          if (vis[j]) {
            //	cout<<i<<" "<<j<<endl;
            ans--;
            break;
          } else if (vis[a[i] / j]) {
            //	cout<<i<<" "<<j<<endl;
            ans--;
            break;
          }
        }
      }
      vis[a[i]]++;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#include <time.h>
#define F(i, a, b) for (long long i = a; i <= (b); ++i)
#define dF(i, a, b) for (long long i = a; i >= (b); --i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
const int mods = 1e9 + 7;
const int maxn = 1e6 + 10;
const int N = 1e5 + 10;
const int E = 1e6 + 10;
int x, n;
int vis[maxn];
int a[maxn];

int main() {
  cin >> n;
  F(i, 1, n) {
    scanf("%d", &a[i]);
    vis[a[i]]++;
  }
  int ans = n;
  F(i, 1, n) {
    if (vis[a[i]] > 1) {
      ans--;
      continue;
    } else {
      vis[a[i]]--;
      F(j, 1, floor((double)sqrt(a[i]))) {
        if (a[i] % j == 0) {
          if (vis[j]) {
            //	cout<<i<<" "<<j<<endl;
            ans--;
            break;
          } else if (vis[a[i] / j]) {
            //	cout<<i<<" "<<j<<endl;
            ans--;
            break;
          }
        }
      }
      vis[a[i]]++;
    }
  }
  cout << ans << endl;
}
Problem p02642 (C++)

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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  // int mx = (int)1e6 + 1;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int mx = *max_element(a.begin(), a.end());
  vector<int> cnt(mx + 1);
  for (int i = 0; i < n; i++) {
    cnt[a[i]]++;
  }
  vector<bool> ok(mx, 1);
  for (int i = 0; i < n; i++) {
    if (cnt[a[i]] != 0) {
      for (int j = a[i] + a[i]; j <= mx; j += a[i]) {
        ok[j] = 0;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (cnt[a[i]] == 1 && ok[a[i]]) {
      ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  // int mx = (int)1e6 + 1;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int mx = *max_element(a.begin(), a.end());
  vector<int> cnt(mx + 1);
  for (int i = 0; i < n; i++) {
    cnt[a[i]]++;
  }
  vector<bool> ok(mx + 1, 1);
  for (int i = 0; i < n; i++) {
    if (cnt[a[i]] != 0) {
      for (int j = a[i] + a[i]; j <= mx; j += a[i]) {
        ok[j] = 0;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (cnt[a[i]] == 1 && ok[a[i]]) {
      ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 998244353;
vector<ll> ans;

ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }

ll multiply(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }

ll power(ll a, ll b) {
  if (b == 0)
    return 1;
  ll temp = power(a, b / 2);
  if (b % 2 == 1)
    return multiply(temp, multiply(temp, a));
  else
    return multiply(temp, temp);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n;
  cin >> n;
  map<ll, ll> s;
  vector<ll> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    s[v[i]]++;
  }
  ll c = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    c = 0;
    for (int j = 1; j <= sqrt(v[i]); j++) {
      if ((v[i] % j) == 0) {
        if (s.find(j) != s.end()) {
          c += s[j];
        }
        if ((v[i] / j) != j && s.find(v[i] / j) != s.end()) {
          c += s[v[i] / j];
        }
      }
    }
    if (c == 1) {
      ans++;
    }
  }
  cout << ans << "\n";
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 998244353;
vector<ll> ans;

ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }

ll multiply(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }

ll power(ll a, ll b) {
  if (b == 0)
    return 1;
  ll temp = power(a, b / 2);
  if (b % 2 == 1)
    return multiply(temp, multiply(temp, a));
  else
    return multiply(temp, temp);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n;
  cin >> n;
  unordered_map<ll, ll> s;
  vector<ll> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    s[v[i]]++;
  }
  ll c = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    c = 0;
    for (int j = 1; j <= sqrt(v[i]); j++) {
      if ((v[i] % j) == 0) {
        if (s.find(j) != s.end()) {
          c += s[j];
        }
        if ((v[i] / j) != j && s.find(v[i] / j) != s.end()) {
          c += s[v[i] / j];
        }
      }
    }
    if (c == 1) {
      ans++;
    }
  }
  cout << ans << "\n";
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
 * D.cpp
 *
 *  Created on: 2020/06/14
 *      Author: admin
 */

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
using namespace std;

int main() {
  long long N;
  cin >> N;
  long long A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  bool dp[1000010];
  for (int i = 0; i < 1000010; i++)
    dp[i] = true;

  sort(A, A + SIZE_OF_ARRAY(A));

  long long count = 0;
  for (int i = 0; i < N; i++) {
    if (i < N - 1) {
      if (A[i] == A[i + 1]) {
        for (long long m = 1; A[i] * m < 1000010; m++) {
          dp[A[i] * m] = false;
        }
      }
    }
    if (dp[A[i]]) {
      count++;
      for (long long m = 1; A[i] * m < 1000010; m++) {
        dp[A[i] * m] = false;
      }
    }
  }
  cout << count;
}


Fixed submission:
/*
 * D.cpp
 *
 *  Created on: 2020/06/14
 *      Author: admin
 */

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
using namespace std;

int main() {
  long long N;
  cin >> N;
  long long A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  bool dp[1000010];
  for (int i = 0; i < 1000010; i++)
    dp[i] = true;

  sort(A, A + SIZE_OF_ARRAY(A));

  long long count = 0;
  for (int i = 0; i < N; i++) {
    if (dp[A[i]]) {
      if (i < N - 1) {
        if (A[i] == A[i + 1]) {
          for (long long m = 1; A[i] * m < 1000010; m++) {
            dp[A[i] * m] = false;
          }
        }
      }
    }
    if (dp[A[i]]) {
      count++;
      for (long long m = 1; A[i] * m < 1000010; m++) {
        dp[A[i] * m] = false;
      }
    }
  }
  cout << count;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>

int main() {
  int N;
  scanf("%d", &N);
  std::vector<int> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  // printf("read\n");
  std::sort(A.begin(), A.end());
  std::vector<int> count(1000004, 0);
  for (int i = 0; i < N; i++) {
    // printf("i=%d\n", i);
    for (int j = A[i]; j < 1000004; j += A[i]) {
      count[j]++;
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (count[A[i]] == 1)
      ans++;
  }
  std::cout << ans << std::endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>

int main() {
  int N;
  scanf("%d", &N);
  std::vector<int> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  // printf("read\n");
  std::sort(A.begin(), A.end());
  std::vector<int> count(1000004, 0);
  for (int i = 0; i < N; i++) {
    // printf("i=%d\n", i);
    if (count[A[i]] > 0) {
      count[A[i]]++;
      continue;
    }
    for (int j = A[i]; j < 1000004; j += A[i]) {
      count[j]++;
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (count[A[i]] == 1)
      ans++;
  }
  std::cout << ans << std::endl;
  return 0;
}
Problem p02642 (C++)

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

int a[111111], b[1111111];
int main() {
  int n, c = 0;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    if (b[a[i]] > 1)
      c--, b[a[i]]--;
    if (b[a[i]])
      continue;
    for (int j = a[i]; j < 1111111; j += a[i])
      b[j] = 1;
    b[a[i]]++;
    c++;
  }
  cout << c << endl;
  return 0;
}


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

int a[222222], b[1111111];
int main() {
  int n, c = 0;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    if (b[a[i]] > 1)
      c--, b[a[i]]--;
    if (b[a[i]])
      continue;
    for (int j = a[i]; j < 1111111; j += a[i])
      b[j] = 1;
    b[a[i]]++;
    c++;
  }
  cout << c << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <stack>
#include <vector>

#define MAX_N 90

using namespace std;

bool criba[MAX_N + 1];
int ocurrences[MAX_N + 1];

int main() {
  int N, i, A, j, counter;

  scanf("%d", &N);
  memset(ocurrences, 0, sizeof ocurrences);
  for (i = 0; i < N; ++i) {
    scanf("%d", &A);
    ++ocurrences[A];
  }

  memset(criba, 0, sizeof criba);
  for (i = 1; i <= MAX_N; ++i)
    if (ocurrences[i]) {
      j = (ocurrences[i] > 1) ? i : 2 * i;

      while (j <= MAX_N) {
        if (ocurrences[j])
          criba[j] = true;
        j += i;
      }
    }

  counter = 0;
  for (i = 0; i <= MAX_N; ++i)
    if (!criba[i])
      counter += ocurrences[i];
  printf("%d", counter);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <stack>
#include <vector>

#define MAX_N 1000000

using namespace std;

bool criba[MAX_N + 1];
int ocurrences[MAX_N + 1];

int main() {
  int N, i, A, j, counter;

  scanf("%d", &N);
  memset(ocurrences, 0, sizeof ocurrences);
  for (i = 0; i < N; ++i) {
    scanf("%d", &A);
    ++ocurrences[A];
  }

  memset(criba, 0, sizeof criba);
  for (i = 1; i <= MAX_N; ++i)
    if (ocurrences[i]) {
      j = (ocurrences[i] > 1) ? i : 2 * i;

      while (j <= MAX_N) {
        if (ocurrences[j])
          criba[j] = true;
        j += i;
      }
    }

  counter = 0;
  for (i = 0; i <= MAX_N; ++i)
    if (!criba[i])
      counter += ocurrences[i];
  printf("%d", counter);

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  int n, tmp;
  cin >> n;
  int count_a[11] = {0};
  int a_max = -1;
  vector<int> b;
  int count = 0;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    count_a[tmp]++;
    if (a_max < tmp) {
      a_max = tmp;
    }
  }

  if (count_a[1] > 1) {
    cout << 0 << endl;
    return 0;
  }
  /*
  for(int i= 1;i <= a_max;i++){
      if(count_a[i] == 1){
          b.push_back(i);
      }
  }
  */

  int blength = b.size();
  bool dp[a_max + 1];
  for (int i = 0; i < a_max + 1; i++) {
    dp[i] = true;
  }

  for (int i = 1; i <= a_max; i++) {
    if (count_a[i] >= 1) {
      tmp = i;
      for (int j = tmp + tmp; j <= a_max; j += tmp) {
        dp[j] = false;
      }
    }
  }

  for (int i = 1; i <= a_max; i++) {
    if (count_a[i] == 1) {
      tmp = i;
      if (dp[tmp]) {
        count++;
      }
    }
  }

  cout << count << endl;
  return 0;
}

/*
5
24 11 8 3 16

4
5 5 5 5

10
33 18 45 28 8 19 89 86 2 4
*/

Fixed submission:
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  int n, tmp;
  cin >> n;
  int count_a[1000001] = {0};
  int a_max = -1;
  vector<int> b;
  int count = 0;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    count_a[tmp]++;
    if (a_max < tmp) {
      a_max = tmp;
    }
  }

  if (count_a[1] > 1) {
    cout << 0 << endl;
    return 0;
  }
  /*
  for(int i= 1;i <= a_max;i++){
      if(count_a[i] == 1){
          b.push_back(i);
      }
  }
  */

  int blength = b.size();
  bool dp[a_max + 1];
  for (int i = 0; i < a_max + 1; i++) {
    dp[i] = true;
  }

  for (int i = 1; i <= a_max; i++) {
    if (count_a[i] >= 1) {
      tmp = i;
      for (int j = tmp + tmp; j <= a_max; j += tmp) {
        dp[j] = false;
      }
    }
  }

  for (int i = 1; i <= a_max; i++) {
    if (count_a[i] == 1) {
      tmp = i;
      if (dp[tmp]) {
        count++;
      }
    }
  }

  cout << count << endl;
  return 0;
}

/*
5
24 11 8 3 16

4
5 5 5 5

10
33 18 45 28 8 19 89 86 2 4
*/
Problem p02642 (C++)

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

UL C[1000001] = {};
UL N;
UL A[200000];

int main() {
  scanf("%u", &N);
  rep(i, N) scanf("%u", A + i);
  sort(A, A + N);
  UL ans = 0;
  rep(i, N) {
    C[A[i]]++;
    if (!C[A[i]])
      continue;
    for (UL j = A[i] + A[i]; j <= 1000000; j += A[i])
      C[j]++;
  }
  rep(i, N) if (C[A[i]] <= 1) ans++;
  printf("%u", ans);

  return 0;
}


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

UL C[1000001] = {};
UL N;
UL A[200000];

int main() {
  scanf("%u", &N);
  rep(i, N) scanf("%u", A + i);
  sort(A, A + N);
  UL ans = 0;
  rep(i, N) {
    C[A[i]]++;
    if (C[A[i]] > 1)
      continue;
    for (UL j = A[i] + A[i]; j <= 1000000; j += A[i])
      C[j]++;
  }
  rep(i, N) if (C[A[i]] <= 1) ans++;
  printf("%u", ans);

  return 0;
}
Problem p02642 (C++)

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

#define lol long long
#define gcd(x, y) __gcd(x, y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed << setprecision(14)
using namespace std;
using pii = pair<int, int>;
template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a && (a = b, true);
}
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
const lol inf = (1LL << 60);
const lol MOD = (1e9) + 7;
const lol mod = 998244353;
const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
lol n, m, k, r, q;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  vector<int> a(n + 1, 0);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end() - 1);
  lol ma = a[n - 1];
  vector<int> dp(ma + 1, 0);
  lol ans = 0;
  for (int i = 0; i < n; i++) {
    if (dp[a[i]] == 0) {

      if (a[i] != a[i + 1])
        ans++;
      for (int j = a[i]; j <= 1000000; j += a[i])
        dp[j]++;
    }
  }
  cout << ans << '\n';
  return (0);
}


Fixed submission:
#include <bits/stdc++.h>

#define lol long long
#define gcd(x, y) __gcd(x, y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed << setprecision(14)
using namespace std;
using pii = pair<int, int>;
template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a && (a = b, true);
}
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
const lol inf = (1LL << 60);
const lol MOD = (1e9) + 7;
const lol mod = 998244353;
const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
lol n, m, k, r, q;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  vector<int> a(n + 1, 0);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end() - 1);
  lol ma = a[n - 1];
  vector<int> dp(1000000 + 1, 0);
  lol ans = 0;
  for (int i = 0; i < n; i++) {
    if (dp[a[i]] == 0) {

      if (a[i] != a[i + 1])
        ans++;
      for (int j = a[i]; j <= 1000000; j += a[i])
        dp[j]++;
    }
  }
  cout << ans << '\n';
  return (0);
}
Problem p02642 (C++)

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

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

#define rep(i, cc, n) for (int i = cc; i < n; ++i)
#define lrep(i, cc, n) for (long long i = cc; i < n; ++i)
#define sqrep(i, cc, n) for (long long i = cc; i * i <= n; ++i)
#define rrep(i, cc, n) for (long i = cc; i > n; --i)
#define pii pair<int, int>
#define pll pair<long long, long long>

using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9 = 1000000000;
const ll mod = 1000000007;

ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
int main() {
  vector<bool> ans(200200, true);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());
  rep(i, 0, n) {
    int p = a[i];
    if (i == 0)
      for (int j = 2 * p; j <= a[0]; j += p)
        ans[j] = false;
    else {
      if (a[i] == a[i - 1])
        for (int j = p; j <= a[0]; j += p)
          ans[j] = false;
      else
        for (int j = 2 * p; j <= a[0]; j += p)
          ans[j] = false;
    }
  }
  int cnt = 0;
  rep(i, 0, n) {
    if (ans[a[i]])
      cnt++;
  }
  cout << cnt << endl;
}

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

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

#define rep(i, cc, n) for (int i = cc; i < n; ++i)
#define lrep(i, cc, n) for (long long i = cc; i < n; ++i)
#define sqrep(i, cc, n) for (long long i = cc; i * i <= n; ++i)
#define rrep(i, cc, n) for (long i = cc; i > n; --i)
#define pii pair<int, int>
#define pll pair<long long, long long>

using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9 = 1000000000;
const ll mod = 1000000007;

ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
int main() {
  vector<bool> ans(2002000, true);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());
  rep(i, 0, n) {
    int p = a[i];
    if (i == 0)
      for (int j = 2 * p; j <= a[0]; j += p)
        ans[j] = false;
    else {
      if (a[i] == a[i - 1])
        for (int j = p; j <= a[0]; j += p)
          ans[j] = false;
      else
        for (int j = 2 * p; j <= a[0]; j += p)
          ans[j] = false;
    }
  }
  int cnt = 0;
  rep(i, 0, n) {
    if (ans[a[i]])
      cnt++;
  }
  cout << cnt << endl;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define A_MAX 2000100
bool dp[A_MAX];

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  sort(A.begin(), A.end());

  fill(dp, dp + A_MAX, true);
  for (int i = N - 1; i >= 0; i--) {
    if (i < N - 1 && A[i + 1] == A[i])
      dp[A[i]] = false;
    int tmp = 2 * A[i];
    while (tmp <= A_MAX) {
      dp[tmp] = false;
      tmp += A[i];
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (dp[A[i]])
      ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define A_MAX 2000100
bool dp[A_MAX];

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  sort(A.begin(), A.end());

  fill(dp, dp + A_MAX, true);
  for (int i = 0; i < N; i++) {
    if (!dp[A[i]])
      continue;
    if (i > 0 && A[i - 1] == A[i])
      dp[A[i]] = false;
    int tmp = 2 * A[i];
    while (tmp <= A_MAX) {
      dp[tmp] = false;
      tmp += A[i];
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (dp[A[i]])
      ans++;
  }
  cout << ans << endl;
}
Problem p02642 (C++)

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

template <typename T> void print_vector(vector<T> &vec) {
  cout << "print_vector -> ";
  for (int i = 0; i < vec.size(); i++) {
    if (i == vec.size() - 1) {
      cout << vec[i] << endl;
    } else {
      cout << vec[i] << " ";
    }
  }
  return;
}

vector<int> v;

void solve(int n) {
  if (n <= 1)
    return;
  int l = sqrt(n);
  for (int i = 2; i <= l; i++) {
    if (n % i == 0) {
      solve(i);
      solve((int)(n / i));
      return;
    }
  }
  v.push_back(n);
  return;
}

int main() {

  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];

  vector<int> map(1000010, 0);

  for (int i = 0; i < N; i++) {
    if (map[A[i]] == 1) {
      map[A[i]]++;
      continue;
    }
    for (int j = A[i]; j < 1000010; j += A[i]) {
      map[j]++;
    }
  }

  int ans = 0;
  for (int a : A) {
    if (map[a] == 1)
      ans++;
  }
  cout << ans << endl;

  return 0;
}

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

template <typename T> void print_vector(vector<T> &vec) {
  cout << "print_vector -> ";
  for (int i = 0; i < vec.size(); i++) {
    if (i == vec.size() - 1) {
      cout << vec[i] << endl;
    } else {
      cout << vec[i] << " ";
    }
  }
  return;
}

vector<int> v;

void solve(int n) {
  if (n <= 1)
    return;
  int l = sqrt(n);
  for (int i = 2; i <= l; i++) {
    if (n % i == 0) {
      solve(i);
      solve((int)(n / i));
      return;
    }
  }
  v.push_back(n);
  return;
}

int main() {

  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];

  vector<int> map(1000010, 0);

  for (int i = 0; i < N; i++) {
    if (map[A[i]] >= 1) {
      map[A[i]]++;
      continue;
    }
    for (int j = A[i]; j < 1000010; j += A[i]) {
      map[j]++;
    }
  }

  int ans = 0;
  for (int a : A) {
    if (map[a] == 1)
      ans++;
  }
  cout << ans << endl;

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace std;
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db double
#define eps 1e-8
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
const ll mod = 1e9 + 9;
const ll maxn = 2e5 + 10;
const ll mxe = 1e6 + 10;
bool divided[mxe];
vector<int> arr;
map<int, int> occ;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  arr.resize(n);
  for (auto &i : arr)
    cin >> i, occ[i]++;
  sort(all(arr));
  ll res = 0;
  for (auto i : arr) {
    if (!divided[i] && occ[i] == 1) {
      res++;
    }
    for (int j = 1; j * i < mxe; j++) {
      divided[j * i] = 1;
    }
  }
  cout << res << endl;
}

Fixed submission:
#include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace std;
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db double
#define eps 1e-8
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
const ll mod = 1e9 + 9;
const ll maxn = 2e5 + 10;
const ll mxe = 1e6 + 10;
bool divided[mxe];
vector<int> arr;
map<int, int> occ;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  arr.resize(n);
  for (auto &i : arr)
    cin >> i, occ[i]++;
  sort(all(arr));
  ll res = 0;
  for (auto i : arr) {
    if (!divided[i] && occ[i] == 1) {
      res++;
    }
    if (!divided[i]) {
      for (int j = 1; j * i < mxe; j++) {
        divided[j * i] = 1;
      }
    }
  }
  cout << res << endl;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma GCC target("avx2")
#pragma GCC optimize "trapv"
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define si(a) scanf("%d", &a)
#define si2(a, b) scanf("%d%d", &a, &b)
#define sl(a) scanf("%lld", &a)
#define sl2(a, b) scanf("%lld%lld", &a, &b)
#define pb push_back
#define mk make_pair
#define loop(n) for (int i = 0; i < n; i++)
#define FOR(a, b) for (int i = a; i <= b; i++)
#define sz size()
#define ff first
#define ss second
#define mem(a, val) memset(a, val, sizeof(a))
#define md 1000000007
#define pi acos(-1.0)

ll a[200010], m[1000005];
int main() {
  ll t, n, i, j, k, l, r, mn = 0, mx = 1;
  cin >> n;
  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
  }

  ll f = 0;
  for (int i = 0; i < n; i++) {
    f = 0;
    if (m[a[i]] > 1)
      continue;
    for (ll j = 1; j * j <= a[i]; j++) {

      if (a[i] % j == 0) {
        if (m[j] > 0 && j != a[i])
          f = 1;

        ll p = a[i] / j;
        if (m[p] > 0 && p != a[i])
          f = 1;
      }
    }
    // cout<<a[i]<<" "<<f<<endl;
    if (f == 0)
      cnt++;
  }
  cout << cnt;
}


Fixed submission:
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define si(a) scanf("%d", &a)
#define si2(a, b) scanf("%d%d", &a, &b)
#define sl(a) scanf("%lld", &a)
#define sl2(a, b) scanf("%lld%lld", &a, &b)
#define pb push_back
#define mk make_pair
#define loop(n) for (int i = 0; i < n; i++)
#define FOR(a, b) for (int i = a; i <= b; i++)
#define sz size()
#define ff first
#define ss second
#define mem(a, val) memset(a, val, sizeof(a))
#define md 1000000007
#define pi acos(-1.0)

ll a[200010], m[1000005];
int main() {
  ll t, n, i, j, k, l, r, mn = 0, mx = 1;
  cin >> n;
  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
  }

  ll f = 0;
  for (int i = 0; i < n; i++) {
    f = 0;
    if (m[a[i]] > 1)
      continue;
    for (ll j = 1; j * j <= a[i]; j++) {

      if (a[i] % j == 0) {
        if (m[j] > 0 && j != a[i])
          f = 1;

        ll p = a[i] / j;
        if (m[p] > 0 && p != a[i])
          f = 1;
      }
    }
    // cout<<a[i]<<" "<<f<<endl;
    if (f == 0)
      cnt++;
  }
  cout << cnt;
}