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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
bool b[200020] = {false};
int main() {
  int n;
  cin >> n;
  int a[200020];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int co = 0;
  for (int i = 0; i < n; i++) {
    bool bo = true;
    for (int j = 1; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        if (b[j] == true) {
          bo = false;
        }
        if (b[a[i] / j] == true) {
          bo = false;
        }
      }
    }
    b[a[i]] = true;
    if (i != n - 1) {
      if (a[i] == a[i + 1]) {
        bo = false;
      }
    }
    if (bo == true) {
      co++;
    }
  }
  cout << co << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
bool b[1000110] = {false};
int main() {
  int n;
  cin >> n;
  int a[200020];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int co = 0;
  for (int i = 0; i < n; i++) {
    bool bo = true;
    for (int j = 1; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        if (b[j] == true) {
          bo = false;
        }
        if (b[a[i] / j] == true) {
          bo = false;
        }
      }
    }
    b[a[i]] = true;
    if (i != n - 1) {
      if (a[i] == a[i + 1]) {
        bo = false;
      }
    }
    if (bo == true) {
      co++;
    }
  }
  cout << co << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int N;
int A[100005];
int table[1000005];

int main() {

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

    table[i] = 0;
  }

  scanf("%d", &N);

  for (int i = 0; i < N; i++) {

    scanf("%d", &A[i]);
    table[A[i]]++;
  }

  if (table[1] > 0) {

    if (table[1] == 1) {

      printf("1\n");
    } else {

      printf("0\n");
    }

    return 0;
  }

  int ans = 0;

  for (int i = 0; i < N; i++) {
    if (table[A[i]] > 1)
      continue;

    bool FLG = true;
    for (int k = 2; k * k <= A[i]; k++) {
      if (A[i] % k != 0)
        continue;
      if (table[k] > 0 || table[A[i] / k] > 0) {

        FLG = false;
        break;
      }
    }
    if (FLG) {

      ans++;
    }
  }

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

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int N;
int A[200005];
int table[1000005];

int main() {

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

    table[i] = 0;
  }

  scanf("%d", &N);

  for (int i = 0; i < N; i++) {

    scanf("%d", &A[i]);
    table[A[i]]++;
  }

  if (table[1] > 0) {

    if (table[1] == 1) {

      printf("1\n");
    } else {

      printf("0\n");
    }

    return 0;
  }

  int ans = 0;

  for (int i = 0; i < N; i++) {
    if (table[A[i]] > 1)
      continue;

    bool FLG = true;
    for (int k = 2; k * k <= A[i]; k++) {
      if (A[i] % k != 0)
        continue;
      if (table[k] > 0 || table[A[i] / k] > 0) {

        FLG = false;
        break;
      }
    }
    if (FLG) {

      ans++;
    }
  }

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

  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
vector<int64_t> divisor(int64_t n) {
  vector<int64_t> ret;
  for (int64_t i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> v;
  map<long long, long long> mp3;
  map<long long, long long> mp;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    v.push_back(x);
    mp[x]++;
    mp3[x]++;
  }
  sort(v.rbegin(), v.rend());
  long long ans = 0;
  for (int iii = 0; iii < n; ++iii) {
    long long value = v[iii];

    mp[value]--;
    int ok = 1;
    if (mp3[value] == 1) {
      for (int64_t i = 1; i * i <= value; i++) {
        if (value % i == 0) {
          if (mp[i] > 0) {
            ok = 0;
            break;
          }
          if (i * i != value) {
            long long vv = value / i;
            if (mp[vv] > 0) {
              ok = 0;
              break;
            }
          }
        }
      }
    } else {
      ok = 0;
    }
    if (ok == 1)
      ++ans;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
vector<int64_t> divisor(int64_t n) {
  vector<int64_t> ret;
  for (int64_t i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> v;
  unordered_map<long long, long long> mp3;
  unordered_map<long long, long long> mp;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    v.push_back(x);
    mp[x]++;
    mp3[x]++;
  }
  sort(v.rbegin(), v.rend());
  long long ans = 0;
  for (int iii = 0; iii < n; ++iii) {
    long long value = v[iii];

    mp[value]--;
    int ok = 1;
    if (mp3[value] == 1) {
      for (int64_t i = 1; i * i <= value; i++) {
        if (value % i == 0) {
          if (mp[i] > 0) {
            ok = 0;
            break;
          }
          if (i * i != value) {
            long long vv = value / i;
            if (mp[vv] > 0) {
              ok = 0;
              break;
            }
          }
        }
      }
    } else {
      ok = 0;
    }
    if (ok == 1)
      ++ans;
  }
  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):

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

#define pb push_back
#define F first
#define S second

#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define int long long
#define ll long long

void solve() {
  int n;
  cin >> n;
  int a[n];
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    mp[a[i]]--;
    bool flag = true;
    for (int j = 1; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        if (mp[j] || mp[a[i] / j]) {
          flag = false;
          break;
        }
      }
    }
    ans += flag;
    mp[a[i]]++;
  }
  cout << ans;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}

