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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e5 + 555;
const int MOD = 1e9 + 7;
int mp[maxn];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  cout << fixed;
  int n;
  cin >> n;
  vector<int> V(n);
  for (int &i : V) {
    cin >> i;
    mp[i]++;
  }
  int ans = 0;
  for (int i : V) {
    mp[i]--;
    bool ok = true;
    for (int j = 1; j * j <= i && ok; j++) {
      if (i % j == 0) {
        ok &= !mp[j];
        ok &= !mp[i / j];
      }
    }
    ans += ok;
    mp[i]++;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e6 + 555;
const int MOD = 1e9 + 7;
int mp[maxn];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  cout << fixed;
  int n;
  cin >> n;
  vector<int> V(n);
  for (int &i : V) {
    cin >> i;
    mp[i]++;
  }
  int ans = 0;
  for (int i : V) {
    mp[i]--;
    bool ok = true;
    for (int j = 1; j * j <= i && ok; j++) {
      if (i % j == 0) {
        ok &= !mp[j];
        ok &= !mp[i / j];
      }
    }
    ans += ok;
    mp[i]++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
// #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod = 1e+9 + 7;

const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
const ll INF = 1e10;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> cnt(1e6 + 10, 0);

  for (auto x : a) {
    /*if(cnt[x]!=0){
 cnt[x]=2;
 continue;
}*/
    for (ll i = x; i < 1e6 + 10; i += x) {
      cnt[i]++;
    }
  }
  ll ans = 0;
  for (auto x : a) {
    if (cnt[x] == 1) {
      // cout<<x<<" ";
      ans++;
    }
  }
  // cout<<endl;
  cout << ans << endl;
}


Fixed submission:
// #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod = 1e+9 + 7;

const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
const ll INF = 1e10;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> cnt(1e6 + 10, 0);

  for (auto x : a) {
    if (cnt[x] != 0) {
      cnt[x] = 2;
      continue;
    }

    for (ll i = x; i < 1e6 + 10; i += x) {
      cnt[i]++;
    }
  }
  ll ans = 0;
  for (auto x : a) {
    if (cnt[x] == 1) {
      // cout<<x<<" ";
      ans++;
    }
  }
  // cout<<endl;
  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
/*
   Created by Ezio112
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
ll inf(1e18);
#define mod ll(1e9 + 7)
// #define mod ll(998244353)
#define ff first
#define ss second
ll power(ll a, ll b) {
  if (!b)
    return 1;
  ll dp = power(a, b / 2) % mod;

  if (b & 1)
    return (((dp * dp) % mod) * a) % mod;

  return (dp * dp) % mod;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll test = 1;
  // cin>>test;

  while (test--) {
    ll n;
    cin >> n;

    vector<ll> vec(n);
    for (ll &x : vec)
      cin >> x;

    vector<short int> dp(200005);
    for (ll x : vec)
      ++dp[x];

    for (ll i = 1; i < dp.size(); ++i) {
      if (dp[i] == 0)
        continue;

      for (ll j = 2 * i; j < dp.size(); j += i)
        dp[j] = 0;
    }
    ll sum = 0;
    for (ll x : dp)
      if (x == 1)
        sum += x;
    cout << sum;
  }
  return 0;
}


Fixed submission:
/*
   Created by Ezio112
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
ll inf(1e18);
#define mod ll(1e9 + 7)
// #define mod ll(998244353)
#define ff first
#define ss second
ll power(ll a, ll b) {
  if (!b)
    return 1;
  ll dp = power(a, b / 2) % mod;

  if (b & 1)
    return (((dp * dp) % mod) * a) % mod;

  return (dp * dp) % mod;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll test = 1;
  // cin>>test;

  while (test--) {
    ll n;
    cin >> n;

    vector<ll> vec(n);
    for (ll &x : vec)
      cin >> x;

    vector<short int> dp(2000005);
    for (ll x : vec)
      ++dp[x];

    for (ll i = 1; i < dp.size(); ++i) {
      if (dp[i] == 0)
        continue;

      for (ll j = 2 * i; j < dp.size(); j += i)
        dp[j] = 0;
    }
    ll sum = 0;
    for (ll x : dp)
      if (x == 1)
        sum += x;
    cout << sum;
  }
  return 0;
}
Problem p02642 (C++)

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

using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 998244353;

int parent[N];

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

int lcm(int a, int b) { return (a * b) / gcd(a, b); }

ll pow(ll x, ll y, ll p) {
  if (y == 0)
    return 1;
  ll res = 1;
  x %= p;
  if (x == 0)
    return 0LL;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y >>= 1;
    x = (x * x) % p;
  }
  return res;
}

int find(int x) { return x == parent[x] ? x : parent[x] = find(parent[x]); }

void Union(int x, int y) {
  int xPar = find(x), yPar = find(y);
  if (xPar != yPar)
    parent[xPar] = yPar;
}

int main() {
  IOS int n;
  cin >> n;
  ll mx = 0;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  vector<int> cnt(N);
  for (auto val : a) {
    if (cnt[val]) {
      cnt[val] = 2;
      continue;
    }
    for (int j = val; j <= mx; j += val)
      cnt[j]++;
  }
  int res = 0;
  for (auto val : a)
    if (cnt[val] == 1)
      res++;
  cout << res << endl;
  return 0;
}


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

using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 998244353;

int parent[N];

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

int lcm(int a, int b) { return (a * b) / gcd(a, b); }

ll pow(ll x, ll y, ll p) {
  if (y == 0)
    return 1;
  ll res = 1;
  x %= p;
  if (x == 0)
    return 0LL;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y >>= 1;
    x = (x * x) % p;
  }
  return res;
}

int find(int x) { return x == parent[x] ? x : parent[x] = find(parent[x]); }

void Union(int x, int y) {
  int xPar = find(x), yPar = find(y);
  if (xPar != yPar)
    parent[xPar] = yPar;
}

int main() {
  IOS int n;
  cin >> n;
  ll mx = 0;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  vector<int> cnt(mx + 1);
  for (auto val : a) {
    if (cnt[val]) {
      cnt[val] = 2;
      continue;
    }
    for (int j = val; j <= mx; j += val)
      cnt[j]++;
  }
  int res = 0;
  for (auto val : a)
    if (cnt[val] == 1)
      res++;
  cout << res << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(nullptr);
#define all(x) x.begin(), x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for (int x = 0; x < n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define ctoi(x) (x - '0')
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

int n, ans;
vi v(200010);
map<int, int> M;

int main() {
  fastio;
  cin >> n;
  FOR(i, n) {
    cin >> v[i + 1];
    M[v[i + 1]]++;
  }
  for (int i = 1; i <= n; i++) {
    int flag = 1;
    for (ll j = 1; j * j <= v[i]; j++) {
      if (v[i] % j == 0) {
        // v[i]/j, j
        if (j == v[i] && M[j] >= 2 || j != v[i] && M[j] >= 1 ||
            v[i] / j == v[i] && M[v[i] / j] >= 2 ||
            v[i] / j != v[i] && M[v[i] / j] >= 1) {
          flag = 0;
          break;
        }
      }
    }
    if (flag)
      ans++;
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(nullptr);
#define all(x) x.begin(), x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for (int x = 0; x < n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define ctoi(x) (x - '0')
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

int n, ans;
vi v(200010);
unordered_map<int, int> M;

int main() {
  fastio;
  cin >> n;
  FOR(i, n) {
    cin >> v[i + 1];
    M[v[i + 1]]++;
  }
  for (int i = 1; i <= n; i++) {
    int flag = 1;
    for (ll j = 1; j * j <= v[i]; j++) {
      if (v[i] % j == 0) {
        // v[i]/j, j
        if (j == v[i] && M[j] >= 2 || j != v[i] && M[j] >= 1 ||
            v[i] / j == v[i] && M[v[i] / j] >= 2 ||
            v[i] / j != v[i] && M[v[i] / j] >= 1) {
          flag = 0;
          break;
        }
      }
    }
    if (flag)
      ans++;
  }
  cout << ans;
}
Problem p02642 (C++)

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

template <typename TYPE> void print_vec(const vector<TYPE> &v) {
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}

template <typename TYPE> void print_vec2(const vector<vector<TYPE>> &v) {
  cout << endl;
  for (int i = 0; i < v[0].size(); i++)
    cout << i << "   ";
  cout << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << "i=" << i << ":   " << endl;
    for (int j = 0; j < v[i].size(); j++) {
      if (v[i][j] == 0)
        cout << "\x1B[0m" << v[i][j] << "   ";
      else
        cout << "\x1B[31m" << v[i][j]
             << "   "; // https://stackoverrun.com/ja/q/12618775
    }
    cout << "\x1B[0m" << endl;
  }
}

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

  // const ll MAX_A = 1e6;
  ll MAX_A = 1e6;
  for (int i = 0; i < N; i++) {
    MAX_A = max(MAX_A, A[i]);
  }
  vector<ll> vec(MAX_A + 5, 0);
  for (ll a : A) {
    for (ll j = 1; a * j <= MAX_A; j++) {
      vec[a * j]++;
    }
  }

  ll ans = 0;
  for (ll a : A) {
    if (vec[a] == 1)
      ans++;
  }

  cout << ans << endl;
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE> void print_vec(const vector<TYPE> &v) {
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}

template <typename TYPE> void print_vec2(const vector<vector<TYPE>> &v) {
  cout << endl;
  for (int i = 0; i < v[0].size(); i++)
    cout << i << "   ";
  cout << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << "i=" << i << ":   " << endl;
    for (int j = 0; j < v[i].size(); j++) {
      if (v[i][j] == 0)
        cout << "\x1B[0m" << v[i][j] << "   ";
      else
        cout << "\x1B[31m" << v[i][j]
             << "   "; // https://stackoverrun.com/ja/q/12618775
    }
    cout << "\x1B[0m" << endl;
  }
}

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

  // const ll MAX_A = 1e6;
  ll MAX_A = 0;
  for (int i = 0; i < N; i++) {
    MAX_A = max(MAX_A, A[i]);
  }
  vector<ll> vec(MAX_A + 5, 0);
  for (ll a : A) {
    for (ll j = 1; a * j <= MAX_A; j++) {
      vec[a * j]++;
    }
  }

  ll ans = 0;
  for (ll a : A) {
    if (vec[a] == 1)
      ans++;
  }

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

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

using namespace std;

int main() {
  int N;
  cin >> N;
  int M = 1000005;
  int cnt[M];
  for (int i = 0; i < M; i++) {
    cnt[i] = 0;
  }
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (cnt[A[i]] > 1) {
      break;
    } else {
      for (int j = A[i]; j < M; j += A[i]) {
        cnt[j]++;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (cnt[A[i]] == 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  int M = 1000005;
  int cnt[M];
  for (int i = 0; i < M; i++) {
    cnt[i] = 0;
  }
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (cnt[A[i]] > 1) {
      continue;
    } else {
      for (int j = A[i]; j < M; j += A[i]) {
        cnt[j]++;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (cnt[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, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD = 1000000007;
int main() {
  int N, ans = 0;
  cin >> N;
  vector<int64_t> A(N);
  vector<bool> div(1000050, true);
  rep(i, N) cin >> A.at(i);
  sort(A.begin(), A.end());
  rep(i, N) {
    int64_t k = A.at(i), l = 2;
    if (div.at(k)) {
      while (k * l <= 1000010) {
        div.at(k * l) = false;
        l++;
      }
    }
  }
  rep(i, N - 1) {
    if (A.at(i) == A.at(i + 1))
      div.at(A.at(i)) = false;
  }

  rep(i, N) {
    if (div.at(A.at(i)))
      ans++;
  }
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD = 1000000007;
int main() {
  int N, ans = 0;
  cin >> N;
  vector<int64_t> A(N);
  vector<bool> div(1000050, true);
  rep(i, N) cin >> A.at(i);
  sort(A.begin(), A.end());
  rep(i, N) {
    int64_t k = A.at(i), l = 2;
    if (div.at(k)) {
      while (k * l <= 1000010) {
        div.at(k * l) = false;
        l++;
      }
    }
    if (i > 0 && k == A.at(i - 1))
      div.at(k) = false;
  }

  rep(i, N) {
    if (div.at(A.at(i)))
      ans++;
  }
  cout << ans;
}
Problem p02642 (C++)

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

const int M = 1000005;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> cnt(M);
  for (int x : a) {
    // if (cnt[x] != 0) {
    //   cnt[x] = 2;
    //   continue;
    // }
    for (int i = x; i < M; i += x)
      cnt[i]++;
  }
  int ans = 0;
  for (int x : a) {
    if (cnt[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)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int M = 1000005;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> cnt(M);
  for (int x : a) {
    if (cnt[x] != 0) {
      cnt[x] = 2;
      continue;
    }
    for (int i = x; i < M; i += x)
      cnt[i]++;
  }
  int ans = 0;
  for (int x : a) {
    if (cnt[x] == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

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

#define int long long
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int memo[1000010];
int all[1000010];

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

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

  for (int i = 1; i <= 1000000; i++) {
    for (int j = i; j <= 1000000; j += i) {
      all[j] += memo[i];
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (all[a[i]] == 1)
      ans++;
  }

  cout << ans << endl;

  return 0;
}


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

#define int long long
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int memo[1000010];
int all[1000010];

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

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

  for (int i = 1; i <= 1000000; i++) {
    for (int j = i; j <= 1000000; j += i) {
      all[j] += memo[i];
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (all[a[i]] == 1)
      ans++;
  }

  cout << ans << endl;

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P, int> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 998244353;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

const int M = 1000001;
int n;
vi a;
bool b[M];

int main() {
  cin >> n;
  a = vi(n);
  map<int, int> mp;
  for (auto &i : a) {
    cin >> i;
    mp[i]++;
  }
  sort(a.begin(), a.end());
  int t = 0;
  for (auto i : a) {
    if (mp[i] == 1 && !b[i])
      t++;
    if (!b[i]) {
      int x = i;
      while (x <= M)
        b[x += i] = 1;
    }
  }
  cout << t << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P, int> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 998244353;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

const int M = 1000001;
int n;
vi a;
bool b[M];

int main() {
  cin >> n;
  a = vi(n);
  map<int, int> mp;
  for (auto &i : a) {
    cin >> i;
    mp[i]++;
  }
  sort(a.begin(), a.end());
  int t = 0;
  for (auto i : a) {
    if (mp[i] == 1 && !b[i])
      t++;
    if (!b[i]) {
      int x = i;
      while (x < M) {
        b[x] = 1;
        x += i;
      }
    }
  }
  cout << t << endl;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath> //sqrt
#include <functional>
#include <iomanip> //setprecision
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define MAX 100001

void _main() {
  ll n;
  cin >> n;
  vector<ll> p(MAX, 0);
  set<ll> s;
  rep(i, n) {
    ll a;
    cin >> a;
    p[a]++;
    s.insert(a);
  }
  ll out = 0;
  for (auto i : s) {
    for (ll j = 2; j < MAX; j++) {
      if (i * j >= MAX)
        break;
      p[i * j]++;
    }
  }
  for (auto i : s) {
    if (p[i] == 1)
      out++;
  }
  cout << out << endl;
  return;
}
int main() {
  cout << fixed << setprecision(10);
  _main();
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath> //sqrt
#include <functional>
#include <iomanip> //setprecision
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define MAX 1000001

void _main() {
  ll n;
  cin >> n;
  vector<ll> p(MAX, 0);
  set<ll> s;
  rep(i, n) {
    ll a;
    cin >> a;
    p[a]++;
    s.insert(a);
  }
  ll out = 0;
  for (auto i : s) {
    for (ll j = 2; j < MAX; j++) {
      if (i * j >= MAX)
        break;
      p[i * j]++;
    }
  }
  for (auto i : s) {
    if (p[i] == 1)
      out++;
  }
  cout << out << endl;
  return;
}
int main() {
  cout << fixed << setprecision(10);
  _main();
  return 0;
}
Problem p02642 (C++)

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

using namespace std;

const int N = 1000005;

int cnt[N];
int n, a[N / 10];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", a + i), cnt[a[i]]++;

  for (int i = 1; i < N; i++)
    if (cnt[i]) {
      for (int j = i + i; j < N; j += i) {
        cnt[j] += cnt[i];
      }
    }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += cnt[a[i]] == 1;
  }

  printf("%d\n", ans);
}


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

using namespace std;

const int N = 1000005;

int cnt[N];
int n, a[N / 5];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", a + i), cnt[a[i]]++;

  for (int i = 1; i < N; i++)
    if (cnt[i]) {
      for (int j = i + i; j < N; j += i) {
        cnt[j] += cnt[i];
      }
    }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += cnt[a[i]] == 1;
  }

  printf("%d\n", ans);
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, a[233333], vis[233333], ans;
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i], vis[a[i]]++;
  for (int i = 1; i <= n; i++) {
    int flg = 1;
    for (int j = 1; j * j <= a[i]; j++)
      if (a[i] % j == 0) {
        if (j != a[i] && vis[j] || j == a[i] && vis[j] > 1 ||
            a[i] / j != a[i] && vis[a[i] / j] ||
            a[i] / j == a[i] && vis[a[i] / j] > 1) {
          flg = 0;
          break;
        }
      }
    if (flg)
      ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, a[2333333], vis[2333333], ans;
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i], vis[a[i]]++;
  for (int i = 1; i <= n; i++) {
    int flg = 1;
    for (int j = 1; j * j <= a[i]; j++)
      if (a[i] % j == 0) {
        if (j != a[i] && vis[j] || j == a[i] && vis[j] > 1 ||
            a[i] / j != a[i] && vis[a[i] / j] ||
            a[i] / j == a[i] && vis[a[i] / j] > 1) {
          flg = 0;
          break;
        }
      }
    if (flg)
      ans++;
  }
  cout << ans << endl;
}
Problem p02642 (C++)

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

using namespace std;

typedef long long ll;

const ll MAXI = 1001;

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

  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> inc(MAXI, 0);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ++inc[a[i]];
  }

  if (inc[1] > 0) {
    if (inc[1] > 1) {
      cout << "0\n";
    } else {
      cout << "1\n";
    }
    return 0;
  }

  int cou = 0;
  for (ll i = 2; i < MAXI; ++i) {
    if (inc[i] == 0) {
      continue;
    }
    if (inc[i] == 1) {
      ++cou;
    }
    for (ll j = i + i; j < MAXI; j += i) {
      inc[j] = 0;
    }
  }
  cout << cou << "\n";

  return 0;
}


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

using namespace std;

typedef long long ll;

const ll MAXI = 1000001;

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

  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> inc(MAXI, 0);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ++inc[a[i]];
  }

  if (inc[1] > 0) {
    if (inc[1] > 1) {
      cout << "0\n";
    } else {
      cout << "1\n";
    }
    return 0;
  }

  int cou = 0;
  for (ll i = 2; i < MAXI; ++i) {
    if (inc[i] == 0) {
      continue;
    }
    if (inc[i] == 1) {
      ++cou;
    }
    for (ll j = i + i; j < MAXI; j += i) {
      inc[j] = 0;
    }
  }
  cout << cou << "\n";

  return 0;
}
Problem p02642 (C++)

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

int a[100009], cnt[1000009];

int main() {
  int n, i, j;
  cin >> n;

  for (i = 0; i < n; i++)
    cin >> a[i];

  sort(a, a + n);

  for (i = 0; i < n; i++) {
    if (cnt[a[i]] != 0) {
      cnt[a[i]] = 2;
      continue;
    }

    for (j = 1; a[i] * j <= a[n - 1]; j++)
      cnt[a[i] * j]++;
  }

  int ans = 0;
  for (i = 0; i < n; i++) {
    if (cnt[a[i]] == 1)
      ans++;
  }

  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second

int a[200009], cnt[1000009];

int main() {
  int n, i, j;
  cin >> n;

  for (i = 0; i < n; i++)
    cin >> a[i];

  sort(a, a + n);

  for (i = 0; i < n; i++) {
    if (cnt[a[i]] != 0) {
      cnt[a[i]] = 2;
      continue;
    }

    for (j = 1; a[i] * j <= a[n - 1]; j++)
      cnt[a[i] * j]++;
  }

  int ans = 0;
  for (i = 0; i < n; i++) {
    if (cnt[a[i]] == 1)
      ans++;
  }

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

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

#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;

void solveBruteForce() {}

void solveOptimized() {
  int n;
  cin >> n;
  int a[n];

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

  sort(a, a + n);

  int divisible[1000001];
  for (int i = 1; i < 1000001; i++)
    divisible[i] = 0;
  divisible[0] = 1;

  for (int i = 0; i < n; i++) {
    int j = a[i];

    while (j < 1000001) {
      divisible[j]++;
      j += a[i];
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (divisible[a[i]] <= 1)
      ans++;
  }

  cout << ans;
}

void solve() {
  // solveBruteForce();
  solveOptimized();
}

int main() {

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

  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}


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

#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;

void solveBruteForce() {}

void solveOptimized() {
  int n;
  cin >> n;
  int a[n];

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

  sort(a, a + n);

  int divisible[1000001];
  for (int i = 1; i < 1000001; i++)
    divisible[i] = 0;
  divisible[0] = 1;

  for (int i = 0; i < n; i++) {
    int j = a[i];
    if (divisible[j] < 2) {
      while (j < 1000001) {
        divisible[j]++;
        j += a[i];
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (divisible[a[i]] <= 1)
      ans++;
  }

  cout << ans;
}

void solve() {
  // solveBruteForce();
  solveOptimized();
}

int main() {

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

  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T> using V = vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
const ll inf = (1e18);
const ll mod = 998244353;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ll n;
  cin >> n;
  V<ll> a(n);
  map<ll, ll> mp;
  map<ll, bool> d;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
    d[a[i]] = true;
  }
  ll ans = 0;
  for (auto p : mp) {
    if (d[p.fi] && p.se == 1)
      ans++;
    for (ll i = 2; i * p.fi <= (1e6); i++) {
      if (mp.count(i * p.fi)) {
        d[i * p.fi] = false;
      }
    }
  }
  cout << ans << "\n";
}


Fixed submission:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T> using V = vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
const ll inf = (1e18);
const ll mod = 998244353;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ll n;
  cin >> n;
  V<ll> a(n);
  map<ll, ll> mp;
  map<ll, bool> d;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
    d[a[i]] = true;
  }
  ll ans = 0;
  for (auto p : mp) {
    if (!d[p.fi])
      continue;
    if (p.se == 1)
      ans++;
    for (ll i = 2; i * p.fi <= (1e6); i++) {
      if (mp.count(i * p.fi)) {
        d[i * p.fi] = false;
      }
    }
  }
  cout << ans << "\n";
}
Problem p02642 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) { cin >> A.at(i); }
  sort(A.begin(), A.end());

  ll res = 0;
  vector<bool> B(N, false);
  for (int i = 0; i < N; i++) {
    if (B[i])
      continue;
    while (i < N - 1 && A[i] == A[i + 1]) {
      B[i] = true;
      B[i + 1] = true;
      i++;
    }
    int x = A[i] * 2;
    while (x <= A[N - 1]) {
      auto y = lower_bound(A.begin(), A.end(), x);
      if (*y == x) {
        int d = y - A.begin();
        B[d] = true;
        for (y++, d++; y != A.end(); y++, d++) {
          if (*y == x) {
            B[d] = true;
          }
        }
      }
      x += A[i];
    }
  }
  rep(i, N) {
    if (!B[i])
      res++;
  }
  cout << res << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) { cin >> A.at(i); }
  sort(A.begin(), A.end());

  ll res = 0;
  vector<bool> B(N, false);
  for (int i = 0; i < N; i++) {
    if (B[i])
      continue;
    while (i < N - 1 && A[i] == A[i + 1]) {
      B[i] = true;
      B[i + 1] = true;
      i++;
    }
    int x = A[i] * 2;
    while (x <= A[N - 1]) {
      auto y = lower_bound(A.begin(), A.end(), x);
      if (*y == x) {
        int d = y - A.begin();
        B[d] = true;
        while (d < N - 1 && A[d] == A[d + 1])
          B[++d] = true;
      }
      x += A[i];
    }
  }
  rep(i, N) {
    if (!B[i])
      res++;
  }
  cout << res << endl;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  const int M = 1000005;
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  vector<int> C(M);
  rep(i, M) C[i] = 0;
  for (int x : A) {
    for (int j = x; j < M; j += x) {
      C[j] = C[j] + 1;
    }
  }
  int ans = 0;
  for (int x : A) {
    if (C[x] == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  const int M = 1000005;
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  vector<int> C(M);
  rep(i, M) C[i] = 0;
  for (int x : A) {
    if (C[x] == 1) {
      C[x] = 2;
      continue;
    }
    if (C[x] != 0)
      continue;
    for (int j = x; j < M; j += x) {
      C[j] = C[j] + 1;
    }
  }
  int ans = 0;
  for (int x : A) {
    if (C[x] == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

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

using namespace std;

#define CIN                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define TEST_CASE(t) for (int zz = 1; zz <= t; zz++)
#define PRINT_CASE printf("Case %d: ", zz)
#define Debug(x) cout << #x " = " << (x) << endl

const int maxn = (int)1e5 + 5;
typedef long long ll;

int cnt[maxn];
void solve() {

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

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (cnt[a[i]]) {
      cnt[a[i]] = 2;
      continue;
    }
    int val = a[i];
    for (int j = val; j < maxn; j += (val)) {
      cnt[j]++;
    }
  }

  for (int i = 1; i <= n; i++) {

    if (cnt[a[i]] <= 1)
      ans++;
  }

  cout << ans << endl;
}

int main() {
  CIN
      // freopen("input.txt", "r", stdin);
      // freopen("output.txt", "w", stdout);

      // cout << "Fi Amanillah" << endl;

      int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}


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

using namespace std;

#define CIN                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define TEST_CASE(t) for (int zz = 1; zz <= t; zz++)
#define PRINT_CASE printf("Case %d: ", zz)
#define Debug(x) cout << #x " = " << (x) << endl

const int maxn = (int)1e6 + 5;
typedef long long ll;

int cnt[maxn];
void solve() {

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

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (cnt[a[i]]) {
      cnt[a[i]] = 2;
      continue;
    }
    int val = a[i];
    for (int j = val; j < maxn; j += (val)) {
      cnt[j]++;
    }
  }

  for (int i = 1; i <= n; i++) {

    if (cnt[a[i]] <= 1)
      ans++;
  }

  cout << ans << endl;
}

int main() {
  CIN
      // freopen("input.txt", "r", stdin);
      // freopen("output.txt", "w", stdout);

      // cout << "Fi Amanillah" << endl;

      int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02642 (C++)

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

int main() {

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

  sort(all(a));

  vector<bool> ng(1000001, false);
  rep(i, n) {
    if (i == 0)
      continue;
    if (a[i] == a[i - 1])
      ng[a[i]] = true;
  }

  vector<bool> dp(1000001, true);

  for (int i : a) {
    if (dp[i]) {
      int x = i * 2;
      while (x <= 1000000) {
        dp[x] = false;
        x += i;
      }
    }
  }

  int ans = 0;

  for (int i : a) {
    if (dp[i] && (!ng[i]))
      ans++;
  }

  cout << ans << endl;
}

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

int main() {

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

  sort(all(a));

  vector<bool> ng(1000001, false);
  rep(i, n) {
    if (i == 0)
      continue;
    if (a[i] == a[i - 1])
      ng[a[i]] = true;
  }

  vector<bool> dp(1000001, true);

  for (int i : a) {
    if (dp[i]) {
      int x = i;
      if (!ng[i])
        x += i;
      while (x <= 1000000) {
        dp[x] = false;
        x += i;
      }
    }
  }

  int ans = 0;

  for (int i : a) {
    if (dp[i] && (!ng[i]))
      ans++;
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define fast                                                                   \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define PB push_back
#define MP make_pair
#define F first
#define S second
int dp[1000006];
int b[1000006];
int main() {
  int n;
  cin >> n;
  int a[100005];
  int count = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  for (int i = 1; i < 1000006; i++) {
    if (b[i] != 0) {
      for (int j = 2 * i; j < 1000006; j += i) {
        dp[j] = 1;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (b[a[i]] > 1) {
      continue;
    }
    if (dp[a[i]] == 0) {
      count++;
    }
  }
  cout << count;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define fast                                                                   \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define PB push_back
#define MP make_pair
#define F first
#define S second
int dp[1000006];
int b[1000006];
int main() {
  int n;
  cin >> n;
  int a[200005];
  int count = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  for (int i = 1; i < 1000006; i++) {
    if (b[i] != 0) {
      for (int j = 2 * i; j < 1000006; j += i) {
        dp[j] = 1;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (b[a[i]] > 1) {
      continue;
    }
    if (dp[a[i]] == 0) {
      count++;
    }
  }
  cout << count;
  return 0;
}
Problem p02642 (C++)

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

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
#define endl "\n";
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)

ll const inf = 1e18;
ll const maxn = 1e6 + 5;
ll const mod = 1e9 + 7;

// code begins here

int main() {
  fast;

  ll n;
  cin >> n;

  vector<ll> arr(n);
  for (auto &u : arr)
    cin >> u;

  vector<ll> cnt(maxn, 0), cnt1(maxn, 0);

  set<ll> s;

  for (ll i = 0; i < n; i++) {
    cnt1[arr[i]]++;
    if (s.count(arr[i]))
      continue;
    for (ll j = arr[i]; j < maxn; j += arr[i]) {
      cnt[j]++;
    }
  }

  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    if (cnt[arr[i]] == 1 && cnt1[arr[i]] == 1)
      ans++;
  }

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


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

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
#define endl "\n";
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)

ll const inf = 1e18;
ll const maxn = 1e6 + 5;
ll const mod = 1e9 + 7;

// code begins here

int main() {
  fast;

  ll n;
  cin >> n;

  vector<ll> arr(n);
  for (auto &u : arr)
    cin >> u;

  vector<ll> cnt(maxn, 0), cnt1(maxn, 0);

  set<ll> s;

  for (ll i = 0; i < n; i++) {
    cnt1[arr[i]]++;
    if (s.count(arr[i]))
      continue;
    for (ll j = arr[i]; j < maxn; j += arr[i]) {
      cnt[j]++;
    }
    s.insert(arr[i]);
  }

  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    if (cnt[arr[i]] == 1 && cnt1[arr[i]] == 1)
      ans++;
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define debug(a) cout << #a ": " << a << endl
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
const int M = 1e6 + 7;
int a[N], b[M];
int main(void) {
  IOS;
  int n;
  cin >> n;
  int mx = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i) {
    if (a[i] == a[i - 1]) {
      b[a[i]] = 1;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (!b[a[i]])
      ans++;
    for (int j = a[i] + a[i]; j <= mx; j += a[i]) {
      b[j] = 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define debug(a) cout << #a ": " << a << endl
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
const int N = 2e5 + 7;
const int M = 1e6 + 7;
int a[N], b[M];
int main(void) {
  IOS;
  int n;
  cin >> n;
  int mx = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i) {
    if (a[i] == a[i - 1]) {
      b[a[i]] = 1;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (!b[a[i]])
      ans++;
    for (int j = a[i] + a[i]; j <= mx; j += a[i]) {
      b[j] = 1;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;

int c[1000006];
vector<int> V;
set<int> S;
multiset<int> T;

int N, A[200005];

int dp[200005];

int main(void) {
  cin >> N;
  int Am = 0;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    V.push_back(A[i]);
    S.insert(A[i]);
    T.insert(A[i]);
    Am = max(Am, A[i]);
  }

  // sort(V.begin(), V.end());

  for (auto y : V) {
    if (c[y] >= 1) {
      c[y] = 2;
    } else if (c[y] >= 0) {
      c[y]++;
      for (long long int j = y * 2; j <= Am; j += y) {
        c[(int)j] = -1;
      }
    }
  }

  int ans = 0;

  for (int i = 1; i <= N; i++) {
    if (T.count(A[i]) >= 2) {
      continue;
    }
    if (c[A[i]] == 1) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;

int c[1000006];
vector<int> V;
set<int> S;
multiset<int> T;

int N, A[200005];

int dp[200005];

int main(void) {
  cin >> N;
  int Am = 0;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    V.push_back(A[i]);
    S.insert(A[i]);
    T.insert(A[i]);
    Am = max(Am, A[i]);
  }

  // sort(V.begin(), V.end());

  for (auto y : V) {
    if (c[y] >= 1) {
      c[y] = 2;
    } else if (c[y] >= 0) {
      c[y]++;
      for (long long int j = y * 2; j <= Am; j += y) {
        c[(int)j] = -1;
      }
    }
  }

  int ans = 0;

  for (int i = 1; i <= N; i++) {
    // if (T.count(A[i]) >= 2) { continue; }
    if (c[A[i]] == 1) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;

int c[1000006];
vector<int> V;
set<int> S;
multiset<int> T;

int N, A[200005];

int dp[200005];

int num[1000006];

int main(void) {
  cin >> N;
  int Am = 0;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    V.push_back(A[i]);
    S.insert(A[i]);
    T.insert(A[i]);
    Am = max(Am, A[i]);
    num[A[i]]++;
  }

  // sort(V.begin(), V.end());

  for (auto y : V) {
    if (c[y] >= 1) {
      c[y] = 2;
    } else if (c[y] >= 0) {
      c[y]++;
      for (long long int j = y * 2; j <= Am; j += y) {
        c[(int)j] = -1;
      }
    }
  }

  int ans = 0;

  for (int i = 1; i <= N; i++) {
    int u = A[i];
    if (T.count(u) >= 2) {
      continue;
    }
    // else  if (c[u] == 1) { ans++; }
  }

  for (int i = 1; i <= N; i++) {
    // if (T.count(A[i]) >= 2) { continue; }
    if (c[A[i]] == 1) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;

int c[1000006];
vector<int> V;
set<int> S;
multiset<int> T;

int N, A[200005];

int dp[200005];

int num[1000006];

int main(void) {
  cin >> N;
  int Am = 0;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    V.push_back(A[i]);
    S.insert(A[i]);
    T.insert(A[i]);
    Am = max(Am, A[i]);
    num[A[i]]++;
  }

  // sort(V.begin(), V.end());

  for (auto y : V) {
    if (c[y] >= 1) {
      c[y] = 2;
    } else if (c[y] >= 0) {
      c[y]++;
      for (long long int j = y * 2; j <= Am; j += y) {
        c[(int)j] = -1;
      }
    }
  }

  int ans = 0;

  for (int i = 1; i <= N; i++) {
    int u = A[i];
    if (T.count(u) >= 2) { /*continue;*/
    }
    // else  if (c[u] == 1) { ans++; }
  }

  for (int i = 1; i <= N; i++) {
    // if (T.count(A[i]) >= 2) { continue; }
    if (c[A[i]] == 1) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  fast();
  int n, a[200005], b[200005], j, i, ans = 0;
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  for (i = 0; i <= a[n - 1]; i++)
    b[i] = 1;
  for (i = 0; i < n; i++)
    if (b[a[i]])
      for (j = a[i] * 2; j <= a[n - 1]; j += a[i])
        b[j] = 0;
  for (i = 0; i < n - 1; i++)
    if (a[i] == a[i + 1])
      b[a[i]] = 0;
  for (i = 0; i < n; i++)
    if (b[a[i]])
      ++ans;
  cout << ans << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  fast();
  int n, a[200005], b[1000005], j, i, ans = 0;
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  for (i = 0; i <= a[n - 1]; i++)
    b[i] = 1;
  for (i = 0; i < n; i++)
    if (b[a[i]])
      for (j = a[i] * 2; j <= a[n - 1]; j += a[i])
        b[j] = 0;
  for (i = 0; i < n - 1; i++)
    if (a[i] == a[i + 1])
      b[a[i]] = 0;
  for (i = 0; i < n; i++)
    if (b[a[i]])
      ++ans;
  cout << ans << "\n";
  return 0;
}