Fixed submission:

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

#define pb push_back
#define F first
#define S second

#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define int long long
#define ll long long

void solve() {
  int n;
  cin >> n;
  int a[n];
  int mp[1000005] = {};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    mp[a[i]]--;
    bool flag = true;
    for (int j = 1; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        if (mp[j] || mp[a[i] / j]) {
          flag = false;
          break;
        }
      }
    }
    ans += flag;
    mp[a[i]]++;
  }
  cout << ans;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
#define MAXN 200007
int a[MAXN];
bool cnt[1000007];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  memset(cnt, 0, sizeof cnt);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int now = a[i];
    // ans+=cnt[now];
    if (cnt[now] == 0 && (i + 1 >= n || a[i] != a[i + 1]))
      ans++;
    for (int j = now; j <= 1000000; j += now) {
      cnt[j] = 1;
    }
  }
  cout << ans << '\n';
}


Fixed submission:
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
#define MAXN 200007
int a[MAXN];
bool cnt[1000007];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  memset(cnt, 0, sizeof cnt);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int now = a[i];
    // ans+=cnt[now];
    if (cnt[now] == 0 && (i + 1 >= n || a[i] != a[i + 1]))
      ans++;
    if (i == 0 || a[i] != a[i - 1])
      for (int j = now; j <= 1000000; j += now) {
        cnt[j] = 1;
      }
  }
  cout << ans << '\n';
}
Problem p02642 (C++)

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

using namespace std;
// https://stackoverflow.com/questions/10150468/how-to-redirect-cin-and-cout-to-files
long long not_divisible(long long n, vector<long long> a) {

  sort(a.begin(), a.end());
  const long long a_max = 1000001;
  bool div[a_max];
  memset(div, false, sizeof div);
  long long count = 0;
  if (a.size() == 1) {
    return 1;
  }
  /*
  for(auto aa = a.begin();aa != a.end();aa++) {
    cout << *aa << endl;
  }
  cout << "=========" << endl;
  */
  for (long long i = 0; i < n; i++) {
    if (i == 0) {
      if (a[i] != a[i + 1]) {
        // cout <<  a[i]<< "!!"  << endl;
        count++;
      }
      long long aa = a[i];
      while (aa < a_max) {
        div[aa] = true;
        aa += a[i];
      }
      continue;
    }
    if (i < n - 1) {
      if (a[i] != a[i - 1] && a[i + 1] != a[i] && !div[a[i]]) {
        // cout << a[i]<< "!!" << div[a[i]] << endl;
        count++;
      }
      long long aa = a[i];
      while (aa < a_max) {
        /*
        if(div[aa]) {
          break;
        }
        */
        div[aa] = true;
        aa += a[i];
      }
      continue;
    }
    // i == n-1
    if (a[i - 1] != a[i] && !div[a[i]]) {
      // cout <<  a[i]<< "!!"  << endl;
      count++;
    }
  }

  return count;
}

int main() {
  long long n;
  cin >> n;
  vector<long long> a;
  for (long long i = 0; i < n; i++) {
    long long aa;
    cin >> aa;
    a.push_back(aa);
  }
  cout << not_divisible(n, a);
}


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

using namespace std;
// https://stackoverflow.com/questions/10150468/how-to-redirect-cin-and-cout-to-files
long long not_divisible(long long n, vector<long long> a) {

  sort(a.begin(), a.end());
  const long long a_max = 1000001;
  bool div[a_max];
  memset(div, false, sizeof div);
  long long count = 0;
  if (a.size() == 1) {
    return 1;
  }
  /*
  for(auto aa = a.begin();aa != a.end();aa++) {
    cout << *aa << endl;
  }
  cout << "=========" << endl;
  */
  for (long long i = 0; i < n; i++) {
    if (i == 0) {
      if (a[i] != a[i + 1]) {
        // cout <<  a[i]<< "!!"  << endl;
        count++;
      }
      long long aa = a[i];
      while (aa < a_max) {
        div[aa] = true;
        aa += a[i];
      }
      continue;
    }
    if (i < n - 1) {
      if (a[i] != a[i - 1] && a[i + 1] != a[i] && !div[a[i]]) {
        // cout << a[i]<< "!!" << div[a[i]] << endl;
        count++;
      }
      if (a[i] == a[i - 1]) {
        continue;
      }
      long long aa = a[i];
      while (aa < a_max) {
        /*
        if(div[aa]) {
          break;
        }
        */
        div[aa] = true;
        aa += a[i];
      }
      continue;
    }
    // i == n-1
    if (a[i - 1] != a[i] && !div[a[i]]) {
      // cout <<  a[i]<< "!!"  << endl;
      count++;
    }
  }

  return count;
}

int main() {
  long long n;
  cin >> n;
  vector<long long> a;
  for (long long i = 0; i < n; i++) {
    long long aa;
    cin >> aa;
    a.push_back(aa);
  }
  cout << not_divisible(n, a);
}
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>;
#define chmax(x, y) x = max(x, y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

vector<int> d(1000005);

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  int ans = 0;
  for (int x : a) {
    for (int j = x; j <= 1000000; j += x) {
      d[j]++;
    }
  }
  for (int x : a) {
    if (d[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>;
#define chmax(x, y) x = max(x, y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

vector<int> d(1000005);

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  int ans = 0;
  for (int x : a) {
    if (d[x] != 0) {
      d[x]++;
      continue;
    }
    for (int j = x; j <= 1000000; j += x) {
      d[j]++;
    }
  }
  for (int x : a) {
    if (d[x] == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, j, n) for (ll i = j; i < n; i++)
#define all(vec) vec.begin(), vec.end()
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const ll INF = 1LL << 60;

int main() {
  int n;
  cin >> n;
  vector<bool> b(1000001);
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) {
    int x = 2;
    while (a[i] * x <= 1000000) {
      b[a[i] * x] = 1;
      x++;
    }
  }
  vector<int> d(1000001);
  rep(i, n) d[a[i]]++;
  rep(i, 1000001) if (d[i] > 1) b[i] = 1;
  int ans = 0;
  rep(i, n) if (!b[a[i]]) ans++;
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, j, n) for (ll i = j; i < n; i++)
#define all(vec) vec.begin(), vec.end()
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const ll INF = 1LL << 60;

int main() {
  int n;
  cin >> n;
  vector<bool> b(1000001);
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int cnt = 0;
  rep(i, n) if (a[i] == 1) cnt++;
  if (cnt == 1) {
    cout << 1 << endl;
    return 0;
  }
  if (cnt > 1) {
    cout << 0 << endl;
    return 0;
  }
  rep(i, n) {
    int x = 2;
    while (a[i] * x <= 1000000) {
      b[a[i] * x] = 1;
      x++;
    }
  }
  vector<int> d(1000001);
  rep(i, n) d[a[i]]++;
  rep(i, 1000001) if (d[i] > 1) b[i] = 1;
  int ans = 0;
  rep(i, n) if (!b[a[i]]) ans++;
  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<int> cnt(1000001);
  for (int i = 0; i < n; i++) {
    for (int j = a[i]; j < cnt.size(); 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 <bits/stdc++.h>
using namespace std;
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());
  vector<int> cnt(a[n - 1] + 1);
  for (int i = 0; i < n; i++) {
    for (int j = a[i]; j < cnt.size(); 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 pb push_back
#define ll long long
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int, int>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> v(n + 1), vis(1000009);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  sort(v.begin(), v.begin() + n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (vis[v[i]])
      continue;
    if (v[i + 1] != v[i])
      ans++;
    for (int j = i; j <= 1000000; j += i)
      vis[j] = 1;
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int, int>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> v(n + 1), vis(1000009);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  sort(v.begin(), v.begin() + n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (vis[v[i]])
      continue;
    if (v[i + 1] != v[i])
      ans++;
    for (int j = v[i]; j <= 1000000; j += v[i])
      vis[j] = 1;
  }
  cout << ans;
}
Problem p02642 (C++)

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

int main() {
  int t = 1;
  cin >> t;

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

    vector<ll> arr(n);
    map<ll, bool> ch;

    for (ll i = 0; i < n; i++)
      cin >> arr[i], ch[arr[i]] = 0;

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

    for (ll i = 0; i < n; i++) {
      if (ch[arr[i]])
        continue;

      for (ll j = 2; arr[i] * j <= arr[n - 1]; j++)
        ch[arr[i] * j] = 1;
    }

    ll ans = 0;

    for (int i = 0; i < n; i++) {
      if (ch[arr[i]])
        continue;
      if (i > 0 && arr[i - 1] == arr[i])
        continue;
      if (i < n - 1 && arr[i + 1] == arr[i])
        continue;
      ans++;
    }

    cout << ans;
  }
  return 0;
}


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

int main() {
  int t = 1;
  // cin>>t;

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

    vector<ll> arr(n);
    map<ll, bool> ch;

    for (ll i = 0; i < n; i++)
      cin >> arr[i], ch[arr[i]] = 0;

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

    for (ll i = 0; i < n; i++) {
      if (ch[arr[i]])
        continue;

      for (ll j = 2; arr[i] * j <= arr[n - 1]; j++)
        ch[arr[i] * j] = 1;
    }

    ll ans = 0;

    for (int i = 0; i < n; i++) {
      if (ch[arr[i]])
        continue;
      if (i > 0 && arr[i - 1] == arr[i])
        continue;
      if (i < n - 1 && arr[i + 1] == arr[i])
        continue;
      ans++;
    }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
int main() {
  long long n;
  scanf("%lld", &n);
  long long b[200001] = {0};
  long long i, j, jmax, p;
  vector<long long> a;
  for (i = 0; i < n; i++) {
    scanf(" %lld", &p);
    b[p]++;
    a.push_back(p);
  }
  sort(a.begin(), a.end());
  long long ans = 0, max = a[n - 1];
  for (i = 0; i <= max; i++) {
    if (b[i] == 1)
      ans++;
    if (i != 0)
      jmax = max / i;
    if (i == 0)
      jmax = 1;
    if (b[i] != 0) {
      for (j = 0; j <= jmax; j++)
        b[i * j] = 0;
    }
  }

  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
int main() {
  long long n;
  scanf("%lld", &n);
  long long b[20000001] = {0};
  long long i, j, jmax, p;
  vector<long long> a;
  for (i = 0; i < n; i++) {
    scanf(" %lld", &p);
    b[p]++;
    a.push_back(p);
  }
  sort(a.begin(), a.end());
  long long ans = 0, max = a[n - 1];
  for (i = 0; i <= max; i++) {
    if (b[i] == 1)
      ans++;
    if (i != 0)
      jmax = max / i;
    if (i == 0)
      jmax = 1;
    if (b[i] != 0) {
      for (j = 0; j <= jmax; j++)
        b[i * j] = 0;
    }
  }

  printf("%lld\n", ans);
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll n;
  cin >> n;
  ll arr[n];
  int cnt[1000002] = {0};
  bool vis[1000002] = {0};
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    cnt[arr[i]]++;
    if (vis[arr[i]] == 0) {
      for (int j = 2 * arr[i]; j <= 1000000; j += arr[i]) {
        vis[j] = 1;
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (vis[arr[i]] == 0 && cnt[arr[i]] == 1) {
      ans++;
    }
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll n;
  cin >> n;
  ll arr[n];
  int cnt[1000002] = {0};
  bool vis[1000002] = {0};
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    cnt[arr[i]]++;
    if (vis[arr[i]] == 0 && cnt[arr[i]] == 1) {
      for (int j = 2 * arr[i]; j <= 1000000; j += arr[i]) {
        vis[j] = 1;
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (vis[arr[i]] == 0 && cnt[arr[i]] == 1) {
      ans++;
    }
  }
  cout << ans;
  return 0;
}
Problem p02642 (C++)

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

typedef long long ll;
typedef pair<int, int> ii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

const int mx = 2e5 + 777;
int flag[mx];

int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int N, A;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A, flag[A]++;
  int ret = 0;
  for (int i = 1; i < mx; i++) {
    if (flag[i]) {
      if (flag[i] == 1)
        ret++;
      for (int j = 2 * i; j < mx; j += i)
        flag[j] = false;
    }
  }
  cout << ret << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

const int mx = 1e6 + 777;
int flag[mx];

int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int N, A;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A, flag[A]++;
  int ret = 0;
  for (int i = 1; i < mx; i++) {
    if (flag[i]) {
      if (flag[i] == 1)
        ret++;
      for (int j = 2 * i; j < mx; j += i)
        flag[j] = false;
    }
  }
  cout << ret << "\n";
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define inf 1000000000000000000
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(), (x).end()
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 main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(15) << fixed;

  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  map<ll, ll> Counter;
  vector<bool> ans(1000001, true);
  for (auto i : A) {
    Counter[i]++;
    for (ll j = 2 * i; j < 1000001; j += i) {
      ans[j] = false;
    }
  }

  ll cnt = 0;
  for (auto i : A) {
    if (ans[i] && Counter[i] == 1)
      cnt++;
  }

  cout << cnt << endl;
}


Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define inf 1000000000000000000
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(), (x).end()
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 main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(15) << fixed;

  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  map<ll, ll> Counter;
  vector<bool> ans(1000001, true);
  for (auto i : A) {
    Counter[i]++;
    if (Counter[i] > 1)
      continue;
    for (ll j = 2 * i; j < 1000001; j += i) {
      ans[j] = false;
    }
  }

  ll cnt = 0;
  for (auto i : A) {
    if (ans[i] && Counter[i] == 1)
      cnt++;
  }

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

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

int n, a[200010], ans = 0;
bool f[200010] = {};

int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  int i, j;
  for (i = 1; i <= n; ++i)
    cin >> a[i];
  sort(a + 1, a + 1 + n);
  for (i = 1; i <= n; ++i) {
    if (!f[a[i]]) {
      ++ans;
      for (j = 1; j * a[i] <= a[n]; ++j)
        f[a[i] * j] = 1;
      if (a[i] == a[i + 1])
        --ans;
    }
  }
  cout << ans;

  return 0;
}

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

int n, a[200010], ans = 0;
bool f[2000010] = {};

int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  int i, j;
  for (i = 1; i <= n; ++i)
    cin >> a[i];
  sort(a + 1, a + 1 + n);
  for (i = 1; i <= n; ++i) {
    if (!f[a[i]]) {
      ++ans;
      for (j = 1; j * a[i] <= a[n]; ++j)
        f[a[i] * j] = 1;
      if (a[i] == a[i + 1])
        --ans;
    }
  }
  cout << ans;

  return 0;
}
Problem p02642 (C++)

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

#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define endl "\n"
#define int long long

int32_t main() {
  IOS;
  int n;
  cin >> n;
  vector<bool> pos(1000005, false);
  vector<int> tot(1000005, 0);
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];

  for (int i = 0; i < n; i++) {
    int cur = arr[i];
    tot[cur]++;
    if (pos[cur] == false) {
      for (int j = 2 * cur; j < pos.size(); j += cur)
        pos[j] = true;
    }
  }

  int cnt = 0;
  for (int i = 0; i < n; i++)
    if (pos[arr[i]] == false && tot[arr[i]] == 1)
      cnt++;

  cout << cnt << endl;
  return 0;
}

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

#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define endl "\n"
#define int long long

int32_t main() {
  IOS;
  int n;
  cin >> n;
  vector<bool> pos(1000005, false);
  vector<int> tot(1000005, 0);
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];

  for (int i = 0; i < n; i++) {
    int cur = arr[i];
    tot[cur]++;
    if (pos[cur] == false && tot[cur] == 1) {
      for (int j = 2 * cur; j < pos.size(); j += cur)
        pos[j] = true;
    }
  }

  int cnt = 0;
  for (int i = 0; i < n; i++)
    if (pos[arr[i]] == false && tot[arr[i]] == 1)
      cnt++;

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

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

const int MAX = 1000005;

int main() {

  int N;
  cin >> N;

  vector<int> cnt(MAX);
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    int x = 0;
    while (x + A[i] < MAX) {
      x += A[i];
      cnt[x]++;
    }
  }

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

  cout << ans << endl;

  return 0;
}

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

const int MAX = 1000005;

int main() {

  int N;
  cin >> N;

  vector<int> cnt(MAX);
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    int x = 0;
    if (cnt[A[i]] != 0) {
      cnt[A[i]]++;
      continue;
    }
    while (x + A[i] < MAX) {
      x += A[i];
      cnt[x]++;
    }
  }

  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>
#include <math.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++)
using ll = long long;
using vec = vector<int>;
using vec2 = vector<vector<int>>;

int main() {
  int n;
  cin >> n;
  int g = pow(10, 6);
  vec d(g);
  vec a(n);
  rep(i, n) { cin >> a[i]; }
  for (int x : a) {

    for (int i = x; i <= g; i += x) {
      d[i]++;
    }
  }
  int sum = 0;
  for (int x : a) {
    if (d[x] == 1) {
      sum++;
    }
  }
  cout << sum << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#include <math.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++)
using ll = long long;
using vec = vector<int>;
using vec2 = vector<vector<int>>;

int main() {
  int n;
  cin >> n;
  int g = pow(10, 6);
  vec d(g);
  vec a(n);
  rep(i, n) { cin >> a[i]; }
  for (int x : a) {
    if (d[x] != 0) {
      d[x] = 2;
      continue;
    }
    for (int i = x; i <= g; i += x) {
      d[i]++;
    }
  }
  int sum = 0;
  for (int x : a) {
    if (d[x] == 1) {
      sum++;
    }
  }
  cout << sum << endl;
}
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>;

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

  vector<int> A(N);
  vector<int> dp(1000000 + 1);
  rep(i, N) { cin >> A.at(i); }
  rep(i, N) {
    int tmp = A.at(i);
    while (tmp <= 1000000) {
      dp.at(tmp)++;
      tmp += A.at(i);
    }
  }
  int count = 0;
  rep(i, N) {
    // cout << A.at(i) << ' ' << dp.at(A.at(i)) << endl;
    if (dp.at(A.at(i)) == 1) {
      count++;
    }
  }
  cout << count << endl;
}

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>;

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

  vector<int> A(N);
  vector<int> dp(1000000 + 1);
  rep(i, N) { cin >> A.at(i); }
  rep(i, N) {
    if (dp.at(A.at(i)) > 1) {
      continue;
    }

    int tmp = A.at(i);
    while (tmp <= 1000000) {
      dp.at(tmp)++;
      tmp += A.at(i);
    }
  }
  int count = 0;
  rep(i, N) {
    // cout << A.at(i) << ' ' << dp.at(A.at(i)) << endl;
    if (dp.at(A.at(i)) == 1) {
      count++;
    }
  }
  cout << count << endl;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
template <class A> void PR(A a, ll n) {
  rep(i, n) {
    if (i)
      cout << ' ';
    cout << a[i];
  }
  cout << "\n";
}
ld PI = 3.14159265358979323846;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N), v(1000010);
  rep(i, N) { cin >> A[i]; }
  ll ans = 0;
  rep(i, N) {
    ll t = A[i];
    while (t < 1000010) {
      v[t]++;
      t += A[i];
    }
  }
  rep(i, N) {
    if (v[A[i]] == 1)
      ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
template <class A> void PR(A a, ll n) {
  rep(i, n) {
    if (i)
      cout << ' ';
    cout << a[i];
  }
  cout << "\n";
}
ld PI = 3.14159265358979323846;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N), v(1000010);
  rep(i, N) { cin >> A[i]; }
  ll ans = 0;
  rep(i, N) {
    ll t = A[i];
    if (v[t] != 0) {
      v[t]++;
      continue;
    }
    while (t < 1000010) {
      v[t]++;
      t += A[i];
    }
  }
  rep(i, N) {
    if (v[A[i]] == 1)
      ans++;
  }
  cout << ans << endl;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
// Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
// Men at Work :)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x) __builtin_popcountll(x)
#define mod 1000000007
#define ps(x, y) fixed << setprecision(y) << x
#define w(x)                                                                   \
  int x;                                                                       \
  cin >> x;                                                                    \
  while (x--)
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds;

void cpp() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main() {
  cpp();
  ll n;
  cin >> n;
  vector<ll> v(n);
  for (ll i = 0; i < n; i++) {
    cin >> v[i];
  }
  vector<ll> num(1000020);
  sort(v.begin(), v.end());
  for (ll i = 0; i < n - 1; i++) {
    if (v[i] == v[i + 1]) {
      num[v[i]] = 1;
    }
  }
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    if (!num[v[i]]) {
      ans++;
    }
    for (ll j = 2 * v[i]; j <= 1000000; j += v[i]) {
      num[j] = 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
// Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
// Men at Work :)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x) __builtin_popcountll(x)
#define mod 1000000007
#define ps(x, y) fixed << setprecision(y) << x
#define w(x)                                                                   \
  int x;                                                                       \
  cin >> x;                                                                    \
  while (x--)
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds;

void cpp() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main() {
  cpp();
  ll n;
  cin >> n;
  vector<ll> v(n);
  for (ll i = 0; i < n; i++) {
    cin >> v[i];
  }
  vector<ll> num(1000020);
  sort(v.begin(), v.end());
  for (ll i = 0; i < n - 1; i++) {
    if (v[i] == v[i + 1]) {
      num[v[i]] = 1;
    }
  }
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    if (!num[v[i]]) {
      ans++;
    }
    if (v[i] != v[i - 1]) {
      for (ll j = 2 * v[i]; j <= 1000000; j += v[i]) {
        num[j] = 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;

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;
}
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> num(1e6 + 1, 0);
  rep(i, n) {
    scanf("%d", &a[i]);
    num[a[i]]++;
  }
  sort(all(a));
  int ans = 0;
  vector<vector<int>> each_divs;
  rep(i, n) {
    vector<int> tmp_div;
    for (int j = 1; j * j <= a[i]; ++j) {
      if (a[i] % j == 0) {
        tmp_div.push_back(j);
        if (j * j != a[i]) {
          tmp_div.push_back(a[i] / j);
        }
      }
    }
    if (num[a[i]] >= 2) {
      continue;
    }
    bool flag = true;
    for (auto e : tmp_div) {
      if (e == a[i]) {
        continue;
      }
      if (find(all(a), e) != a.end()) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans++;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;

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;
}
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> num(1e6 + 1, 0);
  rep(i, n) {
    scanf("%d", &a[i]);
    num[a[i]]++;
  }
  sort(all(a));
  int ans = 0;
  vector<vector<int>> each_divs;
  rep(i, n) {
    vector<int> tmp_div;
    for (int j = 1; j * j <= a[i]; ++j) {
      if (a[i] % j == 0) {
        tmp_div.push_back(j);
        if (j * j != a[i]) {
          tmp_div.push_back(a[i] / j);
        }
      }
    }
    if (num[a[i]] >= 2) {
      continue;
    }
    bool flag = true;
    for (auto e : tmp_div) {
      if (e == a[i]) {
        continue;
      }
      if (num[e]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02642 (C++)

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

using namespace std;

#define int long long
#define fast()                                                                 \
  ios_base ::sync_with_stdio(0);                                               \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define all(v) v.begin(), v.end()
#define ff first
#define ss second
#define out(x) cerr << #x << " is : " << x << endl
#define endl "\n"
#define mem(f, v) memset(f, v, sizeof f)

const int N = 1e5 + 10;

void up() {
  int n;
  cin >> n;
  int f[N], a[n];
  mem(f, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    f[a[i]]++;
  }
  bool cond = false;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    f[a[i]]--;
    cond = true;
    for (int j = 1; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        if (f[j] or f[a[i] / j]) {
          cond = false;
          break;
        }
      }
    }
    f[a[i]]++;
    if (cond)
      cnt++;
  }

  cout << cnt << endl;
  return;
}

int32_t main() {
  fast();
  up();
  return 0;
}


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

using namespace std;

#define int long long
#define fast()                                                                 \
  ios_base ::sync_with_stdio(0);                                               \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define all(v) v.begin(), v.end()
#define ff first
#define ss second
#define out(x) cerr << #x << " is : " << x << endl
#define endl "\n"
#define mem(f, v) memset(f, v, sizeof f)

const int N = 1e6 + 10;

void up() {
  int n;
  cin >> n;
  int f[N], a[n];
  mem(f, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    f[a[i]]++;
  }
  bool cond = false;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    f[a[i]]--;
    cond = true;
    for (int j = 1; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        if (f[j] or f[a[i] / j]) {
          cond = false;
          break;
        }
      }
    }
    f[a[i]]++;
    if (cond)
      cnt++;
  }

  cout << cnt << endl;
  return;
}

int32_t main() {
  fast();
  up();
  return 0;
}
Problem p02642 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> A.at(i);
  }

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

  vector<int> B(1000000);

  for (int i = 1; i <= N; i++) {
    int x = A.at(i);
    for (int j = 1; j <= A.back() / A.at(i); j++) {
      B.at(x * j)++;
    }
  }
  int ans = 0;
  for (auto i = 1; i <= N; i++) {
    if (B.at(A.at(i)) == 1)
      ans++;
  }
  cout << ans << endl;
}


Fixed submission:
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> A.at(i);
  }

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

  vector<int> B(10000000);

  for (int i = 1; i <= N; i++) {
    int x = A.at(i);
    for (int j = 1; j <= A.back() / A.at(i); j++) {
      B.at(x * j)++;
    }
  }
  int ans = 0;
  for (auto i = 1; i <= N; i++) {
    if (B.at(A.at(i)) == 1)
      ans++;
  }
  cout << ans << endl;
}
Problem p02642 (C++)

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

int main() {

  long long N;
  cin >> N;

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

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

  vector<int> S(1000010);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int num = A[i];
    for (int j = num; j < 1000010; j += num)
      S[j]++;
  }

  for (int i = 0; i < N; i++) {
    if (S[A[i]] == 1)
      ans++;
  }

  cout << ans << endl;
}


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

int main() {

  long long N;
  cin >> N;

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

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

  vector<int> S(1000010);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int num = A[i];
    if (S[num] != 0) {
      S[num] = 2;
      continue;
    }
    for (int j = num; j < 1000010; j += num)
      S[j]++;
  }

  for (int i = 0; i < N; i++) {
    if (S[A[i]] == 1)
      ans++;
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define AMAX 1000005
int main() {
  int n;
  cin >> n;
  int value;
  int cnt[1000001];
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> value;
    a[i] = value;
    if (cnt[value] != 0) {
      cnt[value] = 2;
      continue;
    }
    for (int j = value; j < AMAX; j += value) {
      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 <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define AMAX 1000005
int main() {
  int n;
  cin >> n;
  int value;
  int cnt[AMAX];
  for (int i = 0; i < AMAX; i++)
    cnt[i] = 0;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> value;
    a[i] = value;
    if (cnt[value] != 0) {
      cnt[value] = 2;
      continue;
    }
    for (int j = value; j < AMAX; j += value) {
      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>

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  std::map<int, int> cnt;
  rep(i, N) {
    std::cin >> A[i];
    ++cnt[A[i]];
  }
  std::sort(A.begin(), A.end());

  std::vector<bool> dp(1000001, true);

  int ans = 0;
  rep(i, N) {
    if (!dp[A[i]])
      continue;
    if (cnt[A[i]] == 1) {
      ++ans;
    }
    int sub = 2 * A[i];
    while (sub <= 1000000) {
      dp[sub] = false;
      sub += A[i];
    }
  }

  std::cout << ans << '\n';
}


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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  std::map<int, int> cnt;
  rep(i, N) {
    std::cin >> A[i];
    ++cnt[A[i]];
  }
  std::sort(A.begin(), A.end());

  std::vector<bool> dp(1000001, true);

  int ans = 0;
  rep(i, N) {
    if (!dp[A[i]])
      continue;
    if (cnt[A[i]] == 1) {
      ++ans;
    }
    int sub = A[i];
    while (sub <= 1000000) {
      dp[sub] = false;
      sub += A[i];
    }
  }

  std::cout << ans << '\n';
}