problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define sync \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define rep(i, n) for (int i = 0; i < int(n); ++i) #define repp(i, a, n) for (int i = a; i < int(n); ++i) #define sz(x) (x).size() #define pq priority_queue #define pb push_back #define mp make_pair #define dbg(x) cerr << #x " = " << x << endl #define debug(...) fprintf(stderr, __VA_ARGS__) template <class T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &input) { for (auto const &i : input) { os << i << " "; } return os; } template <class T1, class T2> std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &input) { os << "(" << input.first << ", " << input.second << ')'; return os; } typedef long long ll; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<pi> vp; typedef vector<ll> vl; typedef vector<vi> vvi; const int maxn = 1e6; void pre() {} int vis[maxn + 1]; int cnt[maxn + 1]; void solve() { int n; cin >> n; vp a(0); rep(i, n) { int x; cin >> x; a.pb(mp(x, i)); cnt[x]++; } sort(a.begin(), a.end()); int ans = 0; for (auto p : a) { int val = p.first; int i = p.second; if (cnt[val] == 1 && vis[val] == 0) { ans++; } for (int j = val; j <= maxn; j += val) vis[j] = 1; } cout << ans; } int main() { sync; int cas = 1; // cin >> cas; pre(); rep(ca, cas) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define sync \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define rep(i, n) for (int i = 0; i < int(n); ++i) #define repp(i, a, n) for (int i = a; i < int(n); ++i) #define sz(x) (x).size() #define pq priority_queue #define pb push_back #define mp make_pair #define dbg(x) cerr << #x " = " << x << endl #define debug(...) fprintf(stderr, __VA_ARGS__) template <class T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &input) { for (auto const &i : input) { os << i << " "; } return os; } template <class T1, class T2> std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &input) { os << "(" << input.first << ", " << input.second << ')'; return os; } typedef long long ll; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<pi> vp; typedef vector<ll> vl; typedef vector<vi> vvi; const int maxn = 1e6; void pre() {} int vis[maxn + 1]; int cnt[maxn + 1]; void solve() { int n; cin >> n; vp a(0); rep(i, n) { int x; cin >> x; a.pb(mp(x, i)); cnt[x]++; } sort(a.begin(), a.end()); int ans = 0; for (auto p : a) { int val = p.first; int i = p.second; if (cnt[val] == 1 && vis[val] == 0) { ans++; } if (vis[val] == 0) { for (int j = val; j <= maxn; j += val) vis[j] = 1; } } cout << ans; } int main() { sync; int cas = 1; // cin >> cas; pre(); rep(ca, cas) solve(); return 0; }
replace
66
68
66
70
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> // Begin Header {{{ using namespace std; using ll = long long; using P = pair<ll, ll>; using Graph = vector<vector<ll>>; #define rep(i, n) for (ll i = 0; i < n; i++) #define loop(i, j, n) for (ll i = j; i < n; i++) #define all(x) (x).begin(), (x).end() constexpr int INF = 0x3f3f3f3f; const long long mod = 1e9 + 7; const long double PI = acos(-1); // }}} End Header int main() { int n; const int M = 100000005; 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 k = x; k < M; k += x) cnt[k]++; } int ans = 0; for (int x : a) { if (cnt[x] == 1) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> // Begin Header {{{ using namespace std; using ll = long long; using P = pair<ll, ll>; using Graph = vector<vector<ll>>; #define rep(i, n) for (ll i = 0; i < n; i++) #define loop(i, j, n) for (ll i = j; i < n; i++) #define all(x) (x).begin(), (x).end() constexpr int INF = 0x3f3f3f3f; const long long mod = 1e9 + 7; const long double PI = acos(-1); // }}} End Header int main() { int n; const int M = 1000099; 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 k = x; k < M; k += x) cnt[k]++; } int ans = 0; for (int x : a) { if (cnt[x] == 1) ans++; } cout << ans << endl; return 0; }
replace
16
17
16
17
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); typedef long long ll; typedef long double ld; const ll MOD = 1E9 + 7, INF = 2E18 + 5; const double PI = 2 * acos(0.0); const long double EPS = 1.0E-14; ll arr[200005]; map<ll, ll> mp; int main() { ll n, cnt = 0, limit, flag = 0; cin >> n; for (int i = 0; i < n; i++) { scanf("%lld", &arr[i]); mp[arr[i]]++; } for (int i = 0; i < n; i++) { flag = 0; mp[arr[i]]--; for (int j = 1; j * j <= arr[i]; j++) { if (arr[i] % j == 0) { if (mp[j] > 0 or mp[arr[i] / j] > 0) { flag = 1; break; } } } if (!flag) cnt++; mp[arr[i]]++; } cout << cnt; return 0; }
#include <bits/stdc++.h> using namespace std; #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); typedef long long ll; typedef long double ld; const ll MOD = 1E9 + 7, INF = 2E18 + 5; const double PI = 2 * acos(0.0); const long double EPS = 1.0E-14; ll arr[200005]; unordered_map<ll, ll> mp; int main() { ll n, cnt = 0, limit, flag = 0; cin >> n; for (int i = 0; i < n; i++) { scanf("%lld", &arr[i]); mp[arr[i]]++; } for (int i = 0; i < n; i++) { flag = 0; mp[arr[i]]--; for (int j = 1; j * j <= arr[i]; j++) { if (arr[i] % j == 0) { if (mp[j] > 0 or mp[arr[i] / j] > 0) { flag = 1; break; } } } if (!flag) cnt++; mp[arr[i]]++; } cout << cnt; return 0; }
replace
15
16
15
16
TLE
p02642
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <vector> int main() { int n; std::cin >> n; std::vector<int> A; std::vector<int> Done; int maxa = 0; for (int i = 0; i < n; i++) { int a; std::cin >> a; maxa = std::max(maxa, a); A.push_back(a); } std::sort(A.begin(), A.end()); bool not_dividable[maxa + 1]; for (int i = 0; i <= maxa; i++) not_dividable[i] = true; for (int i = 0; i < n; i++) { int idx = A.at(i); if (not_dividable[idx]) { if (i < n - 1 && A.at(i) == A.at(i + 1)) not_dividable[idx] = false; for (int j = 2 * idx; j <= maxa; j += idx) not_dividable[j] = false; } } int ans = 0; for (int i = 0; i < n; i++) { if (std::find(Done.begin(), Done.end(), A.at(i)) != Done.end()) continue; if (not_dividable[A.at(i)]) { ++ans; Done.push_back(A.at(i)); } } std::cout << ans << '\n'; }
#include <algorithm> #include <iostream> #include <vector> int main() { int n; std::cin >> n; std::vector<int> A; std::vector<int> Done; int maxa = 0; for (int i = 0; i < n; i++) { int a; std::cin >> a; maxa = std::max(maxa, a); A.push_back(a); } std::sort(A.begin(), A.end()); bool not_dividable[maxa + 1]; for (int i = 0; i <= maxa; i++) not_dividable[i] = true; for (int i = 0; i < n; i++) { int idx = A.at(i); if (not_dividable[idx]) { if (i < n - 1 && A.at(i) == A.at(i + 1)) not_dividable[idx] = false; for (int j = 2 * idx; j <= maxa; j += idx) not_dividable[j] = false; } } int ans = 0; for (int i = 0; i < n; i++) { if (not_dividable[A.at(i)]) { ++ans; Done.push_back(A.at(i)); } } std::cout << ans << '\n'; }
delete
31
33
31
31
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; typedef long long ll; typedef long double ld; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) #define F first #define S second constexpr char ln = '\n'; const int mx = 100010; const ll mod = 1e9 + 7; int main() { int n; cin >> n; vector<int> a(n); unordered_map<int, int> mp; rep(i, n) { cin >> a[i]; mp[a[i]]++; } sort(a.begin(), a.end()); if (a[0] == 1) { if (a[1] == 1) { cout << 0 << ln; return 0; } else { cout << 1 << ln; return 0; } } vector<bool> d(1000010, true); int ans = 0; rep(i, n) { if (mp[a[i]] == 1 && d[a[i]]) { ans++; } for (int i = 1; i * a[i] < 1000001; i++) { d[a[i] * i] = false; } } cout << ans << ln; return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; typedef long long ll; typedef long double ld; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) #define F first #define S second constexpr char ln = '\n'; const int mx = 100010; const ll mod = 1e9 + 7; int main() { int n; cin >> n; vector<int> a(n); unordered_map<int, int> mp; rep(i, n) { cin >> a[i]; mp[a[i]]++; } sort(a.begin(), a.end()); if (a[0] == 1) { if (a[1] == 1) { cout << 0 << ln; return 0; } else { cout << 1 << ln; return 0; } } vector<bool> d(1000010, true); int ans = 0; rep(i, n) { if (mp[a[i]] == 1 && d[a[i]]) { ans++; } for (int j = 1; j * a[i] < 1000001; j++) { d[a[i] * j] = false; } } cout << ans << ln; return 0; }
replace
42
44
42
44
0
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; void seive(vector<int> &fact, int n, vector<int> a, int r) { int i = 0; while (i < n) { int k = a[i]; for (int j = k; j <= r; j += k) { // cout<<j<<endl; fact[j]++; } i++; } } int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int r = a[n - 1]; vector<int> fact(r + 1, 0); seive(fact, n, a, r); int cnt = 0; for (int i = 0; i < n; i++) { if (fact[a[i]] < 2) cnt++; } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; void seive(vector<int> &fact, int n, vector<int> a, int r) { int i = 0; while (i < n) { int k = a[i]; for (int j = k; j <= r; j += k) { // cout<<j<<endl; fact[j]++; } i++; } } int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); int r = a[n - 1]; vector<int> fact(r + 1, 0); seive(fact, n, a, r); int cnt = 0; for (int i = 0; i < n; i++) { if (fact[a[i]] < 2) cnt++; } cout << cnt << endl; return 0; }
insert
27
27
27
28
0
p02642
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> A(100001, 0); vector<int> has(1000001, 0); for (int i = 0; i < N; i++) { cin >> A[i]; } sort(A.begin(), A.begin() + N); /*for(int i = 0; i < N; i++){ cout << A[i] << endl; }*/ int ans = 0; for (int i = 0; i < N; i++) { if (i < N - 1 && A[i] != A[i + 1]) { if (has[A[i]] == 0) ans++; } else if (i == N - 1) { if (has[A[i]] == 0) ans++; } for (int t = A[i]; t <= A[N - 1]; t += A[i]) { has[t] = 1; } } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> A(2 * 100001, 0); vector<int> has(1000001, 0); for (int i = 0; i < N; i++) { cin >> A[i]; } sort(A.begin(), A.begin() + N); /*for(int i = 0; i < N; i++){ cout << A[i] << endl; }*/ int ans = 0; for (int i = 0; i < N; i++) { if (i < N - 1 && A[i] != A[i + 1]) { if (has[A[i]] == 0) ans++; } else if (i == N - 1) { if (has[A[i]] == 0) ans++; } for (int t = A[i]; t <= A[N - 1]; t += A[i]) { has[t] = 1; } } cout << ans << endl; return 0; }
replace
12
13
12
13
0
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define all(n) begin(n), end(n) const long long INF = numeric_limits<long long>::max(); typedef long long ll; typedef vector<int> vint; typedef vector<vector<int>> vvint; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef unsigned long long ull; 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; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } vint primes; vll div(ll N) { vll yakusuu; for (ll i = 1; i * i <= N; i++) { if (N % i == 0) { yakusuu.push_back(i); if (i * i != N) yakusuu.push_back(N / i); } } return yakusuu; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vint A(N); set<int> s; map<int, int> cnt; for (size_t i = 0; i < N; i++) { cin >> A[i]; s.insert(A[i]); cnt[A[i]]++; } int ans = N; for (size_t i = 0; i < A.size(); i++) { if (cnt[A[i]] >= 2) { ans--; continue; } auto divs = div(A[i]); for (auto &&j : divs) { if (j != A[i] and s.count(j) == 1) { ans--; break; } } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define all(n) begin(n), end(n) const long long INF = numeric_limits<long long>::max(); typedef long long ll; typedef vector<int> vint; typedef vector<vector<int>> vvint; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef unsigned long long ull; 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; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } vint primes; vll div(ll N) { vll yakusuu; for (ll i = 1; i * i <= N; i++) { if (N % i == 0) { yakusuu.push_back(i); if (i * i != N) yakusuu.push_back(N / i); } } return yakusuu; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vint A(N); set<int> s; vint cnt(1e6 + 1); for (size_t i = 0; i < N; i++) { cin >> A[i]; s.insert(A[i]); cnt[A[i]]++; } int ans = N; for (size_t i = 0; i < A.size(); i++) { if (cnt[A[i]] >= 2) { ans--; continue; } auto divs = div(A[i]); for (auto &&j : divs) { if (j != A[i] and s.count(j) == 1) { ans--; break; } } } cout << ans; return 0; }
replace
59
60
59
60
TLE
p02642
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; #define INF = 1000000100; #define rep(i, n) for (int i = 0; i < n; i++) const int M = 1000005; int main() { int N; cin >> N; vector<int> a; 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; }
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; #define INF = 1000000100; #define rep(i, n) for (int i = 0; i < n; i++) 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; }
replace
21
22
21
22
-11
p02642
Python
Time Limit Exceeded
N = int(input()) X = list(map(int, input().split())) MAX = 10**6 + 1 prime = [True] * MAX counted = set() for v in X: if v in counted: prime[v] = False for j in range(2 * v, MAX, v): prime[j] = False counted.add(v) ans = 0 for v in X: ans += int(prime[v]) print(ans)
N = int(input()) X = list(map(int, input().split())) MAX = 10**6 + 1 prime = [True] * MAX counted = set() for v in X: if v in counted: prime[v] = False continue for j in range(2 * v, MAX, v): prime[j] = False counted.add(v) ans = 0 for v in X: ans += int(prime[v]) print(ans)
insert
9
9
9
10
TLE
p02642
Python
Time Limit Exceeded
n = int(input()) a = list(map(int, input().split())) a.sort() flag = False b = [False] * 1000010 for i in range(n - 1): if a[i] == a[i + 1]: for j in range(a[i], 1000010, a[i]): b[j] = True ans = 0 for i in range(n): if not b[a[i]]: ans += 1 for j in range(a[i], 1000010, a[i]): b[j] = True print(ans)
n = int(input()) a = list(map(int, input().split())) a.sort() flag = False b = [False] * 1000010 for i in range(n - 1): if a[i] == a[i + 1]: if b[a[i]]: continue for j in range(a[i], 1000010, a[i]): b[j] = True ans = 0 for i in range(n): if not b[a[i]]: ans += 1 for j in range(a[i], 1000010, a[i]): b[j] = True print(ans)
insert
7
7
7
9
TLE
p02642
Python
Runtime Error
n = int(input()) a = list(map(int, input().split())) xs = [0] * (2 * (10**5) + 1) for v in a: if xs[v] == 0: for j in range(v, len(xs), v): xs[j] += 1 else: xs[v] += 1 print(len(list(filter(lambda v: xs[v] == 1, a))))
n = int(input()) a = list(map(int, input().split())) xs = [0] * (max(a) + 1) for v in a: if xs[v] == 0: for j in range(v, len(xs), v): xs[j] += 1 else: xs[v] += 1 print(len(list(filter(lambda v: xs[v] == 1, a))))
replace
3
4
3
4
0
p02642
C++
Runtime Error
#include <algorithm> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; bool divide[200005] = {}; vector<int> a; int n; int main(void) { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { int in; cin >> in; a.push_back(in); } sort(a.begin(), a.end()); int count = 0; for (int i = 0; i < n; i++) { if (divide[a[i]] == false) { count++; for (int j = 1; j * a[i] <= a[n - 1]; j++) { divide[j * a[i]] = true; } if ((i != n - 1) && a[i + 1] == a[i]) count--; } } cout << count << endl; return 0; }
#include <algorithm> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; bool divide[1000005] = {}; vector<int> a; int n; int main(void) { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { int in; cin >> in; a.push_back(in); } sort(a.begin(), a.end()); int count = 0; for (int i = 0; i < n; i++) { if (divide[a[i]] == false) { count++; for (int j = 1; j * a[i] <= a[n - 1]; j++) { divide[j * a[i]] = true; } if ((i != n - 1) && a[i + 1] == a[i]) count--; } } cout << count << endl; return 0; }
replace
14
15
14
15
0
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define N 200000 #define M 100001 int n; vector<int> u(M, 0); vector<int> a(N); vector<int64_t> divisor(int64_t n) { vector<int64_t> ret; for (int64_t i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } int main(void) { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { u[a[i]]++; } int res = 0; for (int i = 0; i < n; i++) { bool can = true; auto v = divisor(a[i]); for (auto vi : v) { if (vi == a[i] && u[vi] == 1) continue; if (u[vi]) can = false; } if (can) res++; } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define N 200000 #define M 1001001 int n; vector<int> u(M, 0); vector<int> a(N); vector<int64_t> divisor(int64_t n) { vector<int64_t> ret; for (int64_t i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } int main(void) { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { u[a[i]]++; } int res = 0; for (int i = 0; i < n; i++) { bool can = true; auto v = divisor(a[i]); for (auto vi : v) { if (vi == a[i] && u[vi] == 1) continue; if (u[vi]) can = false; } if (can) res++; } cout << res << endl; return 0; }
replace
3
4
3
4
0
p02642
C++
Runtime Error
#include <iostream> using namespace std; int a[200005], vis[200005], flag[1000005]; void slove(int x) { for (int i = 2;; i++) { int t = x * i; if (t > 1e6) return; flag[t] = 1; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; if (vis[a[i]] == 0) slove(a[i]); else flag[a[i]] = 1; vis[a[i]] = 1; } int ans = 0; for (int i = 1; i <= n; i++) { if (flag[a[i]] == 0) ans++; } cout << ans << '\n'; return 0; }
#include <iostream> using namespace std; int a[200005], vis[1000005], flag[1000005]; void slove(int x) { for (int i = 2;; i++) { int t = x * i; if (t > 1e6) return; flag[t] = 1; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; if (vis[a[i]] == 0) slove(a[i]); else flag[a[i]] = 1; vis[a[i]] = 1; } int ans = 0; for (int i = 1; i <= n; i++) { if (flag[a[i]] == 0) ans++; } cout << ans << '\n'; return 0; }
replace
3
4
3
4
0
p02642
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <vector> using namespace std; int SetInput(vector<int> &vec) { int size; cin >> size; for (int i = 0; i < size; ++i) { int value; cin >> value; vec.at(i) = value; } vec.resize(size); return size; } int Calc(vector<int> &input) { // ふるい const int max = 1000000; int sieve[max + 1] = {0}; sort(input.begin(), input.end()); for (const int &i : input) { // cout << "i : " << i << endl; ++sieve[i]; } int count = 0; for (const int &i : input) { const int &s = sieve[i]; if (s == 1) { ++count; } if (s > 0) { const int maxMul = max / i; for (int mul = 2; i * mul <= max; ++mul) { sieve[i * mul] = -1; } } } return count; } int main() { const int N = 200000; vector<int> input(N); SetInput(input); int ans = Calc(input); cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int SetInput(vector<int> &vec) { int size; cin >> size; for (int i = 0; i < size; ++i) { int value; cin >> value; vec.at(i) = value; } vec.resize(size); return size; } int Calc(vector<int> &input) { // ふるい const int max = 1000000; int sieve[max + 1] = {0}; sort(input.begin(), input.end()); for (const int &i : input) { // cout << "i : " << i << endl; ++sieve[i]; } int count = 0; for (const int &i : input) { const int &s = sieve[i]; if (s == 1) { ++count; } if (s > 0) { const int maxMul = max / i; for (int mul = 1; i * mul <= max; ++mul) { sieve[i * mul] = -1; } } } return count; } int main() { const int N = 200000; vector<int> input(N); SetInput(input); int ans = Calc(input); cout << ans << endl; return 0; }
replace
40
41
40
41
TLE
p02642
C++
Time Limit Exceeded
#pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) using ll = long long; using P = pair<ll, ll>; int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); ll n; cin >> n; vector<ll> a(n); vector<int> isprime(1000001, 1); map<ll, ll> mp; for (ll i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; } for (ll i = 2; i <= 1000000; i++) { if (!isprime[i]) continue; for (ll j = 2 * i; j <= 1000000; j += i) { isprime[j] = 0; } for (ll j = 1; i * j <= 1000000; j++) { mp[i * j] += mp[j]; } } ll ans = 0; for (ll i = 0; i < n; i++) { if (mp[a[i]] == 1) ans++; } cout << ans << endl; }
#pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) using ll = long long; using P = pair<ll, ll>; int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); ll n; cin >> n; vector<ll> a(n); vector<int> isprime(1000001, 1); vector<ll> mp(1000001); for (ll i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; } for (ll i = 2; i <= 1000000; i++) { if (!isprime[i]) continue; for (ll j = 2 * i; j <= 1000000; j += i) { isprime[j] = 0; } for (ll j = 1; i * j <= 1000000; j++) { mp[i * j] += mp[j]; } } ll ans = 0; for (ll i = 0; i < n; i++) { if (mp[a[i]] == 1) ans++; } cout << ans << endl; }
replace
16
17
16
17
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <iostream> using namespace std; #define se second #define fi first #define ll long long #define ld long double #define pll pair<ll, ll> #define plll pair<pll, ll> #define ppll pair<pll, pll> #define pii pair<int, int> #define piii pair<pii, int> #define pb push_back const ll llinf = 2e18 + 7; const int inf = 2e9 + 7; const ll mod = 1e9 + 7; const ll N = 1e6 + 7; const ld pi = 3.14159265358979; void solve() { int n, a; cin >> n; vector<int> isprime(N, 1); vector<int> prime(N), arr; for (int i = 0; i < n; i++) { cin >> a; prime[a]++; } for (int i = 0; i < N; i++) { if (prime[i] >= 1) arr.pb(i); } // sort(arr.begin(),arr.end()); int cnt = 0; for (int i = 0; i < n; i++) { if (isprime[arr[i]]) { if (prime[arr[i]] == 1) cnt++; for (int j = 2 * arr[i]; j < N; j += arr[i]) { isprime[j] = 0; } } } cout << cnt; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; t = 1; // cin>>t; while (t--) { solve(); // cout<<"\n"; } return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; #define se second #define fi first #define ll long long #define ld long double #define pll pair<ll, ll> #define plll pair<pll, ll> #define ppll pair<pll, pll> #define pii pair<int, int> #define piii pair<pii, int> #define pb push_back const ll llinf = 2e18 + 7; const int inf = 2e9 + 7; const ll mod = 1e9 + 7; const ll N = 1e6 + 7; const ld pi = 3.14159265358979; void solve() { int n, a; cin >> n; vector<int> isprime(N, 1); vector<int> prime(N), arr; for (int i = 0; i < n; i++) { cin >> a; prime[a]++; } for (int i = 0; i < N; i++) { if (prime[i] >= 1) arr.pb(i); } // sort(arr.begin(),arr.end()); int cnt = 0; for (int i = 0; i < arr.size(); i++) { if (isprime[arr[i]]) { if (prime[arr[i]] == 1) cnt++; for (int j = 2 * arr[i]; j < N; j += arr[i]) { isprime[j] = 0; } } } cout << cnt; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; t = 1; // cin>>t; while (t--) { solve(); // cout<<"\n"; } return 0; }
replace
34
35
34
35
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define repa(i, a, n) for (int i = (a); i < (n); i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define rrepa(i, a, n) for (int i = n - 1; i >= (a); i--) #define all(a) (a).begin(), (a).end() #define MOD 1000000007 #define cmax(a, b) a = max(a, b) #define cmin(a, b) a = min(a, b) #define vc vector typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<vd> vvd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; int main() { int n; cin >> n; vi a(n); rep(i, n) cin >> a[i]; a.push_back(0); sort(all(a)); a.push_back(0); vc<bool> tf(a[n - 1] + 1, true); int ans = 0; repa(i, 1, n + 1) { while (a[i] == a[i + 1]) i++; if (tf[a[i]] && a[i - 1] != a[i]) ans++; for (int j = 1; a[i] * j <= a[n]; j++) { tf[a[i] * j] = false; } } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define repa(i, a, n) for (int i = (a); i < (n); i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define rrepa(i, a, n) for (int i = n - 1; i >= (a); i--) #define all(a) (a).begin(), (a).end() #define MOD 1000000007 #define cmax(a, b) a = max(a, b) #define cmin(a, b) a = min(a, b) #define vc vector typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<vd> vvd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; int main() { int n; cin >> n; vi a(n); rep(i, n) cin >> a[i]; a.push_back(0); sort(all(a)); a.push_back(0); vc<bool> tf(a[n] + 1, true); int ans = 0; repa(i, 1, n + 1) { while (a[i] == a[i + 1]) i++; if (tf[a[i]] && a[i - 1] != a[i]) ans++; for (int j = 1; a[i] * j <= a[n]; j++) { tf[a[i] * j] = false; } } cout << ans << "\n"; return 0; }
replace
35
36
35
36
0
p02642
C++
Time Limit Exceeded
// author rhythmicankur // god_is_almighty #pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> #define f first #define s second #define int long long #define ll int #define ld long double #define pb push_back #define eb emplace_back #define mk make_pair #define vi vector<int> #define pii pair<int, int> #define pip pair<int, pii> #define vpi vector<pii> #define sbcount(x) __builtin_popcountll(x) #define REP(i, n) for (int i = 1; i <= n; i++) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define fill(a, val) memset(a, val, sizeof(a)) #define PI acos(-1) #define coud(a, b) cout << fixed << setprecision((b)) << (a) #define M1 998244353 #define M2 1000000007 const ll LL_INF = 0x3f3f3f3f3f3f3f3f; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } #define test4(x, y, z, a) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << " | " << #a << ": " << a << endl; #define test1(x) cerr << #x << ": " << x << endl #define test2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define test3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl ll power(ll a, ll b, ll m = M2) { ll answer = 1; while (b) { if (b & 1) answer = (answer * a) % m; b /= 2; a = (a * a) % m; } return answer; } using namespace std; void ctrl() { cout << "Control" << endl; } int make_num(string p) { stringstream geek(p); int x = 0; geek >> x; return x; } string make_str(int x) { ostringstream str1; str1 << x; string geek = str1.str(); return geek; } int A[1000000 + 5], fre[1000000 + 5]; signed main() { ios::sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); int n; cin >> n; int val[n]; for (int i = 0; i < n; i++) cin >> val[i], fre[val[i]]++; sort(val, val + n); int cnt = 0; for (int i = 0; i < n; i++) { if (A[val[i]] == 0 && fre[val[i]] == 1) cnt++; for (int j = val[i]; j <= 1000000; j += val[i]) { A[j] = 1; } } cout << cnt; return 0; }
// author rhythmicankur // god_is_almighty #pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> #define f first #define s second #define int long long #define ll int #define ld long double #define pb push_back #define eb emplace_back #define mk make_pair #define vi vector<int> #define pii pair<int, int> #define pip pair<int, pii> #define vpi vector<pii> #define sbcount(x) __builtin_popcountll(x) #define REP(i, n) for (int i = 1; i <= n; i++) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define fill(a, val) memset(a, val, sizeof(a)) #define PI acos(-1) #define coud(a, b) cout << fixed << setprecision((b)) << (a) #define M1 998244353 #define M2 1000000007 const ll LL_INF = 0x3f3f3f3f3f3f3f3f; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } #define test4(x, y, z, a) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << " | " << #a << ": " << a << endl; #define test1(x) cerr << #x << ": " << x << endl #define test2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define test3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl ll power(ll a, ll b, ll m = M2) { ll answer = 1; while (b) { if (b & 1) answer = (answer * a) % m; b /= 2; a = (a * a) % m; } return answer; } using namespace std; void ctrl() { cout << "Control" << endl; } int make_num(string p) { stringstream geek(p); int x = 0; geek >> x; return x; } string make_str(int x) { ostringstream str1; str1 << x; string geek = str1.str(); return geek; } int A[1000000 + 5], fre[1000000 + 5]; signed main() { ios::sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); int n; cin >> n; int val[n]; for (int i = 0; i < n; i++) cin >> val[i], fre[val[i]]++; sort(val, val + n); int cnt = 0; for (int i = 0; i < n; i++) { if (A[val[i]] == 0 && fre[val[i]] == 1) cnt++; if (A[val[i]] == 1) continue; for (int j = val[i]; j <= 1000000; j += val[i]) { A[j] = 1; } } cout << cnt; return 0; }
insert
83
83
83
86
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define repo(i, n) for (int i = 1; i <= n; i++) #define INF 1001001001 #define INFll 100100100100100 // debug用 #define PrintVec(x) \ for (auto elementPrintVec : x) { \ cout << elementPrintVec << " "; \ } \ cout << endl; using namespace std; using ull = unsigned long long; using ll = long long; using P = pair<int, int>; const int mod = 1000000007; int main() { int n; cin >> n; vector<int> a(n); vector<bool> d(1000005); vector<bool> visited(1000005); rep(i, n) { cin >> a[i]; } sort(a.begin(), a.end()); rep(i, n) { int x = a[i]; if (visited[x]) continue; visited[x] = true; while (x <= 1000000) { x += a[i]; d[x] = true; } } int ans = 0; rep(i, n) { if (!d[a[i]]) { if (i != 0 && a[i] == a[i - 1]) continue; if (i != n - 1 && a[i + 1] == a[i]) continue; ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define repo(i, n) for (int i = 1; i <= n; i++) #define INF 1001001001 #define INFll 100100100100100 // debug用 #define PrintVec(x) \ for (auto elementPrintVec : x) { \ cout << elementPrintVec << " "; \ } \ cout << endl; using namespace std; using ull = unsigned long long; using ll = long long; using P = pair<int, int>; const int mod = 1000000007; int main() { int n; cin >> n; vector<int> a(n); vector<bool> d(1000005); vector<bool> visited(1000005); rep(i, n) { cin >> a[i]; } sort(a.begin(), a.end()); rep(i, n) { int x = a[i]; if (visited[x]) continue; visited[x] = true; while (x + a[i] <= 1000000) { x += a[i]; d[x] = true; } } int ans = 0; rep(i, n) { if (!d[a[i]]) { if (i != 0 && a[i] == a[i - 1]) continue; if (i != n - 1 && a[i + 1] == a[i]) continue; ans++; } } cout << ans << endl; return 0; }
replace
31
32
31
32
0
p02642
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { int n; cin >> n; int arr[n]; map<int, int> mp; for (int i = 0; i < n; i++) { cin >> arr[i]; mp[arr[i]]++; } sort(arr, arr + n); int maxi = mp.rbegin()->first; // cout<<maxi<<endl; for (int i = 0; i < n; i++) { int val = arr[i]; if (mp.find(val) == mp.end()) continue; if (mp[val] > 1) mp.erase(val); maxi = mp.rbegin()->first; // cout<<val<<" "<<maxi<<" "<<mp.size()<<endl; for (int j = 2 * val; j <= maxi; j += val) { if (mp.find(j) != mp.end()) mp.erase(j); } } cout << mp.size() << endl; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { int n; cin >> n; int arr[n]; map<int, int> mp; for (int i = 0; i < n; i++) { cin >> arr[i]; mp[arr[i]]++; } sort(arr, arr + n); int maxi = mp.rbegin()->first; // cout<<maxi<<endl; for (int i = 0; i < n; i++) { int val = arr[i]; if (mp.find(val) == mp.end()) continue; if (mp[val] > 1) mp.erase(val); if (mp.size()) maxi = mp.rbegin()->first; // cout<<val<<" "<<maxi<<" "<<mp.size()<<endl; for (int j = 2 * val; j <= maxi; j += val) { if (mp.find(j) != mp.end()) mp.erase(j); } } cout << mp.size() << endl; return 0; }
replace
22
23
22
24
0
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n = 0; cin >> n; vector<int> v(n, 0); vector<int> cnt(1e6 + 5, 0); int mx = -1; for (int i = 0; i < n; i++) { cin >> v[i]; mx = max(mx, v[i]); cnt[v[i]]++; } vector<int> dp(mx + 1, 0); int ans = 0; for (int i = 0; i < n; i++) { ll temp = v[i]; while (temp <= mx) { temp = temp + v[i]; dp[temp] = 1; } } for (int i = 0; i < n; i++) { if (dp[v[i]] == 0 && cnt[v[i]] == 1) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n = 0; cin >> n; vector<int> v(n, 0); vector<int> cnt(1e6 + 5, 0); int mx = -1; for (int i = 0; i < n; i++) { cin >> v[i]; mx = max(mx, v[i]); cnt[v[i]]++; } vector<int> dp(mx + 1, 0); int ans = 0; for (int i = 0; i < n; i++) { ll temp = v[i]; while (temp + v[i] <= mx) { temp = temp + v[i]; dp[temp] = 1; } } for (int i = 0; i < n; i++) { if (dp[v[i]] == 0 && cnt[v[i]] == 1) ans++; } cout << ans << endl; return 0; }
replace
33
34
33
34
0
p02642
C++
Runtime Error
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> #include <vector> using namespace std; #define int long long #define rep(s, i, n) for (int i = s; i < n; i++) #define c(n) cout << n << endl; #define ic(n) \ int n; \ cin >> n; #define sc(s) \ string s; \ cin >> s; #define mod 998244353 #define inf 1000000000000000007 #define f first #define s second #define mini(c, a, b) *min_element(c + a, c + b) #define maxi(c, a, b) *max_element(c + a, c + b) #define pi 3.141592653589793238462643383279 #define e_ 2.718281828459045235360287471352 #define P pair<int, int> #define upp(a, n, x) upper_bound(a, a + n, x) - a; #define low(a, n, x) lower_bound(a, a + n, x) - a; #define UF UnionFind #define pb push_back // printf("%.12Lf\n",); int keta(int x) { rep(0, i, 30) { if (x < 10) { return i + 1; } x = x / 10; } } int gcd(int x, int y) { if (x == 0 || y == 0) return x + y; int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return bb; } bb = bb % aa; if (bb == 0) { return aa; } } } int lcm(int x, int y) { int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return x / bb * y; } bb = bb % aa; if (bb == 0) { return x / aa * y; } } } bool prime(int x) { if (x == 1) return false; rep(2, i, sqrt(x) + 1) { if (x % i == 0 && x != i) { return false; } } return true; } int max(int a, int b) { if (a >= b) return a; else return b; } string maxst(string s, string t) { int n = s.size(); int m = t.size(); if (n > m) return s; else if (n < m) return t; else { rep(0, i, n) { if (s[i] > t[i]) return s; if (s[i] < t[i]) return t; } return s; } } string minst(string s, string t) { int n = s.size(); int m = t.size(); if (n < m) return s; else if (n > m) return t; else { rep(0, i, n) { if (s[i] < t[i]) return s; if (s[i] > t[i]) return t; } return s; } } string string_reverse(string s) { int n = s.size(); string t; rep(0, i, n) t += s[n - i - 1]; return t; } int min(int a, int b) { if (a >= b) return b; else return a; } int n2[31]; int nis[31]; int nia[31]; int mody[31]; int nn; int com(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int bunsi = 1, bunbo = 1; rep(0, i, y) bunsi = (bunsi * (n - i)) % mod; rep(0, i, y) bunbo = (bunbo * (i + 1)) % mod; mody[0] = bunbo; rep(1, i, 41) { bunbo = (bunbo * bunbo) % mod; mody[i] = bunbo; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { bunsi = (bunsi * mody[i]) % mod; } } return bunsi; } int gyakugen(int n, int y) { int ni = 1; for (int i = 0; i < 31; i++) { n2[i] = ni; ni *= 2; } mody[0] = y; rep(1, i, 31) { y = (y * y) % mod; mody[i] = y; } rep(0, i, 31) nis[i] = 0; nn = mod - 2; for (int i = 30; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 31) { if (nis[i] == 1) { n = (n * mody[i]) % mod; } } return n; } int yakuwa(int n) { int sum = 0; rep(1, i, sqrt(n + 1)) { if (n % i == 0) sum += i + n / i; if (i * i == n) sum -= i; } return sum; } int poow(int y, int n) { if (n == 0) return 1; n -= 1; int ni = 1; for (int i = 0; i < 62; i++) { n2[i] = ni; ni *= 2; } int yy = y; mody[0] = yy; rep(1, i, 62) { yy = (yy * yy) % mod; mody[i] = yy; } rep(0, i, 62) nis[i] = 0; nn = n; for (int i = 62; i >= 0; i -= 1) { if (nn >= n2[i]) { nis[i]++; nn -= n2[i]; } } rep(0, i, 62) { if (nis[i] == 1) { y = (y * mody[i]) % mod; } } return y; } int minpow(int x, int y) { int sum = 1; rep(0, i, y) sum *= x; return sum; } int ketawa(int x, int sinsuu) { int sum = 0; rep(0, i, 80) { if (minpow(sinsuu, i) > x) { return sum; } sum += (x % minpow(sinsuu, i + 1)) / (minpow(sinsuu, i)); } return sum; } double distance(double a, double b, double c, double d) { return sqrt((b - a) * (b - a) + (c - d) * (c - d)); } int sankaku(int a) { return a * (a + 1) / 2; } int sames(int a[1111111], int n) { int ans = 0; rep(0, i, n) { if (a[i] == a[i + 1]) { int j = i; while (a[j + 1] == a[i] && j <= n - 2) j++; ans += sankaku(j - i); i = j; } } return ans; } using Graph = vector<vector<int>>; int oya[114514]; int depth[114514]; void dfs(const Graph &G, int v, int p, int d) { depth[v] = d; oya[v] = p; for (auto nv : G[v]) { if (nv == p) continue; // nv が親 p だったらダメ dfs(G, nv, v, d + 1); // d を 1 増やして子ノードへ } } /*int H=10,W=10; char field[10][10]; char memo[10][10]; void dfs(int h, int w) { memo[h][w] = 'x'; // 八方向を探索 for (int dh = -1; dh <= 1; ++dh) { for (int dw = -1; dw <= 1; ++dw) { if(abs(0-dh)+abs(0-dw)==2)continue; int nh = h + dh, nw = w + dw; // 場外アウトしたり、0 だったりはスルー if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; if (memo[nh][nw] == 'x') continue; // 再帰的に探索 dfs(nh, nw); } } }*/ int XOR(int a, int b) { if (a == 0 || b == 0) { return a + b; } int ni = 1; rep(0, i, 41) { n2[i] = ni; ni *= 2; } rep(0, i, 41) nis[i] = 0; for (int i = 40; i >= 0; i -= 1) { if (a >= n2[i]) { nis[i]++; a -= n2[i]; } if (b >= n2[i]) { nis[i]++; b -= n2[i]; } } int sum = 0; rep(0, i, 41) sum += (nis[i] % 2 * n2[i]); return sum; } // int ma[1024577][21]; // for(int bit=0;bit<(1<<n);bit++)rep(0,i,n)if(bit&(1<<i))ma[bit][i]=1; struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); // xの根をrx int ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; int a[514514]; vector<int> b[514514]; vector<int> yaku[1114514]; bool c[514514]; signed main() { ic(n) rep(0, i, 1000001) c[i] = false; rep(0, i, n) { cin >> a[i]; c[a[i]] = true; } sort(a, a + n); rep(1, i, 1000001) { int s = i; rep(0, j, 1000001 / i) { if (c[s]) yaku[s].pb(i); s += i; } } int ans = 0; rep(0, i, n) { bool t = true; rep(0, j, yaku[a[i]].size()) { int l = low(a, n, yaku[a[i]][j]); int u = upp(a, n, yaku[a[i]][j]); if (yaku[a[i]][j] == a[i]) l++; if (u - l >= 1) t = false; } if (t) ans++; } c(ans) }
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> #include <vector> using namespace std; #define int long long #define rep(s, i, n) for (int i = s; i < n; i++) #define c(n) cout << n << endl; #define ic(n) \ int n; \ cin >> n; #define sc(s) \ string s; \ cin >> s; #define mod 998244353 #define inf 1000000000000000007 #define f first #define s second #define mini(c, a, b) *min_element(c + a, c + b) #define maxi(c, a, b) *max_element(c + a, c + b) #define pi 3.141592653589793238462643383279 #define e_ 2.718281828459045235360287471352 #define P pair<int, int> #define upp(a, n, x) upper_bound(a, a + n, x) - a; #define low(a, n, x) lower_bound(a, a + n, x) - a; #define UF UnionFind #define pb push_back // printf("%.12Lf\n",); int keta(int x) { rep(0, i, 30) { if (x < 10) { return i + 1; } x = x / 10; } } int gcd(int x, int y) { if (x == 0 || y == 0) return x + y; int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return bb; } bb = bb % aa; if (bb == 0) { return aa; } } } int lcm(int x, int y) { int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return x / bb * y; } bb = bb % aa; if (bb == 0) { return x / aa * y; } } } bool prime(int x) { if (x == 1) return false; rep(2, i, sqrt(x) + 1) { if (x % i == 0 && x != i) { return false; } } return true; } int max(int a, int b) { if (a >= b) return a; else return b; } string maxst(string s, string t) { int n = s.size(); int m = t.size(); if (n > m) return s; else if (n < m) return t; else { rep(0, i, n) { if (s[i] > t[i]) return s; if (s[i] < t[i]) return t; } return s; } } string minst(string s, string t) { int n = s.size(); int m = t.size(); if (n < m) return s; else if (n > m) return t; else { rep(0, i, n) { if (s[i] < t[i]) return s; if (s[i] > t[i]) return t; } return s; } } string string_reverse(string s) { int n = s.size(); string t; rep(0, i, n) t += s[n - i - 1]; return t; } int min(int a, int b) { if (a >= b) return b; else return a; } int n2[31]; int nis[31]; int nia[31]; int mody[31]; int nn; int com(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int bunsi = 1, bunbo = 1; rep(0, i, y) bunsi = (bunsi * (n - i)) % mod; rep(0, i, y) bunbo = (bunbo * (i + 1)) % mod; mody[0] = bunbo; rep(1, i, 41) { bunbo = (bunbo * bunbo) % mod; mody[i] = bunbo; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { bunsi = (bunsi * mody[i]) % mod; } } return bunsi; } int gyakugen(int n, int y) { int ni = 1; for (int i = 0; i < 31; i++) { n2[i] = ni; ni *= 2; } mody[0] = y; rep(1, i, 31) { y = (y * y) % mod; mody[i] = y; } rep(0, i, 31) nis[i] = 0; nn = mod - 2; for (int i = 30; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 31) { if (nis[i] == 1) { n = (n * mody[i]) % mod; } } return n; } int yakuwa(int n) { int sum = 0; rep(1, i, sqrt(n + 1)) { if (n % i == 0) sum += i + n / i; if (i * i == n) sum -= i; } return sum; } int poow(int y, int n) { if (n == 0) return 1; n -= 1; int ni = 1; for (int i = 0; i < 62; i++) { n2[i] = ni; ni *= 2; } int yy = y; mody[0] = yy; rep(1, i, 62) { yy = (yy * yy) % mod; mody[i] = yy; } rep(0, i, 62) nis[i] = 0; nn = n; for (int i = 62; i >= 0; i -= 1) { if (nn >= n2[i]) { nis[i]++; nn -= n2[i]; } } rep(0, i, 62) { if (nis[i] == 1) { y = (y * mody[i]) % mod; } } return y; } int minpow(int x, int y) { int sum = 1; rep(0, i, y) sum *= x; return sum; } int ketawa(int x, int sinsuu) { int sum = 0; rep(0, i, 80) { if (minpow(sinsuu, i) > x) { return sum; } sum += (x % minpow(sinsuu, i + 1)) / (minpow(sinsuu, i)); } return sum; } double distance(double a, double b, double c, double d) { return sqrt((b - a) * (b - a) + (c - d) * (c - d)); } int sankaku(int a) { return a * (a + 1) / 2; } int sames(int a[1111111], int n) { int ans = 0; rep(0, i, n) { if (a[i] == a[i + 1]) { int j = i; while (a[j + 1] == a[i] && j <= n - 2) j++; ans += sankaku(j - i); i = j; } } return ans; } using Graph = vector<vector<int>>; int oya[114514]; int depth[114514]; void dfs(const Graph &G, int v, int p, int d) { depth[v] = d; oya[v] = p; for (auto nv : G[v]) { if (nv == p) continue; // nv が親 p だったらダメ dfs(G, nv, v, d + 1); // d を 1 増やして子ノードへ } } /*int H=10,W=10; char field[10][10]; char memo[10][10]; void dfs(int h, int w) { memo[h][w] = 'x'; // 八方向を探索 for (int dh = -1; dh <= 1; ++dh) { for (int dw = -1; dw <= 1; ++dw) { if(abs(0-dh)+abs(0-dw)==2)continue; int nh = h + dh, nw = w + dw; // 場外アウトしたり、0 だったりはスルー if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; if (memo[nh][nw] == 'x') continue; // 再帰的に探索 dfs(nh, nw); } } }*/ int XOR(int a, int b) { if (a == 0 || b == 0) { return a + b; } int ni = 1; rep(0, i, 41) { n2[i] = ni; ni *= 2; } rep(0, i, 41) nis[i] = 0; for (int i = 40; i >= 0; i -= 1) { if (a >= n2[i]) { nis[i]++; a -= n2[i]; } if (b >= n2[i]) { nis[i]++; b -= n2[i]; } } int sum = 0; rep(0, i, 41) sum += (nis[i] % 2 * n2[i]); return sum; } // int ma[1024577][21]; // for(int bit=0;bit<(1<<n);bit++)rep(0,i,n)if(bit&(1<<i))ma[bit][i]=1; struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); // xの根をrx int ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; int a[514514]; vector<int> b[514514]; vector<int> yaku[1114514]; bool c[1114514]; signed main() { ic(n) rep(0, i, 1000001) c[i] = false; rep(0, i, n) { cin >> a[i]; c[a[i]] = true; } sort(a, a + n); rep(1, i, 1000001) { int s = i; rep(0, j, 1000001 / i) { if (c[s]) yaku[s].pb(i); s += i; } } int ans = 0; rep(0, i, n) { bool t = true; rep(0, j, yaku[a[i]].size()) { int l = low(a, n, yaku[a[i]][j]); int u = upp(a, n, yaku[a[i]][j]); if (yaku[a[i]][j] == a[i]) l++; if (u - l >= 1) t = false; } if (t) ans++; } c(ans) }
replace
356
357
356
357
-11
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int NMAX = 1 + (int)2e5; int main() { int N; cin >> N; int A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; } sort(A, A + N); int ans = 0; int AA[NMAX] = {}; for (int i = 0; i < N; i++) { bool flag = true; if (i > 0) { AA[A[i - 1]]++; } if (A[i] == A[i + 1]) continue; int k = (int)sqrt((double)A[i]); for (int j = 1; j <= k; j++) { if (AA[j] > 0 && A[i] % j == 0) { flag = false; // cout << "A[i] " << A[i] << " \% " << j << " =0: not counted" << endl; } if (A[i] % j == 0 && AA[A[i] / j] > 0) { flag = false; // cout << "A[i] " << A[i] << " \% " << A[i]/j << " =0: not counted" << // endl; } } if (flag) { // cout << "ans A[i] " << ans << " " << A[i] << endl; ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int NMAX = 1 + (int)1e6; int main() { int N; cin >> N; int A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; } sort(A, A + N); int ans = 0; int AA[NMAX] = {}; for (int i = 0; i < N; i++) { bool flag = true; if (i > 0) { AA[A[i - 1]]++; } if (A[i] == A[i + 1]) continue; int k = (int)sqrt((double)A[i]); for (int j = 1; j <= k; j++) { if (AA[j] > 0 && A[i] % j == 0) { flag = false; // cout << "A[i] " << A[i] << " \% " << j << " =0: not counted" << endl; } if (A[i] % j == 0 && AA[A[i] / j] > 0) { flag = false; // cout << "A[i] " << A[i] << " \% " << A[i]/j << " =0: not counted" << // endl; } } if (flag) { // cout << "ans A[i] " << ans << " " << A[i] << endl; ans++; } } cout << ans << endl; return 0; }
replace
2
3
2
3
0
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using llong = long long int; #define rep(i, n) for (int i = 0; i < n; ++i) #define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr) #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() const static int MOD = 1000000007; const static int INF = 1 << 30; const static int dx[4] = {1, 0, -1, 0}; const static int dy[4] = {0, 1, 0, -1}; int main(int argc, char *argv[]) { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<int> A(n); map<int, int> M; rep(i, n) { cin >> A[i]; ++M[A[i]]; } sort(all(A)); int maxA = 1000000 + 1; vector<bool> check_table(maxA + 1, false); int k; rep(i, n) { k = 2; while (A[i] * k <= maxA) { check_table[A[i] * k] = true; ++k; } } A.erase(unique(all(A)), A.end()); int ans = 0; rep(i, (int)A.size()) { if (!check_table[A[i]] && M[A[i]] == 1) ++ans; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using llong = long long int; #define rep(i, n) for (int i = 0; i < n; ++i) #define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr) #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() const static int MOD = 1000000007; const static int INF = 1 << 30; const static int dx[4] = {1, 0, -1, 0}; const static int dy[4] = {0, 1, 0, -1}; int main(int argc, char *argv[]) { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<int> A(n); map<int, int> M; rep(i, n) { cin >> A[i]; ++M[A[i]]; } sort(all(A)); int maxA = A[n - 1] + 100; vector<bool> check_table(maxA + 1, false); int k; rep(i, n) { k = 2; while (A[i] * k <= maxA) { check_table[A[i] * k] = true; ++k; } } A.erase(unique(all(A)), A.end()); int ans = 0; rep(i, (int)A.size()) { if (!check_table[A[i]] && M[A[i]] == 1) ++ans; } cout << ans << endl; return 0; }
replace
31
32
31
32
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; int f[maxn]; int nope[maxn]; int a[maxn]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", a + i); for (int i = 1; i <= n; i++) { int k = a[i]; f[k]++; for (int j = k + k; j < maxn; j += k) nope[j] = 1; } int ans = 0; for (int i = 1; i <= n; i++) { ans += (f[a[i]] == 1) and !nope[a[i]]; } printf("%d\n", ans); }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; int f[maxn]; int nope[maxn]; int a[maxn]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", a + i); for (int i = 1; i <= n; i++) { int k = a[i]; f[k]++; if (f[k] == 1) for (int j = k + k; j < maxn; j += k) nope[j] = 1; } int ans = 0; for (int i = 1; i <= n; i++) { ans += (f[a[i]] == 1) and !nope[a[i]]; } printf("%d\n", ans); }
replace
19
21
19
22
TLE
p02642
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; const long long INF = 1LL << 60; vector<ll> load[100005]; typedef pair<ll, ll> Pair; int main() { ll N; vector<ll> furui(1e6); cin >> N; vector<ll> A(N); for (ll i = 0; i < N; ++i) cin >> A[i]; for (ll i : A) { if (furui[i] == 1) { furui[i]++; continue; } for (ll j = i; j <= furui.size(); j += i) furui[j]++; } ll count = 0; for (ll i = 0; i < A.size(); ++i) { if (furui[A[i]] == 1) count++; } cout << count << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; const long long INF = 1LL << 60; vector<ll> load[100005]; typedef pair<ll, ll> Pair; int main() { ll N; vector<ll> furui(1e6); cin >> N; vector<ll> A(N); for (ll i = 0; i < N; ++i) cin >> A[i]; for (ll i : A) { if (furui[i] >= 1) { furui[i]++; continue; } for (ll j = i; j <= furui.size(); j += i) furui[j]++; } ll count = 0; for (ll i = 0; i < A.size(); ++i) { if (furui[A[i]] == 1) count++; } cout << count << endl; return 0; }
replace
31
32
31
32
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) vector<int64_t> divisor(int64_t n) { vector<int64_t> ret; ret.push_back(1); for (int64_t i = 2; 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; map<int, int> s; const int n_max = 1e6 + 10; vector<int> aru(n_max, 0); vector<int> a(n); rep(i, n) { cin >> a[i]; aru[a[i]]++; } sort(a.begin(), a.end()); int ans = 0; rep(i, n) { if (aru[a[i]] >= 10000000 || aru[a[i]] < 1) continue; else { if (aru[a[i]] == 1) ans++; for (int j = a[i] * 2; j < n_max; j += a[i]) { aru[j] = 1e7; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) vector<int64_t> divisor(int64_t n) { vector<int64_t> ret; ret.push_back(1); for (int64_t i = 2; 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; map<int, int> s; const int n_max = 1e6 + 10; vector<int> aru(n_max, 0); vector<int> a(n); rep(i, n) { cin >> a[i]; aru[a[i]]++; } sort(a.begin(), a.end()); int ans = 0; if (a[0] == 1) { if (aru[a[0]] > 1) cout << 0 << endl; else cout << 1 << endl; return 0; } rep(i, n) { if (aru[a[i]] >= 10000000 || aru[a[i]] < 1) continue; else { if (aru[a[i]] == 1) ans++; for (int j = a[i] * 2; j < n_max; j += a[i]) { aru[j] = 1e7; } } } cout << ans << endl; return 0; }
insert
36
36
36
43
TLE
p02642
C++
Runtime Error
// Apparat : drobucs, aleonov, vit_72 #include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <vector> // #pragma warning(disable : 4996) // #pragma GCC optimize("O3") using namespace std; #define nptr nullptr #define all(x) (x).begin(), (x).end() #define drobucs \ ios_base::sync_with_stdio(0); \ cout.tie(0); \ cin.tie(0); #define ff first #define ss second #define pb push_back #define sz(x) (int)(x).size() typedef long long ll; const int maxn = (int)2e5 + 13; const ll INFL = 9223372036854775807; const ll INF = 2147483647; const ll MOD = (int)1e9 + 7, MOD2 = 998244353; // 1e9 + 21, 1e9 + 33, 1e9 + 87, 1e9 + 93 const ll base = 101, base2 = 37; int a[maxn]; int mp[maxn]; int main() { drobucs; int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i], mp[a[i]]++; int ans = 0; for (int i = 1; i <= n; ++i) { bool f = 1; for (ll j = 2; j * j <= a[i]; ++j) { if (a[i] % j == 0 && (mp[j] != 0 || mp[a[i] / j] != 0)) f = 0; } if (a[i] != 1 && mp[1] != 0) f = 0; if (mp[a[i]] > 1) f = 0; ans += f; } cout << ans << "\n"; return 0; }
// Apparat : drobucs, aleonov, vit_72 #include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <vector> // #pragma warning(disable : 4996) // #pragma GCC optimize("O3") using namespace std; #define nptr nullptr #define all(x) (x).begin(), (x).end() #define drobucs \ ios_base::sync_with_stdio(0); \ cout.tie(0); \ cin.tie(0); #define ff first #define ss second #define pb push_back #define sz(x) (int)(x).size() typedef long long ll; const int maxn = (int)2e6 + 13; const ll INFL = 9223372036854775807; const ll INF = 2147483647; const ll MOD = (int)1e9 + 7, MOD2 = 998244353; // 1e9 + 21, 1e9 + 33, 1e9 + 87, 1e9 + 93 const ll base = 101, base2 = 37; int a[maxn]; int mp[maxn]; int main() { drobucs; int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i], mp[a[i]]++; int ans = 0; for (int i = 1; i <= n; ++i) { bool f = 1; for (ll j = 2; j * j <= a[i]; ++j) { if (a[i] % j == 0 && (mp[j] != 0 || mp[a[i] / j] != 0)) f = 0; } if (a[i] != 1 && mp[1] != 0) f = 0; if (mp[a[i]] > 1) f = 0; ans += f; } cout << ans << "\n"; return 0; }
replace
31
32
31
32
0
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long int #define pb push_back #define mp make_pair const int mod = 1e9 + 7; void solve() { int n; cin >> n; vector<int> V(n); map<int, pair<int, bool>> um; map<int, int> m; for (int i = 0; i < n; i++) { cin >> V[i]; um[V[i]] = mp(i, true); m[V[i]]++; } if (um[1].second == true) { if (m[1] == 1) cout << 1; else if (m[1] > 1) cout << 0; return; } int cnt = 0; for (int i = 0; i < n; i++) { int x = V[i]; for (int j = 1; j <= sqrt(x); j++) { if (x % j == 0) { if (m[j] == 1) { if (um[j].second == true && um[j].first != i) { cnt++; break; } } else if (m[j] > 1) { if (um[j].second == true) { cnt++; break; } } if (m[x / j] == 1) { if (um[x / j].second == true && um[x / j].first != i) { cnt++; break; } } else if (m[x / j] > 1) { if (um[x / j].second == true) { cnt++; break; } } } } } cout << n - cnt << endl; } int main() { fastio solve(); }
#include <bits/stdc++.h> using namespace std; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long int #define pb push_back #define mp make_pair const int mod = 1e9 + 7; void solve() { int n; cin >> n; vector<int> V(n); unordered_map<int, pair<int, bool>> um; unordered_map<int, int> m; for (int i = 0; i < n; i++) { cin >> V[i]; um[V[i]] = mp(i, true); m[V[i]]++; } if (um[1].second == true) { if (m[1] == 1) cout << 1; else if (m[1] > 1) cout << 0; return; } int cnt = 0; for (int i = 0; i < n; i++) { int x = V[i]; for (int j = 1; j <= sqrt(x); j++) { if (x % j == 0) { if (m[j] == 1) { if (um[j].second == true && um[j].first != i) { cnt++; break; } } else if (m[j] > 1) { if (um[j].second == true) { cnt++; break; } } if (m[x / j] == 1) { if (um[x / j].second == true && um[x / j].first != i) { cnt++; break; } } else if (m[x / j] > 1) { if (um[x / j].second == true) { cnt++; break; } } } } } cout << n - cnt << endl; } int main() { fastio solve(); }
replace
15
17
15
17
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; using pll = pair<ll, ll>; using Graph = vector<vector<ll>>; #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, l, r) for (ll i = (l); i <= (ll)(r); i++) #define rep3(i, l, r) for (ll i = (l); i >= (ll)(r); i--) #define dup(x, y) (((x) + (y)-1) / (y)) // x/yの除算の切り上げ template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const int inf = 1001001001; const ll INF = 1LL << 60; const ll mod = 1000000007; const ld pi = acos(-1); // xor演算 // a^b=b^a // a^(b^c)=(a^b)^c // a^a=0 // a+b=a^b + 2(a&b) //(4a)^(4a+1)^(4a+2)^(4a+3)=0 // union by size + path having // 最初にUnionFind a(n);で宣言 class UnionFind { public: vector<ll> par; // 各元の親を表す配列 vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化) // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; i++) par[i] = i; // 初期では親は自分自身 } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; i++) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool unite(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool same(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } }; // セグメント木 // 全て添字で扱うこと // segment_tree seg; // seg.build(配列名, 単位元)で宣言 // seg.build(a,0) struct segment_tree { ll n; // vの要素数 ll m; // 葉の数 vector<ll> v; // セグ木本体.ただの配列を使う ll id_e; // 単位元 // 区間の和なら0、区間の積なら1、最大値なら-1とか、最小値ならINF、最大公約数なら0 // 二項演算 ll binary_op(ll a, ll b) { return a + b; // 処理 // 区間の和ならa+b、区間の積ならa*b、最大値ならmax(a,b)、最初値ならmin(a,b)、最大公約数ならgcd(a,b) } // 初期化関数.数列と単位元を受け取って初期化 void build(vector<ll> a, ll b) { id_e = b; m = 1; while (m < (ll)a.size()) m *= 2; // aの項数以上の2べきのうち最小のものを求める n = 2 * m - 1; v.resize(n); for (ll i = 0; i < (ll)a.size(); i++) v[m - 1 + i] = a[i]; // 葉(1段目)の値 for (ll i = a.size(); i < m; i++) v[m - 1 + i] = id_e; // 葉(1段目)の右端の0埋め for (ll i = m - 2; i >= 0; i--) { // 2段目以降を順番に埋めていく v[i] = binary_op(v[2 * i + 1], v[2 * i + 2]); } } // ある項の値をbに書き換え void update(ll a, ll b) { a += (m - 1); v[a] = b; // 葉(1段目)を書き換え while ((a - 1) / 2 != a) { // 2段目以降を順番に書き換え a = (a - 1) / 2; v[a] = binary_op(v[2 * a + 1], v[2 * a + 2]); } } // 区間和の補助関数 // cur:今見ている頂点の,配列vでの添字 //[l, r]:v[cur]がカバーする区間 ll seg_sub(ll a, ll b, ll cur, ll l, ll r) { if (a <= l && r <= b) return v [cur]; // 今見ている頂点のカバーする区間が,[a,b]に完全に収まっている場合 if (r < a || b < l) return id_e; // 今見ている頂点のカバーする区間が,[a,b]と全く被っていない場合 return binary_op( // 今見ている頂点のカバーする区間が,[a,b]と一部被っている場合 seg_sub(a, b, 2 * cur + 1, l, (l + r) / 2), seg_sub(a, b, 2 * cur + 2, (l + r) / 2 + 1, r)); } // 区間[a, b]の和 // 最上段の頂点から子へ再帰していく ll partial_sum(ll a, ll b) { return seg_sub(a, b, 0, 0, m - 1); } }; // graph_d g(n);でn頂点のグラフを作成 // g.add_edge(a,b,cost);で頂点aから頂点bへのコストcostの辺が張られる // g.dijkstra(s);で頂点sから各頂点への最短経路をダイクストラ法で探索できる // ll dist=g.d[i];で探索結果を呼び出すことができる struct edge { ll to, cost; }; struct graph_d { ll V; vector<vector<edge>> G; vector<ll> d; graph_d(ll n) { init(n); } void init(ll n) { V = n; G.resize(V); d.resize(V); rep(i, V) { d[i] = INF; } } void add_edge(ll s, ll t, ll cost) { edge e; e.to = t, e.cost = cost; G[s].push_back(e); } void dijkstra(ll s) { rep(i, V) { d[i] = INF; } d[s] = 0; priority_queue<pll, vector<pll>, greater<pll>> que; que.push(pll(0, s)); while (!que.empty()) { pll p = que.top(); que.pop(); ll v = p.second; if (d[v] < p.first) continue; for (auto e : G[v]) { if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(pll(d[e.to], e.to)); } } } } }; ll modpow(ll x, ll n) { x = x % mod; if (n == 0) return 1; else if (n % 2 == 1) { return (x * modpow(x, n - 1)) % mod; } else return modpow((x * x) % mod, n / 2) % mod; } ll modcom(ll n, ll k) { ll x = 1; for (ll i = n - k + 1; i <= n; i++) { x = x * i % mod; } ll y = 1; for (ll i = 1; i <= k; i++) { y = y * i % mod; } y = modpow(y, mod - 2); return x * y % mod; } bool is_prime(ll n) { switch (n) { case 0: case 1: return false; case 2: case 3: return true; } if (n % 2 == 0 || n % 3 == 0) return false; for (ll i = 5; i * i <= n; i += 6) { if (n % i == 0) return false; if (n % (i + 2) == 0) return false; } return true; } ll digsum(ll n) { int res = 0; while (n > 0) { res += n % 10; // res++;だと桁数を求める関数,res+=n%10;なら格桁の和を求める関数 n /= 10; } return res; } vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); return ret; } vector<ll> divisor_cnt(ll n) { vector<ll> cnt(n); for (ll i = 1; i <= n; i++) { for (ll j = i; j <= n; j += i) { cnt[j]++; } } return cnt; } map<ll, ll> prime_factor(ll n) { map<ll, ll> res; res[1] = 1; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { res[i]++; n /= i; } } if (n != 1) res[n] = 1; return res; } template <std::int_fast64_t Modulus> class ModInt { using i64 = std::int_fast64_t; private: i64 m_value; public: constexpr ModInt(const i64 x = 0) noexcept : m_value(x % Modulus) { if (m_value < 0) m_value += Modulus; } constexpr const i64 &value() const noexcept { return m_value; } constexpr ModInt &operator+=(const ModInt rhs) noexcept { m_value += rhs.m_value; if (m_value >= Modulus) { m_value -= Modulus; } return *this; } constexpr ModInt &operator-=(const ModInt rhs) noexcept { if (m_value < rhs.m_value) { m_value += Modulus; } m_value -= rhs.m_value; return *this; } constexpr ModInt &operator*=(const ModInt rhs) noexcept { m_value = m_value * rhs.m_value % Modulus; return *this; } constexpr ModInt &operator/=(ModInt rhs) noexcept { *this *= rhs.inv(); return *this; } constexpr ModInt &operator++() noexcept { *this += 1; return *this; } constexpr ModInt operator++(int) noexcept { ModInt res = *this; *this += 1; return res; } constexpr ModInt &operator--() noexcept { *this -= 1; return *this; } constexpr ModInt operator--(int) noexcept { ModInt res = *this; *this -= 1; return res; } constexpr ModInt inv() const noexcept { i64 q = m_value; i64 b = Modulus, u = 1, v = 0; while (b) { i64 t = q / b; q -= t * b; std::swap(q, b); u -= t * v; std::swap(u, v); } u %= Modulus; if (u < 0) u += Modulus; return u; } constexpr ModInt pow(i64 k) const noexcept { ModInt res = 1; ModInt tmp; if (k < 0) { tmp = (*this).inv(); k = -k; } else { tmp = *this; } for (; k > 0; k >>= 1) { if (k & 1) res *= tmp; tmp *= tmp; } return res; } friend constexpr ModInt operator+(const ModInt &lhs, const ModInt &rhs) noexcept { return ModInt<Modulus>(lhs) += rhs; } friend constexpr ModInt operator-(const ModInt &lhs, const ModInt &rhs) noexcept { return ModInt<Modulus>(lhs) -= rhs; } friend constexpr ModInt operator*(const ModInt &lhs, const ModInt &rhs) noexcept { return ModInt<Modulus>(lhs) *= rhs; } friend constexpr ModInt operator/(const ModInt &lhs, const ModInt &rhs) noexcept { return ModInt<Modulus>(lhs) /= rhs; } friend constexpr bool operator<(const ModInt &lhs, const ModInt &rhs) noexcept { return lhs.m_value < rhs.m_value; } friend constexpr bool operator>(const ModInt &lhs, const ModInt &rhs) noexcept { return lhs.m_value > rhs.m_value; } friend constexpr bool operator<=(const ModInt &lhs, const ModInt &rhs) noexcept { return lhs.m_value <= rhs.m_value; } friend constexpr bool operator>=(const ModInt &lhs, const ModInt &rhs) noexcept { return lhs.m_value >= rhs.m_value; } friend constexpr bool operator==(const ModInt &lhs, const ModInt &rhs) noexcept { return lhs.m_value == rhs.m_value; } friend constexpr bool operator!=(const ModInt &lhs, const ModInt &rhs) noexcept { return lhs.m_value != rhs.m_value; } friend std::istream &operator>>(std::istream &is, ModInt &rhs) { i64 a; is >> a; rhs = a; return is; } friend std::ostream &operator<<(std::ostream &os, const ModInt &rhs) { os << rhs.m_value; return os; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; vector<ll> a(n); vector<ll> cnt(1000005, 0); rep(i, n) { ll x; cin >> a[i]; } for (auto y : a) { for (ll i = y; i <= 1000004; i += y) { cnt[i]++; } } ll ans = 0; for (auto y : a) { if (cnt[y] == 1) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; using pll = pair<ll, ll>; using Graph = vector<vector<ll>>; #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, l, r) for (ll i = (l); i <= (ll)(r); i++) #define rep3(i, l, r) for (ll i = (l); i >= (ll)(r); i--) #define dup(x, y) (((x) + (y)-1) / (y)) // x/yの除算の切り上げ template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const int inf = 1001001001; const ll INF = 1LL << 60; const ll mod = 1000000007; const ld pi = acos(-1); // xor演算 // a^b=b^a // a^(b^c)=(a^b)^c // a^a=0 // a+b=a^b + 2(a&b) //(4a)^(4a+1)^(4a+2)^(4a+3)=0 // union by size + path having // 最初にUnionFind a(n);で宣言 class UnionFind { public: vector<ll> par; // 各元の親を表す配列 vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化) // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; i++) par[i] = i; // 初期では親は自分自身 } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; i++) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool unite(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool same(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } }; // セグメント木 // 全て添字で扱うこと // segment_tree seg; // seg.build(配列名, 単位元)で宣言 // seg.build(a,0) struct segment_tree { ll n; // vの要素数 ll m; // 葉の数 vector<ll> v; // セグ木本体.ただの配列を使う ll id_e; // 単位元 // 区間の和なら0、区間の積なら1、最大値なら-1とか、最小値ならINF、最大公約数なら0 // 二項演算 ll binary_op(ll a, ll b) { return a + b; // 処理 // 区間の和ならa+b、区間の積ならa*b、最大値ならmax(a,b)、最初値ならmin(a,b)、最大公約数ならgcd(a,b) } // 初期化関数.数列と単位元を受け取って初期化 void build(vector<ll> a, ll b) { id_e = b; m = 1; while (m < (ll)a.size()) m *= 2; // aの項数以上の2べきのうち最小のものを求める n = 2 * m - 1; v.resize(n); for (ll i = 0; i < (ll)a.size(); i++) v[m - 1 + i] = a[i]; // 葉(1段目)の値 for (ll i = a.size(); i < m; i++) v[m - 1 + i] = id_e; // 葉(1段目)の右端の0埋め for (ll i = m - 2; i >= 0; i--) { // 2段目以降を順番に埋めていく v[i] = binary_op(v[2 * i + 1], v[2 * i + 2]); } } // ある項の値をbに書き換え void update(ll a, ll b) { a += (m - 1); v[a] = b; // 葉(1段目)を書き換え while ((a - 1) / 2 != a) { // 2段目以降を順番に書き換え a = (a - 1) / 2; v[a] = binary_op(v[2 * a + 1], v[2 * a + 2]); } } // 区間和の補助関数 // cur:今見ている頂点の,配列vでの添字 //[l, r]:v[cur]がカバーする区間 ll seg_sub(ll a, ll b, ll cur, ll l, ll r) { if (a <= l && r <= b) return v [cur]; // 今見ている頂点のカバーする区間が,[a,b]に完全に収まっている場合 if (r < a || b < l) return id_e; // 今見ている頂点のカバーする区間が,[a,b]と全く被っていない場合 return binary_op( // 今見ている頂点のカバーする区間が,[a,b]と一部被っている場合 seg_sub(a, b, 2 * cur + 1, l, (l + r) / 2), seg_sub(a, b, 2 * cur + 2, (l + r) / 2 + 1, r)); } // 区間[a, b]の和 // 最上段の頂点から子へ再帰していく ll partial_sum(ll a, ll b) { return seg_sub(a, b, 0, 0, m - 1); } }; // graph_d g(n);でn頂点のグラフを作成 // g.add_edge(a,b,cost);で頂点aから頂点bへのコストcostの辺が張られる // g.dijkstra(s);で頂点sから各頂点への最短経路をダイクストラ法で探索できる // ll dist=g.d[i];で探索結果を呼び出すことができる struct edge { ll to, cost; }; struct graph_d { ll V; vector<vector<edge>> G; vector<ll> d; graph_d(ll n) { init(n); } void init(ll n) { V = n; G.resize(V); d.resize(V); rep(i, V) { d[i] = INF; } } void add_edge(ll s, ll t, ll cost) { edge e; e.to = t, e.cost = cost; G[s].push_back(e); } void dijkstra(ll s) { rep(i, V) { d[i] = INF; } d[s] = 0; priority_queue<pll, vector<pll>, greater<pll>> que; que.push(pll(0, s)); while (!que.empty()) { pll p = que.top(); que.pop(); ll v = p.second; if (d[v] < p.first) continue; for (auto e : G[v]) { if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(pll(d[e.to], e.to)); } } } } }; ll modpow(ll x, ll n) { x = x % mod; if (n == 0) return 1; else if (n % 2 == 1) { return (x * modpow(x, n - 1)) % mod; } else return modpow((x * x) % mod, n / 2) % mod; } ll modcom(ll n, ll k) { ll x = 1; for (ll i = n - k + 1; i <= n; i++) { x = x * i % mod; } ll y = 1; for (ll i = 1; i <= k; i++) { y = y * i % mod; } y = modpow(y, mod - 2); return x * y % mod; } bool is_prime(ll n) { switch (n) { case 0: case 1: return false; case 2: case 3: return true; } if (n % 2 == 0 || n % 3 == 0) return false; for (ll i = 5; i * i <= n; i += 6) { if (n % i == 0) return false; if (n % (i + 2) == 0) return false; } return true; } ll digsum(ll n) { int res = 0; while (n > 0) { res += n % 10; // res++;だと桁数を求める関数,res+=n%10;なら格桁の和を求める関数 n /= 10; } return res; } vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); return ret; } vector<ll> divisor_cnt(ll n) { vector<ll> cnt(n); for (ll i = 1; i <= n; i++) { for (ll j = i; j <= n; j += i) { cnt[j]++; } } return cnt; } map<ll, ll> prime_factor(ll n) { map<ll, ll> res; res[1] = 1; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { res[i]++; n /= i; } } if (n != 1) res[n] = 1; return res; } template <std::int_fast64_t Modulus> class ModInt { using i64 = std::int_fast64_t; private: i64 m_value; public: constexpr ModInt(const i64 x = 0) noexcept : m_value(x % Modulus) { if (m_value < 0) m_value += Modulus; } constexpr const i64 &value() const noexcept { return m_value; } constexpr ModInt &operator+=(const ModInt rhs) noexcept { m_value += rhs.m_value; if (m_value >= Modulus) { m_value -= Modulus; } return *this; } constexpr ModInt &operator-=(const ModInt rhs) noexcept { if (m_value < rhs.m_value) { m_value += Modulus; } m_value -= rhs.m_value; return *this; } constexpr ModInt &operator*=(const ModInt rhs) noexcept { m_value = m_value * rhs.m_value % Modulus; return *this; } constexpr ModInt &operator/=(ModInt rhs) noexcept { *this *= rhs.inv(); return *this; } constexpr ModInt &operator++() noexcept { *this += 1; return *this; } constexpr ModInt operator++(int) noexcept { ModInt res = *this; *this += 1; return res; } constexpr ModInt &operator--() noexcept { *this -= 1; return *this; } constexpr ModInt operator--(int) noexcept { ModInt res = *this; *this -= 1; return res; } constexpr ModInt inv() const noexcept { i64 q = m_value; i64 b = Modulus, u = 1, v = 0; while (b) { i64 t = q / b; q -= t * b; std::swap(q, b); u -= t * v; std::swap(u, v); } u %= Modulus; if (u < 0) u += Modulus; return u; } constexpr ModInt pow(i64 k) const noexcept { ModInt res = 1; ModInt tmp; if (k < 0) { tmp = (*this).inv(); k = -k; } else { tmp = *this; } for (; k > 0; k >>= 1) { if (k & 1) res *= tmp; tmp *= tmp; } return res; } friend constexpr ModInt operator+(const ModInt &lhs, const ModInt &rhs) noexcept { return ModInt<Modulus>(lhs) += rhs; } friend constexpr ModInt operator-(const ModInt &lhs, const ModInt &rhs) noexcept { return ModInt<Modulus>(lhs) -= rhs; } friend constexpr ModInt operator*(const ModInt &lhs, const ModInt &rhs) noexcept { return ModInt<Modulus>(lhs) *= rhs; } friend constexpr ModInt operator/(const ModInt &lhs, const ModInt &rhs) noexcept { return ModInt<Modulus>(lhs) /= rhs; } friend constexpr bool operator<(const ModInt &lhs, const ModInt &rhs) noexcept { return lhs.m_value < rhs.m_value; } friend constexpr bool operator>(const ModInt &lhs, const ModInt &rhs) noexcept { return lhs.m_value > rhs.m_value; } friend constexpr bool operator<=(const ModInt &lhs, const ModInt &rhs) noexcept { return lhs.m_value <= rhs.m_value; } friend constexpr bool operator>=(const ModInt &lhs, const ModInt &rhs) noexcept { return lhs.m_value >= rhs.m_value; } friend constexpr bool operator==(const ModInt &lhs, const ModInt &rhs) noexcept { return lhs.m_value == rhs.m_value; } friend constexpr bool operator!=(const ModInt &lhs, const ModInt &rhs) noexcept { return lhs.m_value != rhs.m_value; } friend std::istream &operator>>(std::istream &is, ModInt &rhs) { i64 a; is >> a; rhs = a; return is; } friend std::ostream &operator<<(std::ostream &os, const ModInt &rhs) { os << rhs.m_value; return os; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; vector<ll> a(n); vector<ll> cnt(1000005, 0); rep(i, n) { ll x; cin >> a[i]; } for (auto y : a) { if (cnt[y] != 0) { cnt[y] = 2; continue; } for (ll i = y; i <= 1000004; i += y) { cnt[i]++; } } ll ans = 0; for (auto y : a) { if (cnt[y] == 1) ans++; } cout << ans << endl; }
insert
448
448
448
452
TLE
p02642
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; vector<int> V; vector<int> resposta; int vis[100100]; int crivo(int limite, int ind) { int cont = 0; for (int i = 0; i < ind; i++) { if (vis[V[i]] == 0) { vis[V[i]] = 2; cont++; for (int j = 2 * V[i]; j <= limite; j += V[i]) vis[j] = 1; } else if (vis[V[i]] == 2) { // Ja foi contado vis[V[i]] = 3; cont--; } } return cont; } int main() { int n; cin >> n; int limite = 0; for (int i = 0; i < n; i++) { int num; cin >> num; if (num > limite) limite = num; V.push_back(num); } sort(V.begin(), V.end()); cout << crivo(limite, n) << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; vector<int> V; vector<int> resposta; int vis[1001000]; int crivo(int limite, int ind) { int cont = 0; for (int i = 0; i < ind; i++) { if (vis[V[i]] == 0) { vis[V[i]] = 2; cont++; for (int j = 2 * V[i]; j <= limite; j += V[i]) vis[j] = 1; } else if (vis[V[i]] == 2) { // Ja foi contado vis[V[i]] = 3; cont--; } } return cont; } int main() { int n; cin >> n; int limite = 0; for (int i = 0; i < n; i++) { int num; cin >> num; if (num > limite) limite = num; V.push_back(num); } sort(V.begin(), V.end()); cout << crivo(limite, n) << endl; return 0; }
replace
7
8
7
8
0
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define FAST \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define show(x) cout << (x) << endl #define REP(i, a, n) for (int i = a; i < n; i++) #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define UM unordered_map #define PB push_back #define V vector #define EPS 1e-8 typedef unsigned long ul; typedef long long ll; typedef string str; /*FIN*/ set<int> m; map<ul, ul> f; ul a[200001]; ul n, ans; int main() { FAST; cin >> n; REP(i, 0, n) cin >> a[i]; sort(a, a + n); REP(i, 0, n) { if (!f.count(a[i])) f[a[i]] = 0; f[a[i]]++; } ans = 0; REP(i, 0, n) { if (f[a[i]] == 1) { bool ff = 1; for (auto t : m) { if (a[i] % t == 0) ff = 0; } if (ff) ans++; } m.insert(a[i]); } show(ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define FAST \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define show(x) cout << (x) << endl #define REP(i, a, n) for (int i = a; i < n; i++) #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define UM unordered_map #define PB push_back #define V vector #define EPS 1e-8 typedef unsigned long ul; typedef long long ll; typedef string str; /*FIN*/ set<int> m; map<ul, ul> f; ul a[200001]; ul n, ans; int main() { FAST; cin >> n; REP(i, 0, n) cin >> a[i]; sort(a, a + n); REP(i, 0, n) { if (!f.count(a[i])) f[a[i]] = 0; f[a[i]]++; } ans = 0; REP(i, 0, n) { if (!m.count(a[i]) and f[a[i]] == 1) ans++; for (ul j = a[i]; j <= a[n - 1]; j += a[i]) m.insert(j); } show(ans); return 0; }
replace
35
45
35
39
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long int using namespace std; /* // AUTHOR wiley_codechef // TASK : Atcoder //--------------------------------HEADERS-------------------------------------------------------------// #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; //-------------------------------------------------------Typedefs----------------------------------------------// typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<string, string> pss; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vii; typedef vector<ll> vl; typedef vector<vl> vvl; double EPS = 1e-9; int INF = 1000000005; long long INFF = 1000000000000000005LL; double PI = acos(-1); int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 }; int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 }; //---------------------------------------------------------Hash defines--------------------------------------------------// # define PII 3.14159265358979323846 #ifdef TESTING #define DEBUG fprintf(stderr, "====TESTING====\n") #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl #define debug(...) fprintf(stderr, __VA_ARGS__) #else #define DEBUG #define VALUE(x) #define debug(...) #endif #define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) #define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a)) #define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a)) #define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a)) #define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a)) #define FOREACH(a, b) for (auto&(a) : (b)) #define REP(i, n) FOR(i, 0, n) #define REPN(i, n) FORN(i, 1, n) #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define SQR(x) ((ll)(x) * (x)) #define RESET(a, b) memset(a, b, sizeof(a)) #define fi first #define se second #define mp make_pair #define pb push_back #define ALL(v) v.begin(), v.end() #define ALLA(arr, sz) arr, arr + sz #define SIZE(v) (int)v.size() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define SORTA(arr, sz) sort(ALLA(arr, sz)) #define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) #define PERMUTE next_permutation #define T(a) ll a; cin >> a; #define TT(t) T(t); while (t--) #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define f(i, x, y) for(int i = x; i < y; i++) #define array(a) ll a[n]; #define line "\n"; //-------------------------------------------------TEMPLATES----------------------------------------------------------// template<class T> T max(T a, T b, T c) { return max(a, max(b, c)); } template<class T> T min(T a, T b, T c) { return min(a, min(b, c)); } void SieveOfEratosthenes(ll n)//O(nloglogn) { ll prime[n]; memset(prime, true, sizeof(prime)); for (ll p = 2; p * p <= n; p++) { if (prime[p] == true) { for (ll i = p * p; i <= n; i += p) prime[i] = false; } } } bool isPrime(ll n)//O(sqrt(n)) { if (n < 2) return false; for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } std::vector<ll> generatePrimeFactors(ll n) { std::vector<ll> prime; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { prime.pb(i); while (n % i == 0) n = n / i; } } if (n != 1) prime.pb(n); return prime; } std::vector<ll> generateFactors(ll n) { std::vector<ll> fact; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { fact.pb(i); if (n / i != i) fact.pb(n / i); //24 - 1,2,3,4,6,8,12 } } fact.pb(1); if (n != 1) fact.pb(n); sort(fact.begin(), fact.end()); return fact; } ll extendedGCD(ll a, ll b, ll &x, ll &y) { //produces correct results for negative integers as well if (a == 0) { x = 0; y = 1; return b; } ll x1, y1, d; d = extendedGCD(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return d; } ll gcd(ll a, ll b) //O(log min(a,b)) { /* recursive implementation below if(!b) return a; return gcd(b,a%b); */ int n, ans; vector<int> v(200010); unordered_map<int, int> M; int main() { cin >> n; for (int i = 0; i < n; i++) { 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; }
#include <bits/stdc++.h> #define ll long long int using namespace std; /* // AUTHOR wiley_codechef // TASK : Atcoder //--------------------------------HEADERS-------------------------------------------------------------// #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; */ int n, ans; vector<int> v(200010); unordered_map<int, int> M; int main() { cin >> n; for (int i = 0; i < n; i++) { 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; }
replace
33
203
33
34
TLE
p02642
C++
Runtime Error
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; const int M = 1000005; int main(void) { int N; cin >> N; vector<int> A(N, 0); for (int i = 0; i < N; i++) { cin >> A[i]; } int ans(0); vector<int> dp(M, 0); int p; for (auto e : A) { if (dp[p] != 0) { dp[p] = 2; continue; } for (p = e; p < M; p += e) { dp.at(p)++; } } for (auto e : A) { if (dp[e] == 1) ans++; } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; const int M = 1000005; int main(void) { int N; cin >> N; vector<int> A(N, 0); for (int i = 0; i < N; i++) { cin >> A[i]; } int ans(0); vector<int> dp(M, 0); int p; for (auto e : A) { if (dp[e] != 0) { dp[e] = 2; continue; } for (p = e; p < M; p += e) { dp.at(p)++; } } for (auto e : A) { if (dp[e] == 1) ans++; } cout << ans << endl; return 0; }
replace
22
24
22
24
0
p02642
Python
Runtime Error
from collections import Counter n = int(input()) alist = [int(v) for v in input().split()] dup_set = {k for k, v in Counter(alist).items() if v >= 2} alist = sorted(set(alist)) adict = {a: False for a in alist} a_max = alist[-1] max_ind = -1 count = 0 if 1 in adict: count = 0 if 1 in dup_set else 1 else: for a, f in adict.items(): if f: continue if a not in dup_set: count += 1 for k in range(a, a_max + 1, a): if k in adict: adict[k] = True if k == a_max: max_ind -= 1 a_max = alist[max_ind] print(count)
from collections import Counter n = int(input()) alist = [int(v) for v in input().split()] dup_set = {k for k, v in Counter(alist).items() if v >= 2} alist = sorted(set(alist)) adict = {a: False for a in alist} a_max = alist[-1] max_ind = -1 count = 0 if 1 in adict: count = 0 if 1 in dup_set else 1 else: for a, f in adict.items(): if f: continue if a not in dup_set: count += 1 for k in range(a, a_max + 1, a): if k in adict: adict[k] = True if k == a_max: max_ind -= 1 if abs(max_ind) <= len(alist): a_max = alist[max_ind] print(count)
replace
24
25
24
26
0
p02642
Python
Runtime Error
from numba import njit @njit(cache=True) def fact(x): i = 1 while i * i <= x: if x % i == 0: yield i yield x // i i += 1 def main(): n = int(input()) a = tuple(map(int, input().split())) c = [0] * (max(a) + 1) for e in a: c[e] += 1 ans = n for e in a: c[e] -= 1 for fct in fact(e): if c[fct]: ans -= 1 break c[e] += 1 print(ans) if __name__ == "__main__": main()
from numba import njit @njit(fastmath=True) def fact(x): i = 1 while i * i <= x: if x % i == 0: yield i yield x // i i += 1 def main(): n = int(input()) a = tuple(map(int, input().split())) c = [0] * (max(a) + 1) for e in a: c[e] += 1 ans = n for e in a: c[e] -= 1 for fct in fact(e): if c[fct]: ans -= 1 break c[e] += 1 print(ans) if __name__ == "__main__": main()
replace
3
4
3
4
ModuleNotFoundError: No module named 'numba'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02642/Python/s936960783.py", line 1, in <module> from numba import njit ModuleNotFoundError: No module named 'numba'
p02642
C++
Time Limit Exceeded
#include <algorithm> #include <cassert> #include <cstdio> #include <cstdlib> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define repi(i, a, b) for (ll i = (a); i < (b); ++i) #define rep(i, a) repi(i, 0, a) #define repdi(i, a, b) for (ll i = (a)-1; i >= (b); --i) #define repd(i, a) repdi(i, a, 0) #define itr(it, a) for (auto it = (a).begin(); it != (a).end(); ++it) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() using ll = long long; using P = std::pair<ll, ll>; constexpr ll INF = 1ll << 60; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class S, class T> std::ostream &operator<<(std::ostream &out, const std::pair<S, T> &a) { std::cout << '(' << a.first << ", " << a.second << ')'; return out; } template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &a) { std::cout << '['; rep(i, a.size()) { std::cout << a[i]; if (i != a.size() - 1) std::cout << ", "; } std::cout << ']'; return out; } std::vector<ll> divisors(ll x) { std::vector<ll> ret; for (ll i = 1; i * i <= x; ++i) if (x % i == 0) { ret.emplace_back(i); if (i != x / i) ret.emplace_back(x / i); } return ret; } std::map<ll, ll> prime_factor(ll x) { std::map<ll, ll> ret; for (ll i = 2; i * i <= x; ++i) { while (x % i == 0) { ++ret[i]; x /= i; } } if (x != 1) ++ret[x]; return ret; } ll N; ll A[200010]; std::map<ll, ll> mp; ll ans; int main() { std::cin >> N; rep(i, N) { std::cin >> A[i]; ++mp[A[i]]; } rep(i, N) { auto ds = divisors(A[i]); bool fl = true; for (auto d : ds) { fl &= d == A[i] ? mp[d] == 1 : !mp[d]; if (!fl) break; } if (fl) ++ans; } std::cout << ans << std::endl; return 0; }
#include <algorithm> #include <cassert> #include <cstdio> #include <cstdlib> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define repi(i, a, b) for (ll i = (a); i < (b); ++i) #define rep(i, a) repi(i, 0, a) #define repdi(i, a, b) for (ll i = (a)-1; i >= (b); --i) #define repd(i, a) repdi(i, a, 0) #define itr(it, a) for (auto it = (a).begin(); it != (a).end(); ++it) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() using ll = long long; using P = std::pair<ll, ll>; constexpr ll INF = 1ll << 60; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class S, class T> std::ostream &operator<<(std::ostream &out, const std::pair<S, T> &a) { std::cout << '(' << a.first << ", " << a.second << ')'; return out; } template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &a) { std::cout << '['; rep(i, a.size()) { std::cout << a[i]; if (i != a.size() - 1) std::cout << ", "; } std::cout << ']'; return out; } std::vector<ll> divisors(ll x) { std::vector<ll> ret; for (ll i = 1; i * i <= x; ++i) if (x % i == 0) { ret.emplace_back(i); if (i != x / i) ret.emplace_back(x / i); } return ret; } std::map<ll, ll> prime_factor(ll x) { std::map<ll, ll> ret; for (ll i = 2; i * i <= x; ++i) { while (x % i == 0) { ++ret[i]; x /= i; } } if (x != 1) ++ret[x]; return ret; } ll N; ll A[200010]; ll mp[2000010]; ll ans; int main() { std::cin >> N; rep(i, N) { std::cin >> A[i]; ++mp[A[i]]; } rep(i, N) { auto ds = divisors(A[i]); bool fl = true; for (auto d : ds) { fl &= d == A[i] ? mp[d] == 1 : !mp[d]; if (!fl) break; } if (fl) ++ans; } std::cout << ans << std::endl; return 0; }
replace
91
92
91
92
TLE
p02642
C++
Runtime Error
/**Function Template**/ #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pint; const int MAX = 510000; const int MOD = 1000000007; #define rep(i, n) for (ll i = ll(0); i < ll(n); i++) #define Rep(i, n) for (ll i = ll(1); i < ll(n); i++) #define ALL(a) (a).begin(), (a).end() #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define PI 3.14159265358979323846 #define ifYN(x) cout << (x ? "Yes" : "No") << "\n" ll fac[MAX], finv[MAX], inv[MAX]; 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; } bool palindrome(string s) { bool flag = true; rep(i, (ll)s.size()) if (s[i] != s[s.size() - 1 - i]) flag = false; return flag; } // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll Len(ll n) { ll s = 0; while (n != 0) s++, n /= 10; return s; } ll Sint(ll n) { ll m = 0, s = 0, a = n; while (a != 0) s++, a /= 10; for (ll i = s - 1; i >= 0; i--) m += n / ((ll)pow(10, i)) - (n / ((ll)pow(10, i + 1))) * 10; return m; } ll Svec(vector<ll> v) { ll n = 0; rep(i, (ll)v.size()) n += v[i]; return n; } ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } ll LCM(ll a, ll b) { return a / GCD(a, b) * b; } ll Factorial(ll n) { ll m = 1; while (n >= 1) m *= n, n--; return m; } void runlength(string s, vector<pair<char, ll>> &p) { ll x = 1; if (s.size() == 1) { p.push_back(pair<char, ll>(s[0], 1)); } rep(i, (ll)s.size() - 1) { if (s[i] == s[i + 1]) { x++; if (i == (ll)s.size() - 2) { p.push_back(pair<char, ll>(s[i], x)); } } else { p.push_back(pair<char, ll>(s[i], x)); x = 1; if (i == (ll)s.size() - 2) { p.push_back(pair<char, ll>(s[s.size() - 1], x)); } } } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } string Toupper(string s) { string ans = ""; rep(i, s.size()) { if ('a' <= s[i] && s[i] <= 'z') ans += (char)s[i] - 32; else ans += s[i]; } return ans; } string Tolower(string s) { string ans = ""; rep(i, s.size()) { if ('A' <= s[i] && s[i] <= 'Z') ans += (char)s[i] + 32; else ans += s[i]; } return ans; } void dis(vector<ll> v) { rep(i, v.size()) cout << v[i] << endl; } const int MAX_N = 100010; vector<bool> sieve_of_eratosthenes() { vector<bool> isPrime(MAX_N + 1, true); /* isPrime[1]=false; */ for (int i = 2; i <= MAX_N; i++) { if (isPrime[i]) { for (int j = 2 * i; j <= MAX_N; j += i) { isPrime[j] = false; } } } return isPrime; } vector<pint> prime_factorize(ll n) { vector<pint> ans; for (ll p = 2; p <= sqrt(n); p++) { if (n % p != 0) continue; ll cnt = 0; while (n % p == 0) { n /= p; cnt++; } ans.push_back(make_pair(p, cnt)); } if (n != 1) ans.push_back(make_pair(n, 1)); return ans; } /*bool cmp(pint a, pint b) { return a.second < b.second; }*/ /* 約数列挙 */ vector<ll> divisor(ll n) { // O(√n) vector<ll> ans; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ans.push_back(i); if (i * i != n) ans.push_back(n / i); } } sort(ALL(ans)); return ans; } /*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/ int main() { IOS; ll n; cin >> n; vector<ll> v(200010, false), a(n); map<ll, ll> mp; ll ans = 0; rep(i, n) { cin >> a[i]; v[a[i]] = true; mp[a[i]]++; } rep(i, n) { if (mp[a[i]] > 1) continue; vector<ll> tmp = divisor(a[i]); bool flag = true; rep(j, tmp.size() - 1) if (v[tmp[j]]) flag = false; if (flag) ans++; } cout << ans << endl; }
/**Function Template**/ #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pint; const int MAX = 510000; const int MOD = 1000000007; #define rep(i, n) for (ll i = ll(0); i < ll(n); i++) #define Rep(i, n) for (ll i = ll(1); i < ll(n); i++) #define ALL(a) (a).begin(), (a).end() #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define PI 3.14159265358979323846 #define ifYN(x) cout << (x ? "Yes" : "No") << "\n" ll fac[MAX], finv[MAX], inv[MAX]; 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; } bool palindrome(string s) { bool flag = true; rep(i, (ll)s.size()) if (s[i] != s[s.size() - 1 - i]) flag = false; return flag; } // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll Len(ll n) { ll s = 0; while (n != 0) s++, n /= 10; return s; } ll Sint(ll n) { ll m = 0, s = 0, a = n; while (a != 0) s++, a /= 10; for (ll i = s - 1; i >= 0; i--) m += n / ((ll)pow(10, i)) - (n / ((ll)pow(10, i + 1))) * 10; return m; } ll Svec(vector<ll> v) { ll n = 0; rep(i, (ll)v.size()) n += v[i]; return n; } ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } ll LCM(ll a, ll b) { return a / GCD(a, b) * b; } ll Factorial(ll n) { ll m = 1; while (n >= 1) m *= n, n--; return m; } void runlength(string s, vector<pair<char, ll>> &p) { ll x = 1; if (s.size() == 1) { p.push_back(pair<char, ll>(s[0], 1)); } rep(i, (ll)s.size() - 1) { if (s[i] == s[i + 1]) { x++; if (i == (ll)s.size() - 2) { p.push_back(pair<char, ll>(s[i], x)); } } else { p.push_back(pair<char, ll>(s[i], x)); x = 1; if (i == (ll)s.size() - 2) { p.push_back(pair<char, ll>(s[s.size() - 1], x)); } } } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } string Toupper(string s) { string ans = ""; rep(i, s.size()) { if ('a' <= s[i] && s[i] <= 'z') ans += (char)s[i] - 32; else ans += s[i]; } return ans; } string Tolower(string s) { string ans = ""; rep(i, s.size()) { if ('A' <= s[i] && s[i] <= 'Z') ans += (char)s[i] + 32; else ans += s[i]; } return ans; } void dis(vector<ll> v) { rep(i, v.size()) cout << v[i] << endl; } const int MAX_N = 100010; vector<bool> sieve_of_eratosthenes() { vector<bool> isPrime(MAX_N + 1, true); /* isPrime[1]=false; */ for (int i = 2; i <= MAX_N; i++) { if (isPrime[i]) { for (int j = 2 * i; j <= MAX_N; j += i) { isPrime[j] = false; } } } return isPrime; } vector<pint> prime_factorize(ll n) { vector<pint> ans; for (ll p = 2; p <= sqrt(n); p++) { if (n % p != 0) continue; ll cnt = 0; while (n % p == 0) { n /= p; cnt++; } ans.push_back(make_pair(p, cnt)); } if (n != 1) ans.push_back(make_pair(n, 1)); return ans; } /*bool cmp(pint a, pint b) { return a.second < b.second; }*/ /* 約数列挙 */ vector<ll> divisor(ll n) { // O(√n) vector<ll> ans; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ans.push_back(i); if (i * i != n) ans.push_back(n / i); } } sort(ALL(ans)); return ans; } /*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/ int main() { IOS; ll n; cin >> n; vector<ll> v(1000010, false), a(n); map<ll, ll> mp; ll ans = 0; rep(i, n) { cin >> a[i]; v[a[i]] = true; mp[a[i]]++; } rep(i, n) { if (mp[a[i]] > 1) continue; vector<ll> tmp = divisor(a[i]); bool flag = true; rep(j, tmp.size() - 1) if (v[tmp[j]]) flag = false; if (flag) ans++; } cout << ans << endl; }
replace
197
198
197
198
0
p02642
C++
Time Limit Exceeded
#ifdef DEBUG #else #pragma GCC optimize("O3,no-stack-protector") #pragma GCC optimize("unroll-loops") #if __cplusplus < 201703L #pragma GCC target("avx") #else #pragma GCC target("avx2") #endif #endif #define _USE_MATH_DEFINES #include <bits/stdc++.h> #define dump(x) cout << x << endl typedef int64_t Int; typedef long double Ld; using namespace std; using Graph = vector<vector<Int>>; template <typename T> using vec = vector<T>; template <typename T> using vec2 = vector<vector<T>>; template <typename T> using vec3 = vector<vector<vector<T>>>; const Ld pi = M_PI; const Int MOD = 1000000007; const Int INF = 1LL << 61; Int Floor(Int a, Int b) { return (a - (a % b)) / b; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); const int inf = 1000000; int n; cin >> n; vec<int> a(n), cnt(inf + 10, 0); for (int i = 0; i < n; i++) { cin >> a[i]; cnt[a[i]]++; } sort(a.begin(), a.end()); int ans = 0; vec<bool> isok(inf + 10, true); for (int i = 0; i < n; i++) { if (isok[a[i]] && cnt[a[i]] == 1) { ans++; } for (int j = 1;; j++) { int mult = j * a[i]; if (mult <= inf) { isok[mult] = false; } else { break; } } } cout << ans << endl; return 0; }
#ifdef DEBUG #else #pragma GCC optimize("O3,no-stack-protector") #pragma GCC optimize("unroll-loops") #if __cplusplus < 201703L #pragma GCC target("avx") #else #pragma GCC target("avx2") #endif #endif #define _USE_MATH_DEFINES #include <bits/stdc++.h> #define dump(x) cout << x << endl typedef int64_t Int; typedef long double Ld; using namespace std; using Graph = vector<vector<Int>>; template <typename T> using vec = vector<T>; template <typename T> using vec2 = vector<vector<T>>; template <typename T> using vec3 = vector<vector<vector<T>>>; const Ld pi = M_PI; const Int MOD = 1000000007; const Int INF = 1LL << 61; Int Floor(Int a, Int b) { return (a - (a % b)) / b; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); const int inf = 1000000; int n; cin >> n; vec<int> a(n), cnt(inf + 10, 0); for (int i = 0; i < n; i++) { cin >> a[i]; cnt[a[i]]++; } sort(a.begin(), a.end()); int ans = 0; vec<bool> isok(inf + 10, true); for (int i = 0; i < n; i++) { if (isok[a[i]] && cnt[a[i]] == 1) { ans++; } if (isok[a[i]]) { for (int j = 1;; j++) { int mult = j * a[i]; if (mult <= inf) { isok[mult] = false; } else { break; } } } } cout << ans << endl; return 0; }
replace
58
64
58
66
TLE
p02642
C++
Runtime Error
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <locale> #include <map> #include <numeric> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; // typedef //------------------------------------------ typedef long long LL; typedef vector<int> VI; typedef vector<bool> VB; typedef vector<char> VC; typedef vector<double> VD; typedef vector<string> VS; typedef vector<LL> VLL; typedef vector<VI> VVI; typedef vector<VB> VVB; typedef vector<VS> VVS; typedef vector<VLL> VVLL; typedef vector<VVI> VVVI; typedef vector<VVLL> VVVLL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef pair<int, string> PIS; typedef pair<string, int> PSI; typedef pair<string, string> PSS; typedef vector<PII> VPII; typedef vector<PLL> VPLL; typedef vector<VPII> VVPII; typedef vector<VPLL> VVPLL; typedef vector<VS> VVS; typedef map<int, int> MII; typedef map<LL, LL> MLL; typedef map<string, int> MSI; typedef map<int, string> MIS; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define SZ(a) int((a).size()) #define EACH(i, arr) \ for (typeof((arr).begin()) i = (arr).begin(); i != (arr).end(); ++i) #define EXIST(str, e) ((str).find(e) != (str).end()) #define COUNT(arr, v) count((arr).begin(), (arr).end(), v) #define SEARCH(v, w) search((v).begin(), (v).end(), (w).begin(), (w).end()) #define SORT(c) sort((c).begin(), (c).end()) #define RSORT(c) sort((c).rbegin(), (c).rend()) #define REVERSE(c) reverse((c).begin(), (c).end()) #define ROTATE_LEFT(arr, c) \ rotate((arr).begin(), (arr).begin() + (c), (arr).end()) #define ROTATE_RIGHT(arr, c) \ rotate((arr).rbegin(), (arr).rbegin() + (c), (arr).rend()) #define SUMI(arr) accumulate((arr).begin(), (arr).end(), 0) #define SUMD(arr) accumulate((arr).begin(), (arr).end(), 0.) #define SUMLL(arr) accumulate((arr).begin(), (arr).end(), 0LL) #define MULD(arr) \ accumulate((arr).begin(), (arr).end(), 1., multiplies<double>()) #define UB(arr, n) upper_bound((arr).begin(), (arr).end(), n) #define LB(arr, n) lower_bound((arr).begin(), (arr).end(), n) #define PB push_back #define MP make_pair #define ft first #define sd second // input output //------------------------------------------ #define GL(s) getline(cin, (s)) #define INIT() \ std::ios::sync_with_stdio(false); \ std::cin.tie(0) #define OUT(d) std::cout << (d) #define OUT_L(d) std::cout << (d) << endl #define FOUT(n, data) std::cout << std::fixed << std::setprecision(n) << (data) #define FOUT_L(n, data) \ std::cout << std::fixed << std::setprecision(n) << (data) << "\n" #define EL() printf("\n") #define SHOW_VECTOR(v) \ { \ std::cerr << #v << "\t:"; \ for (const auto &xxx : v) { \ std::cerr << xxx << " "; \ } \ std::cerr << "\n"; \ } #define SHOW_MAP(v) \ { \ std::cerr << #v << endl; \ for (const auto &xxx : v) { \ std::cerr << xxx.first << " " << xxx.second << "\n"; \ } \ } #define Yes() printf("Yes\n") #define No() printf("No\n") #define YES() printf("YES\n") #define NO() printf("NO\n") #define Yay() printf("Yay!\n") #define Nnn() printf(":(\n") #define CE(x, y) ((x + y - 1) / (y)) template <typename T1, typename T2> istream &operator>>(istream &in, pair<T1, T2> &p) { in >> p.first >> p.second; return in; } template <typename T> istream &operator>>(istream &in, vector<T> &v) { for (auto &x : v) in >> x; return in; } template <typename T1, typename T2> ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) { out << "[" << p.first << ", " << p.second << "]" << "\n"; return out; } template <class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true; } return false; } template <class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true; } return false; } // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) for (int i = n - 1; i >= 0; i--) #define FORLL(i, a, b) for (LL i = LL(a); i < LL(b); ++i) #define RFORLL(i, a, b) for (LL i = LL(b) - 1; i >= LL(a); --i) #define REPLL(i, n) for (LL i = 0; i < LL(n); ++i) #define RREPLL(i, n) for (LL i = LL(n) - 1; i >= 0; --i) #define FOREACH(x, arr) for (auto &(x) : (arr)) // Option + Control + K Terminal // Command + Control + K Run // Command + b EOF //------------------------------------------ //------------------------------------------ int MAX = 200020; int main() { int N; cin >> N; vector<int> A(N); cin >> A; SORT(A); vector<int> dp(MAX, 0); for (auto x : A) { if (dp[x] >= 2) continue; for (int i = x; i < MAX; i += x) dp[i]++; } int ans = 0; for (auto x : A) if (dp[x] == 1) ans++; cout << ans << endl; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <locale> #include <map> #include <numeric> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; // typedef //------------------------------------------ typedef long long LL; typedef vector<int> VI; typedef vector<bool> VB; typedef vector<char> VC; typedef vector<double> VD; typedef vector<string> VS; typedef vector<LL> VLL; typedef vector<VI> VVI; typedef vector<VB> VVB; typedef vector<VS> VVS; typedef vector<VLL> VVLL; typedef vector<VVI> VVVI; typedef vector<VVLL> VVVLL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef pair<int, string> PIS; typedef pair<string, int> PSI; typedef pair<string, string> PSS; typedef vector<PII> VPII; typedef vector<PLL> VPLL; typedef vector<VPII> VVPII; typedef vector<VPLL> VVPLL; typedef vector<VS> VVS; typedef map<int, int> MII; typedef map<LL, LL> MLL; typedef map<string, int> MSI; typedef map<int, string> MIS; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define SZ(a) int((a).size()) #define EACH(i, arr) \ for (typeof((arr).begin()) i = (arr).begin(); i != (arr).end(); ++i) #define EXIST(str, e) ((str).find(e) != (str).end()) #define COUNT(arr, v) count((arr).begin(), (arr).end(), v) #define SEARCH(v, w) search((v).begin(), (v).end(), (w).begin(), (w).end()) #define SORT(c) sort((c).begin(), (c).end()) #define RSORT(c) sort((c).rbegin(), (c).rend()) #define REVERSE(c) reverse((c).begin(), (c).end()) #define ROTATE_LEFT(arr, c) \ rotate((arr).begin(), (arr).begin() + (c), (arr).end()) #define ROTATE_RIGHT(arr, c) \ rotate((arr).rbegin(), (arr).rbegin() + (c), (arr).rend()) #define SUMI(arr) accumulate((arr).begin(), (arr).end(), 0) #define SUMD(arr) accumulate((arr).begin(), (arr).end(), 0.) #define SUMLL(arr) accumulate((arr).begin(), (arr).end(), 0LL) #define MULD(arr) \ accumulate((arr).begin(), (arr).end(), 1., multiplies<double>()) #define UB(arr, n) upper_bound((arr).begin(), (arr).end(), n) #define LB(arr, n) lower_bound((arr).begin(), (arr).end(), n) #define PB push_back #define MP make_pair #define ft first #define sd second // input output //------------------------------------------ #define GL(s) getline(cin, (s)) #define INIT() \ std::ios::sync_with_stdio(false); \ std::cin.tie(0) #define OUT(d) std::cout << (d) #define OUT_L(d) std::cout << (d) << endl #define FOUT(n, data) std::cout << std::fixed << std::setprecision(n) << (data) #define FOUT_L(n, data) \ std::cout << std::fixed << std::setprecision(n) << (data) << "\n" #define EL() printf("\n") #define SHOW_VECTOR(v) \ { \ std::cerr << #v << "\t:"; \ for (const auto &xxx : v) { \ std::cerr << xxx << " "; \ } \ std::cerr << "\n"; \ } #define SHOW_MAP(v) \ { \ std::cerr << #v << endl; \ for (const auto &xxx : v) { \ std::cerr << xxx.first << " " << xxx.second << "\n"; \ } \ } #define Yes() printf("Yes\n") #define No() printf("No\n") #define YES() printf("YES\n") #define NO() printf("NO\n") #define Yay() printf("Yay!\n") #define Nnn() printf(":(\n") #define CE(x, y) ((x + y - 1) / (y)) template <typename T1, typename T2> istream &operator>>(istream &in, pair<T1, T2> &p) { in >> p.first >> p.second; return in; } template <typename T> istream &operator>>(istream &in, vector<T> &v) { for (auto &x : v) in >> x; return in; } template <typename T1, typename T2> ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) { out << "[" << p.first << ", " << p.second << "]" << "\n"; return out; } template <class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true; } return false; } template <class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true; } return false; } // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) for (int i = n - 1; i >= 0; i--) #define FORLL(i, a, b) for (LL i = LL(a); i < LL(b); ++i) #define RFORLL(i, a, b) for (LL i = LL(b) - 1; i >= LL(a); --i) #define REPLL(i, n) for (LL i = 0; i < LL(n); ++i) #define RREPLL(i, n) for (LL i = LL(n) - 1; i >= 0; --i) #define FOREACH(x, arr) for (auto &(x) : (arr)) // Option + Control + K Terminal // Command + Control + K Run // Command + b EOF //------------------------------------------ //------------------------------------------ int MAX = 2000020; int main() { int N; cin >> N; vector<int> A(N); cin >> A; SORT(A); vector<int> dp(MAX, 0); for (auto x : A) { if (dp[x] >= 2) continue; for (int i = x; i < MAX; i += x) dp[i]++; } int ans = 0; for (auto x : A) if (dp[x] == 1) ans++; cout << ans << endl; }
replace
185
186
185
186
0
p02642
Python
Time Limit Exceeded
n = int(input()) a = list(map(int, input().split())) cand = set(a) exist = set() dup = set() for item in a: if item in exist: dup.add(item) else: exist.add(item) dame_set = set() a.sort() ret = 0 for val in a: if val in dup: i = 1 cnt = 10**6 // val while i <= cnt: tmp = i * val if tmp in cand: dame_set.add(tmp) i += 1 else: if val in dame_set: continue else: ret += 1 i = 1 cnt = 10**6 // val while i <= cnt: tmp = i * val if tmp in cand: dame_set.add(tmp) i += 1 print(ret)
n = int(input()) a = list(map(int, input().split())) cand = set(a) exist = set() dup = set() for item in a: if item in exist: dup.add(item) else: exist.add(item) dame_set = set() a.sort() ret = 0 for val in a: if val in dup: if val in dame_set: continue else: i = 1 cnt = 10**6 // val while i <= cnt: tmp = i * val if tmp in cand: dame_set.add(tmp) i += 1 else: if val in dame_set: continue else: ret += 1 i = 1 cnt = 10**6 // val while i <= cnt: tmp = i * val if tmp in cand: dame_set.add(tmp) i += 1 print(ret)
replace
20
27
20
30
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < int(N); ++i) #define rep1(i, N) for (int i = 1; i < int(N); ++i) #define all(a) (a).begin(), (a).end() #define print(v) \ { \ cerr << #v << ": [ "; \ for (auto _ : v) \ cerr << _ << ", "; \ cerr << "]" << endl; \ } #define printpair(v) \ { \ cerr << #v << ": [ "; \ for (auto _ : v) \ cerr << "{" << _.first << "," << _.second << "}" \ << ", "; \ cerr << "]" << endl; \ } #define dump(x) cerr << #x << ": " << x << endl; #define bit(k) (1LL << (k)) typedef long long ll; typedef pair<int, int> i_i; typedef pair<ll, ll> l_l; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "{" << p.first << ", " << p.second << "}"; return os; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int INF = (ll)1e9; const ll INFLL = (ll)1e18 + 1; const ll MOD = (ll)1e9 + 7; const double PI = acos(-1.0); /* const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const string dir = "DRUL"; */ template <typename T> vector<T> divisor(T N) { vector<T> res; for (T i = 1; i * i <= N; i++) { if (N % i == 0) { res.push_back(i); if (i * i != N) res.push_back(N / i); } } sort(res.begin(), res.end()); return res; } template <typename T> map<T, int> factorize(T x) { map<T, int> mp; for (T i = 2; i * i <= x; i++) { while (x % i == 0) { x /= i; mp[i]++; } if (x == 1) break; } if (x != 1) mp[x]++; return mp; } int A[200010]; int mp[200010]; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int N; cin >> N; // map<ll,int> mp; rep(i, N) { cin >> A[i]; mp[A[i]]++; } // sort(all(A)); int ans = 0; vector<bool> ok(N, true); rep(i, N) { /* auto v = divisor(A[i]); for(auto &p: v){ if(mp[p] > 0){ ok = false; break; } }*/ if (mp[A[i]] > 1) { ok[i] = false; continue; } mp[A[i]]--; for (ll j = 1; j * j <= A[i]; j++) { if (A[i] % j == 0) { // res.push_back(i); if (mp[j] > 0) { ok[i] = false; } if (j * j != A[i]) { // res.push_back(N / i); if (mp[A[i] / j] > 0) { ok[i] = false; } } } } mp[A[i]]++; } rep(i, N) if (ok[i]) ans++; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < int(N); ++i) #define rep1(i, N) for (int i = 1; i < int(N); ++i) #define all(a) (a).begin(), (a).end() #define print(v) \ { \ cerr << #v << ": [ "; \ for (auto _ : v) \ cerr << _ << ", "; \ cerr << "]" << endl; \ } #define printpair(v) \ { \ cerr << #v << ": [ "; \ for (auto _ : v) \ cerr << "{" << _.first << "," << _.second << "}" \ << ", "; \ cerr << "]" << endl; \ } #define dump(x) cerr << #x << ": " << x << endl; #define bit(k) (1LL << (k)) typedef long long ll; typedef pair<int, int> i_i; typedef pair<ll, ll> l_l; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "{" << p.first << ", " << p.second << "}"; return os; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int INF = (ll)1e9; const ll INFLL = (ll)1e18 + 1; const ll MOD = (ll)1e9 + 7; const double PI = acos(-1.0); /* const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const string dir = "DRUL"; */ template <typename T> vector<T> divisor(T N) { vector<T> res; for (T i = 1; i * i <= N; i++) { if (N % i == 0) { res.push_back(i); if (i * i != N) res.push_back(N / i); } } sort(res.begin(), res.end()); return res; } template <typename T> map<T, int> factorize(T x) { map<T, int> mp; for (T i = 2; i * i <= x; i++) { while (x % i == 0) { x /= i; mp[i]++; } if (x == 1) break; } if (x != 1) mp[x]++; return mp; } int A[200010]; int mp[2000100]; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int N; cin >> N; // map<ll,int> mp; rep(i, N) { cin >> A[i]; mp[A[i]]++; } // sort(all(A)); int ans = 0; vector<bool> ok(N, true); rep(i, N) { /* auto v = divisor(A[i]); for(auto &p: v){ if(mp[p] > 0){ ok = false; break; } }*/ if (mp[A[i]] > 1) { ok[i] = false; continue; } mp[A[i]]--; for (ll j = 1; j * j <= A[i]; j++) { if (A[i] % j == 0) { // res.push_back(i); if (mp[j] > 0) { ok[i] = false; } if (j * j != A[i]) { // res.push_back(N / i); if (mp[A[i] / j] > 0) { ok[i] = false; } } } } mp[A[i]]++; } rep(i, N) if (ok[i]) ans++; cout << ans << endl; }
replace
84
85
84
85
0
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define sz(x) int(x.size()) typedef long long ll; typedef long double ld; typedef pair<int, int> P; vector<long long> divisor(long long n) { vector<long long> res; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { res.push_back(i); if (n / i != i) res.push_back(n / i); } } return res; } int main() { int n; cin >> n; vector<int> a(n); map<int, int> mp; rep(i, n) { cin >> a[i]; mp[a[i]]++; } int res = 0; for (int i = 0; i < n; i++) { auto div = divisor(a[i]); bool ok = true; mp[a[i]]--; for (auto e : div) if (mp[e] > 0) ok = false; if (ok) res++; mp[a[i]]++; } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define sz(x) int(x.size()) typedef long long ll; typedef long double ld; typedef pair<int, int> P; vector<long long> divisor(long long n) { vector<long long> res; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { res.push_back(i); if (n / i != i) res.push_back(n / i); } } return res; } int main() { int n; cin >> n; vector<int> a(n); unordered_map<int, int> mp; rep(i, n) { cin >> a[i]; mp[a[i]]++; } int res = 0; for (int i = 0; i < n; i++) { auto div = divisor(a[i]); bool ok = true; mp[a[i]]--; for (auto e : div) if (mp[e] > 0) ok = false; if (ok) res++; mp[a[i]]++; } cout << res << endl; return 0; }
replace
22
23
22
23
TLE
p02642
C++
Time Limit Exceeded
#include <algorithm> #include <assert.h> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using ll = long long; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; 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; int a[200010]; for (int i = 0; i < n; i++) { cin >> a[i]; } multiset<int> s; for (int i = 0; i < n; i++) { s.insert(a[i]); } int res = 0; for (int i = 0; i < n; i++) { s.erase(s.find(a[i])); auto div = divisor(a[i]); for (auto e : div) { if (s.find(e) != s.end()) { goto bad; } } res++; bad: s.insert(a[i]); } cout << res << endl; }
#include <algorithm> #include <assert.h> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using ll = long long; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; vector<int> divisor(int n) { vector<int> ret; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int a[200010]; for (int i = 0; i < n; i++) { cin >> a[i]; } multiset<int> s; for (int i = 0; i < n; i++) { s.insert(a[i]); } int res = 0; for (int i = 0; i < n; i++) { s.erase(s.find(a[i])); auto div = divisor(a[i]); for (auto e : div) { if (s.find(e) != s.end()) { goto bad; } } res++; bad: s.insert(a[i]); } cout << res << endl; }
replace
27
30
27
30
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define ll long long #define pp pair<ll, ll> #define ld long double #define all(a) (a).begin(), (a).end() #define mk make_pair ll MOD = 998244353; int inf = 1000001000; ll INF = 1e18 + 5; ll mod = INF; int main() { int n; cin >> n; vector<int> a(n + 1), b(2000000, 0); rep(i, n) { cin >> a[i]; } a[n] = inf; sort(all(a)); int ans = 0; rep(i, n) { if (b[a[i]] == 0 && a[i] != a[i + 1]) ans++; int c = a[i]; while (true) { if (c > 2000000) break; b[c] = 1; c += a[i]; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define ll long long #define pp pair<ll, ll> #define ld long double #define all(a) (a).begin(), (a).end() #define mk make_pair ll MOD = 998244353; int inf = 1000001000; ll INF = 1e18 + 5; ll mod = INF; int main() { int n; cin >> n; vector<int> a(n + 1), b(2000000, 0); rep(i, n) { cin >> a[i]; } a[n] = inf; sort(all(a)); int ans = 0; rep(i, n) { if (b[a[i]] == 0 && a[i] != a[i + 1]) ans++; if (b[a[i]] == 1) continue; int c = a[i]; while (true) { if (c > 2000000) break; b[c] = 1; c += a[i]; } } cout << ans << endl; }
insert
24
24
24
26
TLE
p02642
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef long double ld; typedef pair<ld, ld> LDP; typedef vector<vector<ll>> mat; typedef vector<ll> vec; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) #define all(v) (v).begin(), (v).end() const ll mod = 1000000007; const ll INF = mod * mod; const ld eps = 1e-12; const ld pi = acos(-1.0); // int qp(int a,ll b){int // ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;} ll qp(ll a, ll b, int mo) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } // 最大公約数 ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // 最小公倍数 int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << "(" << pa.first << "," << pa.second << ")"; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template <typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); } template <typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); } template <typename T> bool chmax(T &m, const T q) { if (m < q) { m = q; return true; } else return false; } template <typename T> bool chmin(T &m, const T q) { if (q < m) { m = q; return true; } else return false; } template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); } template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); } template <typename T1, typename T2> pair<T1, T2> operator<(const pair<T1, T2> l, const pair<T1, T2> r) { return (l.first < r.first); } template <typename T1, typename T2> pair<T1, T2> operator>(const pair<T1, T2> l, const pair<T1, T2> r) { return (l.first > r.first); } void solve() { int N; cin >> N; map<int, int> ok; vec A; rep(i, N) { int a; cin >> a; if (ok[a] > 0) ok[a]++; else { A.push_back(a); ok[a]++; } } int res = 0; for (auto a : A) { if (ok[a] > 1) continue; bool flg = true; for (int k = 1; k * k <= a; k++) { if (a % k == 0) { if (ok[k] > 0 && k != a) { flg = false; break; } if (ok[a / k] > 0 && (a / k) != a) { flg = false; break; } } } if (flg) res++; } cout << res << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); std::cout << fixed << setprecision(10); solve(); return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef long double ld; typedef pair<ld, ld> LDP; typedef vector<vector<ll>> mat; typedef vector<ll> vec; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) #define all(v) (v).begin(), (v).end() const ll mod = 1000000007; const ll INF = mod * mod; const ld eps = 1e-12; const ld pi = acos(-1.0); // int qp(int a,ll b){int // ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;} ll qp(ll a, ll b, int mo) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } // 最大公約数 ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // 最小公倍数 int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << "(" << pa.first << "," << pa.second << ")"; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template <typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); } template <typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); } template <typename T> bool chmax(T &m, const T q) { if (m < q) { m = q; return true; } else return false; } template <typename T> bool chmin(T &m, const T q) { if (q < m) { m = q; return true; } else return false; } template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); } template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); } template <typename T1, typename T2> pair<T1, T2> operator<(const pair<T1, T2> l, const pair<T1, T2> r) { return (l.first < r.first); } template <typename T1, typename T2> pair<T1, T2> operator>(const pair<T1, T2> l, const pair<T1, T2> r) { return (l.first > r.first); } void solve() { int N; cin >> N; unordered_map<int, int> ok; vec A; rep(i, N) { int a; cin >> a; if (ok[a] > 0) ok[a]++; else { A.push_back(a); ok[a]++; } } int res = 0; for (auto a : A) { if (ok[a] > 1) continue; bool flg = true; for (int k = 1; k * k <= a; k++) { if (a % k == 0) { if (ok[k] > 0 && k != a) { flg = false; break; } if (ok[a / k] > 0 && (a / k) != a) { flg = false; break; } } } if (flg) res++; } cout << res << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); std::cout << fixed << setprecision(10); solve(); return 0; }
replace
170
171
170
171
TLE
p02642
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long int ll; typedef long double ld; typedef pair<ll, ll> P; typedef pair<P, P> PP; const ll MOD = 998244353; const ll MAX_N = 500010; const ll INF = 100100100100100; 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<bool> visited(1001001, true); for (int i = 0; i < n - 1; i++) { if (a[i] == a[i + 1]) visited[a[i]] = false; } int ans = 0; for (int i = 0; i < n; i++) { int num = a[i]; if (visited[num]) ans++; for (int times = 1; num * times < 1001001; times++) { visited[num * times] = false; } } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long int ll; typedef long double ld; typedef pair<ll, ll> P; typedef pair<P, P> PP; const ll MOD = 998244353; const ll MAX_N = 500010; const ll INF = 100100100100100; 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<bool> visited(1001001, true); for (int i = 0; i < n - 1; i++) { if (a[i] == a[i + 1]) visited[a[i]] = false; } int ans = 0; for (int i = 0; i < n; i++) { int num = a[i]; if (i > 0 && a[i] == a[i - 1]) continue; if (visited[num]) ans++; for (int times = 1; num * times < 1001001; times++) { visited[num * times] = false; } } cout << ans << endl; }
insert
49
49
49
51
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; const ll mod = 1e9; const int inf = 0x3f3f3f3f; int a[200005]; int isp[1000005]; int boom[1000005]; vector<int> v; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; boom[a[i]]++; } int ans = 0; for (int i = 0; i <= 1000000; i++) { if (boom[i] == 1) v.push_back(i); else if (boom[i] >= 2) { int t = 1; while (i * t <= 1000000) { isp[v[i] * t] = 1; t++; } } } for (int i = 0; i < v.size(); i++) { if (isp[v[i]] == 0) { ans++; int t = 1; while (v[i] * t <= 1000000) { isp[v[i] * t] = 1; t++; } } } if (boom[1] > 1) ans = 0; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; const ll mod = 1e9; const int inf = 0x3f3f3f3f; int a[200005]; int isp[1000005]; int boom[1000005]; vector<int> v; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; boom[a[i]]++; } int ans = 0; for (int i = 0; i <= 1000000; i++) { if (boom[i] == 1) v.push_back(i); else if (boom[i] >= 2) { int t = 1; while (i * t <= 1000000) { isp[i * t] = 1; t++; } } } for (int i = 0; i < v.size(); i++) { if (isp[v[i]] == 0) { ans++; int t = 1; while (v[i] * t <= 1000000) { isp[v[i] * t] = 1; t++; } } } if (boom[1] > 1) ans = 0; cout << ans << endl; }
replace
24
25
24
25
0
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < int(N); ++i) #define rep1(i, N) for (int i = 1; i < int(N); ++i) #define all(a) (a).begin(), (a).end() #define print(v) \ { \ cerr << #v << ": [ "; \ for (auto _ : v) \ cerr << _ << ", "; \ cerr << "]" << endl; \ } #define printpair(v) \ { \ cerr << #v << ": [ "; \ for (auto _ : v) \ cerr << "{" << _.first << "," << _.second << "}" \ << ", "; \ cerr << "]" << endl; \ } #define dump(x) cerr << #x << ": " << x << endl; #define bit(k) (1LL << (k)) typedef long long ll; typedef pair<int, int> i_i; typedef pair<ll, ll> l_l; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "{" << p.first << ", " << p.second << "}"; return os; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int INF = (ll)1e9; const ll INFLL = (ll)1e18 + 1; const ll MOD = (ll)1e9 + 7; const double PI = acos(-1.0); /* const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const string dir = "DRUL"; */ int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int N; cin >> N; vector<ll> A(N); vector<ll> cnt(1000100, 0); vector<bool> ok(1000100, true); rep(i, N) { cin >> A[i]; cnt[A[i]]++; } sort(all(A)); int ans = 0; rep(i, N) { if (cnt[A[i]] == 1 && ok[A[i]]) ans++; for (int j = A[i]; j <= 1000000; j += A[i]) { ok[j] = false; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < int(N); ++i) #define rep1(i, N) for (int i = 1; i < int(N); ++i) #define all(a) (a).begin(), (a).end() #define print(v) \ { \ cerr << #v << ": [ "; \ for (auto _ : v) \ cerr << _ << ", "; \ cerr << "]" << endl; \ } #define printpair(v) \ { \ cerr << #v << ": [ "; \ for (auto _ : v) \ cerr << "{" << _.first << "," << _.second << "}" \ << ", "; \ cerr << "]" << endl; \ } #define dump(x) cerr << #x << ": " << x << endl; #define bit(k) (1LL << (k)) typedef long long ll; typedef pair<int, int> i_i; typedef pair<ll, ll> l_l; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "{" << p.first << ", " << p.second << "}"; return os; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int INF = (ll)1e9; const ll INFLL = (ll)1e18 + 1; const ll MOD = (ll)1e9 + 7; const double PI = acos(-1.0); /* const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const string dir = "DRUL"; */ int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int N; cin >> N; vector<ll> A(N); vector<ll> cnt(1000100, 0); vector<bool> ok(1000100, true); rep(i, N) { cin >> A[i]; cnt[A[i]]++; } sort(all(A)); int ans = 0; rep(i, N) { if (cnt[A[i]] == 1 && ok[A[i]]) ans++; if (!ok[A[i]]) continue; for (int j = A[i]; j <= 1000000; j += A[i]) { ok[j] = false; } } cout << ans << endl; }
insert
76
76
76
78
TLE
p02642
C++
Time Limit Exceeded
/* [Template].cpp Example code to use when starting new code. This particular problem was problem 977A_Wrong_Subtraction from CodeForces Compile: g++ -o D.exe D.cpp Execute: ./D */ #include <bits/stdc++.h> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <limits> #include <string> using namespace std; int main() { int n, a[200000]; bool dp[1000001] = {false}; int a_max = 1000000; int result = 0; int dummy; // Input cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } // Sort array sort(a, a + n); // Sieve for elements in list for (int i = 0; i < n; i++) { for (int dummy = a[i] * 2; dummy <= a_max; dummy += a[i]) { if (!dp[dummy]) dp[dummy] = true; } if (i > 0) if (a[i] == a[i - 1]) dp[a[i]] = true; if (i < n - 1) if (a[i] == a[i + 1]) dp[a[i]] = true; } // Search through list to see if elements are safe for (int i = 0; i < n; i++) { // cout << "testing: " << a[i] << " " << dp[a[i]] << endl; if (!dp[a[i]]) { result++; } } cout << result << endl; return 0; }
/* [Template].cpp Example code to use when starting new code. This particular problem was problem 977A_Wrong_Subtraction from CodeForces Compile: g++ -o D.exe D.cpp Execute: ./D */ #include <bits/stdc++.h> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <limits> #include <string> using namespace std; int main() { int n, a[200000]; bool dp[1000001] = {false}; int a_max = 1000000; int result = 0; int dummy; // Input cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } // Sort array sort(a, a + n); // Edge cases related to 1 if (n == 1 && a[0] == 1) { cout << 1 << endl; return 0; } if (n > 1 && a[0] == 1 && a[1] == 1) { cout << 0 << endl; return 0; } if (n > 1 && a[0] == 1 && a[1] != 1) { cout << 1 << endl; return 0; } // Sieve for elements in list for (int i = 0; i < n; i++) { for (int dummy = a[i] * 2; dummy <= a_max; dummy += a[i]) { if (!dp[dummy]) dp[dummy] = true; } if (i > 0) if (a[i] == a[i - 1]) dp[a[i]] = true; if (i < n - 1) if (a[i] == a[i + 1]) dp[a[i]] = true; } // Search through list to see if elements are safe for (int i = 0; i < n; i++) { // cout << "testing: " << a[i] << " " << dp[a[i]] << endl; if (!dp[a[i]]) { result++; } } cout << result << endl; return 0; }
insert
34
34
34
48
TLE
p02642
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; // 定義 typedef long long ll; typedef pair<ll, ll> P; #define ALL(x) (x).begin(), (x).end() #define REP(i, n) for (ll i = 0; i < (ll)n; ++i) #define REPN(i, m, n) for (ll i = m; i < (ll)n; ++i) #define REVREP(i, n) for (ll i = n - 1; i >= 0; i--) #define VL vector<ll> #define VVL vector<vector<ll>> #define VVVL vector<vector<vector<ll>>> #define VC vector<char> #define VVC vector<vector<char>> #define INF (ll)2e9 #define INF_LL 1LL << 60 // #define MOD 998244353 #define MOD 1000000007 ll Ceil(ll val, ll div) { return (val + div - 1) / div; } ll CeilN(ll val, ll div) { return Ceil(val, div) * div; } ll FloorN(ll x, ll n) { return (x - x % n); } bool IsOdd(ll x) { return ((x & 1) == 1); } bool IsEven(ll x) { return ((x & 1) == 0); } template <class T> bool chmax(T &a, T b) { if (a <= b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, T b) { if (a >= b) { a = b; return 1; } return 0; } void Solve() { ll N; cin >> N; VL A(N); REP(i, N) cin >> A[i]; sort(ALL(A)); VL cnt(1000 * 1000 + 5, 0); for (auto one : A) { cnt[one]++; } for (auto one : A) { if (cnt[one] == INF) continue; ll add = one + one; while (add < cnt.size()) { if (cnt[add]) { cnt[add] = INF; } add += one; } } ll ans = 0; for (auto one : cnt) { if (one == 1) ans++; } cout << ans << endl; } // メイン int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Solve(); return 0; }
#include "bits/stdc++.h" using namespace std; // 定義 typedef long long ll; typedef pair<ll, ll> P; #define ALL(x) (x).begin(), (x).end() #define REP(i, n) for (ll i = 0; i < (ll)n; ++i) #define REPN(i, m, n) for (ll i = m; i < (ll)n; ++i) #define REVREP(i, n) for (ll i = n - 1; i >= 0; i--) #define VL vector<ll> #define VVL vector<vector<ll>> #define VVVL vector<vector<vector<ll>>> #define VC vector<char> #define VVC vector<vector<char>> #define INF (ll)2e9 #define INF_LL 1LL << 60 // #define MOD 998244353 #define MOD 1000000007 ll Ceil(ll val, ll div) { return (val + div - 1) / div; } ll CeilN(ll val, ll div) { return Ceil(val, div) * div; } ll FloorN(ll x, ll n) { return (x - x % n); } bool IsOdd(ll x) { return ((x & 1) == 1); } bool IsEven(ll x) { return ((x & 1) == 0); } template <class T> bool chmax(T &a, T b) { if (a <= b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, T b) { if (a >= b) { a = b; return 1; } return 0; } void Solve() { ll N; cin >> N; VL A(N); REP(i, N) cin >> A[i]; sort(ALL(A)); VL cnt(1000 * 1000 + 5, 0); for (auto one : A) { cnt[one]++; } for (auto one : A) { if (cnt[one] == INF) continue; ll add = one + one; while (add <= A.back()) { if (cnt[add]) { cnt[add] = INF; } add += one; } } ll ans = 0; for (auto one : cnt) { if (one == 1) ans++; } cout << ans << endl; } // メイン int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Solve(); return 0; }
replace
55
56
55
56
TLE
p02642
C++
Time Limit Exceeded
// Rishabh Agarwal #include <bits/stdc++.h> #define F first #define S second #define MAX 10000003 using namespace std; typedef long long int ll; const ll mod = 1e9 + 7; const ll INF = 1e18; long double PI = 3.1415926; map<ll, ll> mp; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("inp.txt", "r", stdin); freopen("out.tex", "w", stdout); #endif ll n; cin >> n; ll a[n]; for (ll x = 0; x < n; x++) { cin >> a[x]; } sort(a, a + n); ll sum = 0; for (ll x = 0; x < n; x++) { ll p = sqrtl(a[x]); ll ans = 0; for (ll y = 1; y <= p; y++) { if (a[x] % y == 0) { if (mp[y] != 0 || mp[a[x] / y] != 0) { ans++; } } } mp[a[x]]++; ll r = sum; if (ans == 0) { sum++; } if (x < n - 1 && a[x] == a[x + 1] && sum - r == 1) { sum--; } } cout << sum << "\n"; mp.clear(); return 0; }
// Rishabh Agarwal #include <bits/stdc++.h> #define F first #define S second #define MAX 10000003 using namespace std; typedef long long int ll; const ll mod = 1e9 + 7; const ll INF = 1e18; long double PI = 3.1415926; map<ll, ll> mp; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("inp.txt", "r", stdin); freopen("out.tex", "w", stdout); #endif ll n; cin >> n; ll a[n]; for (ll x = 0; x < n; x++) { cin >> a[x]; } sort(a, a + n); ll sum = 0; for (ll x = 0; x < n; x++) { ll p = sqrt(a[x]); ll ans = 0; for (ll y = 1; y <= p; y++) { if (a[x] % y == 0) { if (mp[y] != 0 || mp[a[x] / y] != 0) { ans++; } } } mp[a[x]]++; ll r = sum; if (ans == 0) { sum++; } if (x < n - 1 && a[x] == a[x + 1] && sum - r == 1) { sum--; } } cout << sum << "\n"; mp.clear(); return 0; }
replace
33
34
33
34
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) #define ALL(c) (c).begin(), (c).end() #define SUM(x) std::accumulate(ALL(x), 0LL) #define MIN(v) *std::min_element(v.begin(), v.end()) #define MAX(v) *std::max_element(v.begin(), v.end()) #define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) using namespace std; using ll = long long; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline void dump(vector<T> v) { for (auto &x : v) cerr << x << " "; cerr << endl; } template <class T> inline void dump(vector<pair<T, T>> v) { for (auto &p : v) cerr << p.first << " " << p.second << endl; } template <class T> inline void dump(vector<vector<T>> vv) { for (auto &v : vv) { for (auto &x : v) cerr << x << " "; cerr << endl; } } constexpr int INF = 1001001001; constexpr long long INFL = (1LL << 60); constexpr double eps = (1e-9); int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<int> a(n); rep(i, n) { cin >> a[i]; } sort(ALL(a)); vector<int> v(1000001, 0); for (auto &x : a) { v[x]++; for (int i = x * 2; i <= 1000000; i += x) { v[i]++; } } int ans = 0; for (auto &x : a) { if (v[x] == 1) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) #define ALL(c) (c).begin(), (c).end() #define SUM(x) std::accumulate(ALL(x), 0LL) #define MIN(v) *std::min_element(v.begin(), v.end()) #define MAX(v) *std::max_element(v.begin(), v.end()) #define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) using namespace std; using ll = long long; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline void dump(vector<T> v) { for (auto &x : v) cerr << x << " "; cerr << endl; } template <class T> inline void dump(vector<pair<T, T>> v) { for (auto &p : v) cerr << p.first << " " << p.second << endl; } template <class T> inline void dump(vector<vector<T>> vv) { for (auto &v : vv) { for (auto &x : v) cerr << x << " "; cerr << endl; } } constexpr int INF = 1001001001; constexpr long long INFL = (1LL << 60); constexpr double eps = (1e-9); int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<int> a(n); rep(i, n) { cin >> a[i]; } sort(ALL(a)); vector<int> v(1000001, 0); for (auto &x : a) { if (v[x] != 0) { v[x]++; continue; } for (int i = x; i <= 1000000; i += x) { v[i]++; } } int ans = 0; for (auto &x : a) { if (v[x] == 1) ans++; } cout << ans << endl; return 0; }
replace
59
61
59
64
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; typedef long long ll; typedef vector<ll> vl; #define rp(i, f, t) for (long long int i = f; i < t; i++) #define pr(i, f, t) for (long long int i = t - 1; i >= f; i--) #define ca(n, a) \ rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ") #define ia(n, a) rp(ia_i, 0, n) cin >> a[ia_i] #define za(n, a) rp(za_i, 0, n) a[za_i] = 0 #define be(a) a.begin(), a.end() #define ce(a) cout << (a) << endl vector<long long> divisor(long long n) { vector<long long> res; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { res.push_back(i); if (i != n / i) res.push_back(n / i); } } return res; } int main() { ll n; cin >> n; vl a(n); rp(i, 0, n) cin >> a[i]; sort(be(a)); map<ll, ll> all; rp(i, 0, n - 1) { if (a[i] == a[i + 1]) all[a[i]]++; } ll ans = 0; rp(i, 0, n) { bool sig = true; vl now = divisor(a[i]); rp(j, 0, now.size()) { if (all[now[j]] > 0) { sig = false; } } all[a[i]]++; if (sig) ans++; } ce(ans); }
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; typedef long long ll; typedef vector<ll> vl; #define rp(i, f, t) for (long long int i = f; i < t; i++) #define pr(i, f, t) for (long long int i = t - 1; i >= f; i--) #define ca(n, a) \ rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ") #define ia(n, a) rp(ia_i, 0, n) cin >> a[ia_i] #define za(n, a) rp(za_i, 0, n) a[za_i] = 0 #define be(a) a.begin(), a.end() #define ce(a) cout << (a) << endl vector<long long> divisor(long long n) { vector<long long> res; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { res.push_back(i); if (i != n / i) res.push_back(n / i); } } return res; } int main() { ll n; cin >> n; vl a(n); rp(i, 0, n) cin >> a[i]; sort(be(a)); ll all[1111111]; za(1111111, all); rp(i, 0, n - 1) { if (a[i] == a[i + 1]) all[a[i]]++; } ll ans = 0; rp(i, 0, n) { bool sig = true; vl now = divisor(a[i]); rp(j, 0, now.size()) { if (all[now[j]] > 0) { sig = false; } } all[a[i]]++; if (sig) ans++; } ce(ans); }
replace
30
31
30
32
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #include <cstdlib> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) typedef long long ll; int main() { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a.at(i); sort(a.begin(), a.end()); vector<int> yakusuu(1000005, 0); rep(i, n) { int x = a.at(i); for (int j = x; j < 1000005; j += x) { yakusuu.at(j)++; } } int ans = 0; rep(i, n) { int x = a.at(i); if (yakusuu.at(x) == 1) ans++; } cout << ans; }
#include <bits/stdc++.h> using namespace std; #include <cstdlib> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) typedef long long ll; int main() { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a.at(i); sort(a.begin(), a.end()); vector<int> yakusuu(1000005, 0); rep(i, n) { int x = a.at(i); if (yakusuu.at(x) != 0) { yakusuu.at(x) = 2; continue; } for (int j = x; j < 1000005; j += x) { yakusuu.at(j)++; } } int ans = 0; rep(i, n) { int x = a.at(i); if (yakusuu.at(x) == 1) ans++; } cout << ans; }
insert
19
19
19
23
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { int n; cin >> n; vector<int> xs(n); map<int, int> mp; for (int i = 0; i < n; i++) { int x; cin >> x; xs[i] = x; mp[x]++; } int bound = 1000010; vector<bool> table(bound); sort(xs.begin(), xs.end()); int ans = 0; for (int i = 0; i < xs.size(); i++) { int v = xs[i]; if (!table[v] && mp[v] == 1) { ans++; } for (int j = v; j < bound; j += v) { table[j] = true; } } if (n == 1) { cout << 1 << endl; } else { cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { int n; cin >> n; vector<int> xs(n); map<int, int> mp; for (int i = 0; i < n; i++) { int x; cin >> x; xs[i] = x; mp[x]++; } int bound = 1000010; vector<bool> table(bound); sort(xs.begin(), xs.end()); int ans = 0; for (int i = 0; i < xs.size(); i++) { int v = xs[i]; if (!table[v] && mp[v] == 1) { ans++; } if (!table[v]) { for (int j = v; j < bound; j += v) { table[j] = true; } } } if (n == 1) { cout << 1 << endl; } else { cout << ans << endl; } return 0; }
replace
25
27
25
29
TLE
p02642
C++
Time Limit Exceeded
// https://atcoder.jp/contests/abc170/tasks/abc170_d #include "algorithm" #include "bitset" #include "cmath" #include "functional" #include "iomanip" #include "iostream" #include "map" #include "numeric" #include "queue" #include "set" #include "string" #include "vector" #define rep(i, to) for (ll i = 0; i < (to); ++i) #define rep1(i, to) for (ll i = 1; i <= (to); ++i) #define repf(i, from, to) for (ll i = from; i < (to); ++i) #define repr(i, from) for (ll i = from - 1; i >= 0; --i) #define all(vec) vec.begin(), vec.end() #define unless(cond) if (!(cond)) #define fi first #define se second using namespace std; typedef long long ll; typedef long double ld; template <typename T> using V = vector<T>; using VL = V<ll>; using VVL = V<VL>; template <typename T, typename U> using P = pair<T, U>; using PL = P<ll, ll>; using VPL = V<PL>; template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> inline ll len(V<T> arr) { return arr.size(); } struct exit_exception : public std::exception { const char *what() const throw() { return "Exited"; } }; template <typename T> void drop(T res) { cout << res << endl; throw exit_exception(); } const ll INF = 1e18; void solve(); #ifndef TEST int main() { cin.tie(0); ios::sync_with_stdio(false); try { solve(); } catch (exit_exception &e) { } return 0; } #endif void solve() { ll N; cin >> N; VL as(N); rep(i, N) cin >> as[i]; ll MAX = 1e6; V<bool> satisfied(MAX + 1, true); VL num_cts(MAX + 1, 0); sort(all(as)); for (auto a : as) { ++num_cts[a]; if (!satisfied[a]) continue; for (ll m = 2 * a; m <= MAX; m += a) { satisfied[m] = false; } } ll res = 0; for (auto a : as) { if (num_cts[a] == 1 && satisfied[a]) res++; } cout << res << "\n"; }
// https://atcoder.jp/contests/abc170/tasks/abc170_d #include "algorithm" #include "bitset" #include "cmath" #include "functional" #include "iomanip" #include "iostream" #include "map" #include "numeric" #include "queue" #include "set" #include "string" #include "vector" #define rep(i, to) for (ll i = 0; i < (to); ++i) #define rep1(i, to) for (ll i = 1; i <= (to); ++i) #define repf(i, from, to) for (ll i = from; i < (to); ++i) #define repr(i, from) for (ll i = from - 1; i >= 0; --i) #define all(vec) vec.begin(), vec.end() #define unless(cond) if (!(cond)) #define fi first #define se second using namespace std; typedef long long ll; typedef long double ld; template <typename T> using V = vector<T>; using VL = V<ll>; using VVL = V<VL>; template <typename T, typename U> using P = pair<T, U>; using PL = P<ll, ll>; using VPL = V<PL>; template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> inline ll len(V<T> arr) { return arr.size(); } struct exit_exception : public std::exception { const char *what() const throw() { return "Exited"; } }; template <typename T> void drop(T res) { cout << res << endl; throw exit_exception(); } const ll INF = 1e18; void solve(); #ifndef TEST int main() { cin.tie(0); ios::sync_with_stdio(false); try { solve(); } catch (exit_exception &e) { } return 0; } #endif void solve() { ll N; cin >> N; VL as(N); rep(i, N) cin >> as[i]; ll MAX = 1e6; V<bool> satisfied(MAX + 1, true); VL num_cts(MAX + 1, 0); sort(all(as)); for (auto a : as) { ++num_cts[a]; if (!satisfied[a]) continue; unless(num_cts[a] == 1) continue; for (ll m = 2 * a; m <= MAX; m += a) { satisfied[m] = false; } } ll res = 0; for (auto a : as) { if (num_cts[a] == 1 && satisfied[a]) res++; } cout << res << "\n"; }
insert
94
94
94
95
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a), i##_len = (b); i < i##_len; ++i) #define MSVC_UNKO(x) x #define rep(...) \ MSVC_UNKO(_overload3(__VA_ARGS__, repi, _rep, _rep)(__VA_ARGS__)) #define all(c) c.begin(), c.end() #define write(x) cout << (x) << '\n' using namespace std; using ll = long long; template <class T> using vv = vector<vector<T>>; template <class T> auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); } constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; } aaaa; int main() { int N; cin >> N; vector<int> A(N); rep(i, N) cin >> A[i]; sort(all(A)); constexpr int Amax = 1e6; vector<bool> isDiv(Amax + 1); int ans = 0; rep(i, N) { if ((i == N - 1 || A[i] != A[i + 1]) && !isDiv[A[i]]) ans++; for (int n = A[i]; n <= Amax; n += A[i]) { isDiv[n] = true; } } write(ans); }
#include <bits/stdc++.h> #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a), i##_len = (b); i < i##_len; ++i) #define MSVC_UNKO(x) x #define rep(...) \ MSVC_UNKO(_overload3(__VA_ARGS__, repi, _rep, _rep)(__VA_ARGS__)) #define all(c) c.begin(), c.end() #define write(x) cout << (x) << '\n' using namespace std; using ll = long long; template <class T> using vv = vector<vector<T>>; template <class T> auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); } constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; } aaaa; int main() { int N; cin >> N; vector<int> A(N); rep(i, N) cin >> A[i]; sort(all(A)); constexpr int Amax = 1e6; vector<bool> isDiv(Amax + 1); int ans = 0; for (int i = 0, j; i < N; i = j) { for (j = i + 1; j < N; ++j) { if (A[j] != A[i]) break; } if (isDiv[A[i]]) continue; else { if (j - i == 1) ans++; for (int n = A[i]; n <= Amax; n += A[i]) { isDiv[n] = true; } } } write(ans); }
replace
37
42
37
50
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; bool good[1000005]; int a[200005], rep[1000005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<int> v; memset(rep, 0, sizeof rep); for (int i = 1; i <= n; i++) { cin >> a[i]; rep[a[i]]++; v.push_back(a[i]); } memset(good, 0, sizeof good); for (int i = 0; i < n; i++) { if (i > 0) if (v[i] == v[i - 1]) continue; for (int j = v[i] * 2; j <= 1000000; j += v[i]) { good[j] = true; } } int cnt = 0; for (int i = 1; i <= n; i++) { if (!good[a[i]] && rep[a[i]] == 1) { cnt++; } } cout << cnt; }
#include <bits/stdc++.h> using namespace std; bool good[1000005]; int a[200005], rep[1000005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<int> v; memset(rep, 0, sizeof rep); for (int i = 1; i <= n; i++) { cin >> a[i]; rep[a[i]]++; v.push_back(a[i]); } sort(v.begin(), v.end()); memset(good, 0, sizeof good); for (int i = 0; i < n; i++) { if (i > 0) if (v[i] == v[i - 1]) continue; for (int j = v[i] * 2; j <= 1000000; j += v[i]) { good[j] = true; } } int cnt = 0; for (int i = 1; i <= n; i++) { if (!good[a[i]] && rep[a[i]] == 1) { cnt++; } } cout << cnt; }
insert
17
17
17
18
TLE
p02642
C++
Time Limit Exceeded
/* Author:zeke pass System Test! GET AC!! */ #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using ll = long long; using ld = long double; using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var)) #define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var)) #define Mp(a, b) make_pair((a), (b)) #define F first #define S second #define Icin(s) \ ll(s); \ cin >> (s); #define Scin(s) \ ll(s); \ cin >> (s); 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; } typedef pair<ll, ll> P; typedef vector<ll> V; typedef vector<V> VV; typedef vector<P> VP; ll mod = 1e9 + 7; ll MOD = 1e9 + 7; ll INF = 1e18; // cout << "Case #" << index << " :IMPOSSIBLE"; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); ll n; cin >> n; vector<bool> dp(1e6 + 100, false); V vec(n); map<ll, ll> mp; map<ll, ll> mp2; rep(i, n) { cin >> vec[i]; mp[vec[i]]++; } sort(all(vec)); rep(i, n) { ll index = 2; mp2[vec[i]]++; while (vec[i] * index <= 1e6 + 10) { dp[vec[i] * index] = true; index++; } } ll res = 0; rep(i, n) { if (dp[vec[i]] || mp[vec[i]] >= 2) { // cout<<vec[i]<<endl; res++; } } cout << n - res << endl; }
/* Author:zeke pass System Test! GET AC!! */ #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using ll = long long; using ld = long double; using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var)) #define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var)) #define Mp(a, b) make_pair((a), (b)) #define F first #define S second #define Icin(s) \ ll(s); \ cin >> (s); #define Scin(s) \ ll(s); \ cin >> (s); 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; } typedef pair<ll, ll> P; typedef vector<ll> V; typedef vector<V> VV; typedef vector<P> VP; ll mod = 1e9 + 7; ll MOD = 1e9 + 7; ll INF = 1e18; // cout << "Case #" << index << " :IMPOSSIBLE"; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); ll n; cin >> n; vector<bool> dp(1e6 + 100, false); V vec(n); map<ll, ll> mp; map<ll, ll> mp2; rep(i, n) { cin >> vec[i]; mp[vec[i]]++; } sort(all(vec)); rep(i, n) { ll index = 2; if (mp2[vec[i]] == 1 || dp[vec[i]]) { continue; } mp2[vec[i]]++; while (vec[i] * index <= 1e6 + 10) { dp[vec[i] * index] = true; index++; } } ll res = 0; rep(i, n) { if (dp[vec[i]] || mp[vec[i]] >= 2) { // cout<<vec[i]<<endl; res++; } } cout << n - res << endl; }
insert
76
76
76
79
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> #include <chrono> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace std::chrono; using namespace __gnu_pbds; #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define fi first #define se second #define int long long #define pb push_back #define emp emplace_back #define vv(x) vector<x> #define mp(x, y) map<x, y> #define dq(x) deque<x> #define pql(x) priority_queue<x> #define pqs(x) priority_queue<x, vv(x), greater<x>> #define M 1000000007 #define forf(i, a, b) for (int i = a; i < b; i++) #define it(x) x::iterator #define ll long long #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #define time__(d) \ for (long blockTime = 0; \ (blockTime == 0 ? (blockTime = clock()) != 0 : false); \ debug("%s time : %.4fs", d, \ (double)(clock() - blockTime) / CLOCKS_PER_SEC)) #define vii vector<int> #define big 1e18 #define sm -2e9 #define mkr make_pair #define vpi vector<pair<int, int>> #define pii pair<int, int> #define rng 500005 #define sz(x) (int)x.size() #define rv(x) reverse(x.begin(), x.end()) #define out(x) cout << x.fi << " " << x.se << endl; // #define ordered_set tree<pii, null_type,less<pii>, // rb_tree_tag,tree_order_statistics_node_update> void pr_init() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif } // friend ostream & operator << (ostream &out, const Complex &c); // friend istream & operator >> (istream &in, Complex &c); int a[200005]; int mp[100001]; void solve() { int n; cin >> n; forf(i, 0, n) cin >> a[i], mp[a[i]]++; int an = 0; forf(i, 0, n) { int is = 1; for (int j = 1; j * j <= a[i]; j++) if (a[i] % j == 0) { if (mp[j] > 0) { if (j == a[i] && mp[j] > 1) is = 0; else if (j != a[i] && mp[j] > 0) is = 0; } if (mp[a[i] / j] > 0) { if (j == 1 && mp[a[i] / j] > 1) is = 0; else if (j != 1 && mp[a[i] / j] > 0) is = 0; } } if (is) an++; } cout << an << endl; } int32_t main() { // pr_init(); fastio; solve(); }
#include <bits/stdc++.h> #include <chrono> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace std::chrono; using namespace __gnu_pbds; #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define fi first #define se second #define int long long #define pb push_back #define emp emplace_back #define vv(x) vector<x> #define mp(x, y) map<x, y> #define dq(x) deque<x> #define pql(x) priority_queue<x> #define pqs(x) priority_queue<x, vv(x), greater<x>> #define M 1000000007 #define forf(i, a, b) for (int i = a; i < b; i++) #define it(x) x::iterator #define ll long long #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #define time__(d) \ for (long blockTime = 0; \ (blockTime == 0 ? (blockTime = clock()) != 0 : false); \ debug("%s time : %.4fs", d, \ (double)(clock() - blockTime) / CLOCKS_PER_SEC)) #define vii vector<int> #define big 1e18 #define sm -2e9 #define mkr make_pair #define vpi vector<pair<int, int>> #define pii pair<int, int> #define rng 500005 #define sz(x) (int)x.size() #define rv(x) reverse(x.begin(), x.end()) #define out(x) cout << x.fi << " " << x.se << endl; // #define ordered_set tree<pii, null_type,less<pii>, // rb_tree_tag,tree_order_statistics_node_update> void pr_init() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif } // friend ostream & operator << (ostream &out, const Complex &c); // friend istream & operator >> (istream &in, Complex &c); int a[200005]; int mp[1000001]; void solve() { int n; cin >> n; forf(i, 0, n) cin >> a[i], mp[a[i]]++; int an = 0; forf(i, 0, n) { int is = 1; for (int j = 1; j * j <= a[i]; j++) if (a[i] % j == 0) { if (mp[j] > 0) { if (j == a[i] && mp[j] > 1) is = 0; else if (j != a[i] && mp[j] > 0) is = 0; } if (mp[a[i] / j] > 0) { if (j == 1 && mp[a[i] / j] > 1) is = 0; else if (j != 1 && mp[a[i] / j] > 0) is = 0; } } if (is) an++; } cout << an << endl; } int32_t main() { // pr_init(); fastio; solve(); }
replace
58
59
58
59
0
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; vector<long long> divisor(long long n) { vector<long long> ret; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); return ret; } int main() { int N; cin >> N; int A[N]; map<int, int> mp; for (int i = 0; i < N; i++) { cin >> A[i]; mp[A[i]]++; } for (int i = 0; i < N; i++) { auto yaku = divisor(A[i]); for (auto j : yaku) { if (j == A[i]) continue; if (mp[j] >= 1) { mp[A[i]]++; } } } int ans = 0; for (int i = 0; i < N; i++) { if (mp[A[i]] == 1) { ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; vector<int> divisor(int n) { vector<int> ret; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); return ret; } int main() { int N; cin >> N; int A[N]; map<int, int> mp; for (int i = 0; i < N; i++) { cin >> A[i]; mp[A[i]]++; } for (int i = 0; i < N; i++) { auto yaku = divisor(A[i]); for (auto j : yaku) { if (j == A[i]) continue; if (mp[j] >= 1) { mp[A[i]]++; } } } int ans = 0; for (int i = 0; i < N; i++) { if (mp[A[i]] == 1) { ans++; } } cout << ans << endl; }
replace
3
6
3
6
TLE
p02642
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; /* a と b の最大公約数を返す関数 */ long long GCD(long long a, long long b) { if (b == 0) return a; else return GCD(b, a % b); } int main() { int N; const int MAX_VAL = 200100; cin >> N; vector<int> cnt(MAX_VAL); vector<int> val(N, 0); int t; rep(i, N) cin >> val.at(i); for (int x : val) { if (cnt.at(x) != 0) { cnt.at(x) = 2; continue; } for (int i = x; i < MAX_VAL; i += x) cnt.at(i)++; } int ans = 0; for (int x : val) { if (cnt.at(x) == 1) ans++; } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; /* a と b の最大公約数を返す関数 */ long long GCD(long long a, long long b) { if (b == 0) return a; else return GCD(b, a % b); } int main() { int N; const int MAX_VAL = 1000005; cin >> N; vector<int> cnt(MAX_VAL); vector<int> val(N, 0); int t; rep(i, N) cin >> val.at(i); for (int x : val) { if (cnt.at(x) != 0) { cnt.at(x) = 2; continue; } for (int i = x; i < MAX_VAL; i += x) cnt.at(i)++; } int ans = 0; for (int x : val) { if (cnt.at(x) == 1) ans++; } cout << ans << endl; return 0; }
replace
21
22
21
22
0
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int a[200001], v[100001]; bool b[1000001]; int main() { int n, maxn; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; v[a[i]]++; maxn = max(maxn, a[i]); } if (n == 1) { cout << 1 << endl; return 0; } for (int now = 1; now <= n; now++) { int i = a[now]; bool f = true; v[i]--; for (int j = 1; j * j <= i; j++) { if (i % j != 0) continue; if (v[j] > 0 || v[i / j] > 0) { f = false; break; } } if (f) b[i] = 1; v[i]++; } int cnt = 0; for (int i = 1; i <= n; i++) if (b[a[i]]) cnt++; cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a[200001], v[1000001]; bool b[1000001]; int main() { int n, maxn; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; v[a[i]]++; maxn = max(maxn, a[i]); } if (n == 1) { cout << 1 << endl; return 0; } for (int now = 1; now <= n; now++) { int i = a[now]; bool f = true; v[i]--; for (int j = 1; j * j <= i; j++) { if (i % j != 0) continue; if (v[j] > 0 || v[i / j] > 0) { f = false; break; } } if (f) b[i] = 1; v[i]++; } int cnt = 0; for (int i = 1; i <= n; i++) if (b[a[i]]) cnt++; cout << cnt << endl; return 0; }
replace
3
4
3
4
0
p02642
C++
Time Limit Exceeded
// bismillahir rahmanir rahim //Author:Fayed Anik #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> using namespace std; // using namespace __gnu_pbds; // #define ordered_set tree<int, null_type,less<int>, // rb_tree_tag,tree_order_statistics_node_update> #define ll long long #define lf double #define pb(x) push_back(x) #define ull unsigned long long #define sfl(a) scanf("%lld", &a) #define sf(a) scanf("%d", &a) #define pf(a) printf("%d\n", a) #define pfl(a) printf("%lld\n", a) #define FOR(x, n) for (ll x = 1; x <= n; ++x) #define pii pair<ll, ll> #define mp(a, b) make_pair(a, b) #define mod 1000000007 #define INF 2e18 #define EPS 1e-15 #define f1 first #define f2 second #define all(v) v.begin(), v.end() #define PI acos(-1) #define printminusone printf("-1\n") #define bug printf("bug") #define FILEIN freopen("in.txt", "r", stdin) #define FILEOUT freopen("out.txt", "w", stdout) // ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); } // ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); } // bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); } // priority_queue <ll, vector<ll>, greater<ll> > pq; #define lim 2000005 ll a[lim], b[lim], cnt[lim]; int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ll n; sfl(n); FOR(i, n) { sfl(a[i]); cnt[a[i]]++; } sort(a + 1, a + n + 1); ll ans = 0; for (ll i = 1; i <= n; i++) { if (!b[a[i]] and cnt[a[i]] == 1) { ans++; } for (ll j = a[i]; j <= 1e6; j += a[i]) { b[j] = 1; } } pfl(ans); return 0; }
// bismillahir rahmanir rahim //Author:Fayed Anik #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> using namespace std; // using namespace __gnu_pbds; // #define ordered_set tree<int, null_type,less<int>, // rb_tree_tag,tree_order_statistics_node_update> #define ll long long #define lf double #define pb(x) push_back(x) #define ull unsigned long long #define sfl(a) scanf("%lld", &a) #define sf(a) scanf("%d", &a) #define pf(a) printf("%d\n", a) #define pfl(a) printf("%lld\n", a) #define FOR(x, n) for (ll x = 1; x <= n; ++x) #define pii pair<ll, ll> #define mp(a, b) make_pair(a, b) #define mod 1000000007 #define INF 2e18 #define EPS 1e-15 #define f1 first #define f2 second #define all(v) v.begin(), v.end() #define PI acos(-1) #define printminusone printf("-1\n") #define bug printf("bug") #define FILEIN freopen("in.txt", "r", stdin) #define FILEOUT freopen("out.txt", "w", stdout) // ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); } // ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); } // bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); } // priority_queue <ll, vector<ll>, greater<ll> > pq; #define lim 2000005 ll a[lim], b[lim], cnt[lim]; int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ll n; sfl(n); FOR(i, n) { sfl(a[i]); cnt[a[i]]++; } sort(a + 1, a + n + 1); ll ans = 0; for (ll i = 1; i <= n; i++) { if (a[i] == a[i - 1]) continue; if (!b[a[i]] and cnt[a[i]] == 1) { ans++; } for (ll j = a[i]; j <= 1e6; j += a[i]) { b[j] = 1; } } pfl(ans); return 0; }
insert
55
55
55
57
TLE
p02642
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef int itn; const ll LINF = 1e18; const int INF = 1e9; // マクロ定義 #define vvint(vec, n, m, l) \ vector<vector<int>> vec(n, vector<int>(m, l)); // lで初期化 #define vvll(vec, n, m, l) vector<vector<ll>> vec(n, vector<ll>(m, l)); #define vint vector<int> #define pint pair<int, int> #define rep(i, a) for (ll i = 0; i < (a); i++) #define all(x) (x).begin(), (x).end() #define debug system("pause") // デバッグ用 #define ret return 0 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; } using Graph = vector<vector<ll>>; #define ketasitei setprecision(15) // 15桁表示 const ll MOD = 1000000007; const double PI = 3.1415926535897932; int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; map<ll, ll> a; vector<ll> b(n); ll tmp; rep(i, n) { cin >> tmp; a[tmp]++; b[i] = tmp; } sort(all(b)); if (a[1] > 0) { if (a[1] > 1) cout << 0 << endl; else cout << 1 << endl; ret; } ll ans = 0; bool ok = false; rep(i, n) { if (i > 1 && b[i] == b[i - 1]) continue; if (a[b[i]] > 1) continue; ll tmp = b[i]; ok = false; for (ll j = 1; j * j <= b[i]; j++) { if (b[i] % j == 0) { if (a[j] > 0) { ok = false; break; } if (a[b[i] / j] > 0 && j != 1) { ok = false; break; } if (a[b[i] / j] > 1 && j == 1) { ok = false; break; } } else { if ((j + 1) * (j + 1) > b[i]) ok = true; continue; } ok = true; } if (ok) ans++; } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef int itn; const ll LINF = 1e18; const int INF = 1e9; // マクロ定義 #define vvint(vec, n, m, l) \ vector<vector<int>> vec(n, vector<int>(m, l)); // lで初期化 #define vvll(vec, n, m, l) vector<vector<ll>> vec(n, vector<ll>(m, l)); #define vint vector<int> #define pint pair<int, int> #define rep(i, a) for (ll i = 0; i < (a); i++) #define all(x) (x).begin(), (x).end() #define debug system("pause") // デバッグ用 #define ret return 0 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; } using Graph = vector<vector<ll>>; #define ketasitei setprecision(15) // 15桁表示 const ll MOD = 1000000007; const double PI = 3.1415926535897932; int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; vector<ll> a(1000001); vector<ll> b(n); ll tmp; rep(i, n) { cin >> tmp; a[tmp]++; b[i] = tmp; } sort(all(b)); if (a[1] > 0) { if (a[1] > 1) cout << 0 << endl; else cout << 1 << endl; ret; } ll ans = 0; bool ok = false; rep(i, n) { if (i > 1 && b[i] == b[i - 1]) continue; if (a[b[i]] > 1) continue; ll tmp = b[i]; ok = false; for (ll j = 1; j * j <= b[i]; j++) { if (b[i] % j == 0) { if (a[j] > 0) { ok = false; break; } if (a[b[i] / j] > 0 && j != 1) { ok = false; break; } if (a[b[i] / j] > 1 && j == 1) { ok = false; break; } } else { if ((j + 1) * (j + 1) > b[i]) ok = true; continue; } ok = true; } if (ok) ans++; } cout << ans << endl; return 0; }
replace
62
63
62
63
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> #include <math.h> using namespace std; int main(void) { int n; cin >> n; vector<int> A(n); for (int i = 0; i < n; i++) { cin >> A.at(i); } vector<int> X(100001); for (int a : A) { X[a] += 1; } int c = 0; for (int a : A) { X[a] -= 1; int q, r; bool f = true; for (int i = 1; i < int(sqrt(a)) + 1; i++) { q = a / i; r = a % i; if (r == 0) { if (X[i] != 0 || X[q] != 0) { f = false; break; } } } c += int(f); X[a] += 1; } cout << c << endl; }
#include <bits/stdc++.h> #include <iostream> #include <math.h> using namespace std; int main(void) { int n; cin >> n; vector<int> A(n); for (int i = 0; i < n; i++) { cin >> A.at(i); } vector<int> X(1000001); for (int a : A) { X[a] += 1; } int c = 0; for (int a : A) { X[a] -= 1; int q, r; bool f = true; for (int i = 1; i < int(sqrt(a)) + 1; i++) { q = a / i; r = a % i; if (r == 0) { if (X[i] != 0 || X[q] != 0) { f = false; break; } } } c += int(f); X[a] += 1; } cout << c << endl; }
replace
11
12
11
12
0
p02642
C++
Time Limit Exceeded
/// in the name of Allah the most beneficent the most merciful. #include <bits/stdc++.h> #define ll long long #define pb push_back #define MAX 1e18 #define MIN -1e18 #define MOD 1000000007 // #define mod2 20071027 // #define MOD 998244353 #define base 139 // #define mod 1000074259 #define base2 31 #define memz(a) memset(a, 0, sizeof(a)) #define memn(a) memset(a, -1, sizeof(a)) #define in1(a) scanf("%lld", &a) #define in2(a, b) scanf("%lld%lld", &a, &b) #define TC(c) printf("Case #%lld: ", ++c) #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define FILE \ freopen("input.txt", "r", stdin); \ freopen("out.txt", "w", stdout); #define out(x) cout << #x << " -> " << x << endl; using namespace std; const ll N = 300010, M = 2000005; ll a[N], n, res; bool vis[M], freq[M]; int solve() { in1(n); for (int i = 0; i < n; i++) { in1(a[i]); if (freq[a[i]] > 0) vis[a[i]] = 1; freq[a[i]] = 1; for (int j = 2 * a[i]; j <= 1000000; j += a[i]) { vis[j] = 1; } } for (int i = 0; i < n; i++) if (vis[a[i]] == 0) res++; printf("%lld\n", res); return 0; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int ret = solve(); return 0; } /* */
/// in the name of Allah the most beneficent the most merciful. #include <bits/stdc++.h> #define ll long long #define pb push_back #define MAX 1e18 #define MIN -1e18 #define MOD 1000000007 // #define mod2 20071027 // #define MOD 998244353 #define base 139 // #define mod 1000074259 #define base2 31 #define memz(a) memset(a, 0, sizeof(a)) #define memn(a) memset(a, -1, sizeof(a)) #define in1(a) scanf("%lld", &a) #define in2(a, b) scanf("%lld%lld", &a, &b) #define TC(c) printf("Case #%lld: ", ++c) #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define FILE \ freopen("input.txt", "r", stdin); \ freopen("out.txt", "w", stdout); #define out(x) cout << #x << " -> " << x << endl; using namespace std; const ll N = 300010, M = 2000005; ll a[N], n, res; bool vis[M], freq[M]; int solve() { in1(n); for (int i = 0; i < n; i++) { in1(a[i]); if (freq[a[i]] > 0) vis[a[i]] = 1; freq[a[i]] = 1; if (vis[a[i]] == 0) { for (int j = 2 * a[i]; j <= 1000000; j += a[i]) { vis[j] = 1; } } } for (int i = 0; i < n; i++) if (vis[a[i]] == 0) res++; printf("%lld\n", res); return 0; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int ret = solve(); return 0; } /* */
replace
35
37
35
39
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 2e5 + 5; int f[N], dp[N]; void compute() { for (int i = 1; i < N; ++i) { if (f[i] > 0) { if (f[i] > 1) dp[i] = 1; for (int j = 2; i * j < N; ++j) dp[i * j] = 1; } } return; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n, res = 0; cin >> n; int a[N]; for (int i = 0; i < n; ++i) { cin >> a[i]; ++f[a[i]]; } compute(); for (int i = 0; i < n; ++i) res += !dp[a[i]]; cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 1e6 + 5; int f[N], dp[N]; void compute() { for (int i = 1; i < N; ++i) { if (f[i] > 0) { if (f[i] > 1) dp[i] = 1; for (int j = 2; i * j < N; ++j) dp[i * j] = 1; } } return; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n, res = 0; cin >> n; int a[N]; for (int i = 0; i < n; ++i) { cin >> a[i]; ++f[a[i]]; } compute(); for (int i = 0; i < n; ++i) res += !dp[a[i]]; cout << res; return 0; }
replace
5
6
5
6
0
p02642
C++
Runtime Error
// Author: pankaj_m05 #include <bits/stdc++.h> #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define f_in(file) freopen(file, "r", stdin) #define f_out(file) freopen(file, "w", stdout) #define sz(a) int((a).size()) #define fi first #define se second #define mp make_pair #define pb push_back #define all(c) c.begin(), c.end() #define tr(c, i) for (typeof(c).begin() i = c.begin(); i != c.end(); i++) #define present(c, x) (c.find(x) != c.end()) // Set and Maps #define cpresent(c, x) (find(allc, x) != c.end()) // Vectors using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef long long ll; const int mod = 1e9 + 7; const int mxN = 2 * 1e5; const int mxA = 1e6; int n, a[mxN]; int cnt[mxA + 1]; void testcase() { cin >> n; int mx = -1; for (int i = 0; i < n; ++i) { cin >> a[i]; mx = max(mx, a[i]); } for (int i = 0; i < n; ++i) { int t = a[i]; if (cnt[t] >= 1) { ++cnt[t]; continue; } while (t <= mx) { ++cnt[t]; t += a[i]; } } int ans = 0; for (int i = 0; i < n; ++i) { if (cnt[a[i]] <= 1) ++ans; } cout << ans << '\n'; } int main(void) { fast int t; cin >> t; while (t--) { testcase(); } return 0; }
// Author: pankaj_m05 #include <bits/stdc++.h> #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define f_in(file) freopen(file, "r", stdin) #define f_out(file) freopen(file, "w", stdout) #define sz(a) int((a).size()) #define fi first #define se second #define mp make_pair #define pb push_back #define all(c) c.begin(), c.end() #define tr(c, i) for (typeof(c).begin() i = c.begin(); i != c.end(); i++) #define present(c, x) (c.find(x) != c.end()) // Set and Maps #define cpresent(c, x) (find(allc, x) != c.end()) // Vectors using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef long long ll; const int mod = 1e9 + 7; const int mxN = 2 * 1e5; const int mxA = 1e6; int n, a[mxN]; int cnt[mxA + 1]; void testcase() { cin >> n; int mx = -1; for (int i = 0; i < n; ++i) { cin >> a[i]; mx = max(mx, a[i]); } for (int i = 0; i < n; ++i) { int t = a[i]; if (cnt[t] >= 1) { ++cnt[t]; continue; } while (t <= mx) { ++cnt[t]; t += a[i]; } } int ans = 0; for (int i = 0; i < n; ++i) { if (cnt[a[i]] <= 1) ++ans; } cout << ans << '\n'; } int main(void) { fast testcase(); return 0; }
replace
57
62
57
58
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { int n; cin >> n; vector<int> a(n); map<int, bool> m; set<int> s; rep(i, n) { cin >> a[i]; if (s.count(a[i])) { m[a[i]] = true; } else { s.insert(a[i]); } } vector<bool> b(1000001, true); for (int x : a) { for (int i = x + x; i <= 1000000; i += x) { b[i] = false; } } int cnt = 0; rep(i, n) { if (m[a[i]]) { continue; } if (b[a[i]]) { cnt++; } } cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { int n; cin >> n; vector<int> a(n); map<int, bool> m; set<int> s; rep(i, n) { cin >> a[i]; if (s.count(a[i])) { m[a[i]] = true; } else { s.insert(a[i]); } } vector<bool> b(1000001, true); for (int x : s) { for (int i = x + x; i <= 1000000; i += x) { b[i] = false; } } int cnt = 0; rep(i, n) { if (m[a[i]]) { continue; } if (b[a[i]]) { cnt++; } } cout << cnt << endl; }
replace
19
20
19
20
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, a) for (int i = (int)0; i < (int)a; ++i) #define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll INF = 1LL << 60; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll gcd(ll n, ll m) { ll tmp; while (m != 0) { tmp = n % m; n = m; m = tmp; } return n; } ll lcm(ll n, ll m) { return abs(n) / gcd(n, m) * abs(m); // gl=xy } using namespace std; void solve() { int n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; vector<bool> b(1e6 + 5); vector<int> ng(1e6 + 5); sort(all(a)); rep(i, n) { ng[a[i]]++; if (b[a[i]]) continue; for (int j = a[i] + a[i];; j += a[i]) { if (j > 1e6) break; b[j] = true; } } int ans = 0; rep(i, n) { if (ng[a[i]] >= 2) continue; if (b[a[i]]) continue; ++ans; } cout << ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }
#include <bits/stdc++.h> #define rep(i, a) for (int i = (int)0; i < (int)a; ++i) #define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll INF = 1LL << 60; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll gcd(ll n, ll m) { ll tmp; while (m != 0) { tmp = n % m; n = m; m = tmp; } return n; } ll lcm(ll n, ll m) { return abs(n) / gcd(n, m) * abs(m); // gl=xy } using namespace std; void solve() { int n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; vector<bool> b(1e6 + 5); vector<int> ng(1e6 + 5); sort(all(a)); rep(i, n) { if (ng[a[i]]) { ng[a[i]]++; continue; } ng[a[i]]++; if (b[a[i]]) continue; for (int j = a[i] + a[i];; j += a[i]) { if (j > 1e6) break; b[j] = true; } } int ans = 0; rep(i, n) { if (ng[a[i]] >= 2) continue; if (b[a[i]]) continue; ++ans; } cout << ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }
insert
53
53
53
57
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18; const ll MOD = 1e9 + 7; #define REP(i, j, n) for (int i = j; i < n; i++) #define rep(i, n) REP(i, 0, n) vector<int64_t> divisor(int64_t n) { vector<int64_t> ret; for (int64_t i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } // Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: // You use the default template now. You can remove this line by using your // custom template) int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<int64_t> vec(n); rep(i, n) cin >> vec[i]; sort(vec.begin(), vec.end()); int cnt = 0; rep(i, n) { vector<int64_t> div = divisor(vec[i]); div.push_back(vec[i]); // bool flag = false; for (int j = 0; j < div.size(); j++) { int d = upper_bound(vec.begin(), vec.end(), div[j]) - lower_bound(vec.begin(), vec.end(), div[j]); // cout << vec[i] << " " << div[j] << " " << d << endl; if (d == 1 && div[j] != vec[i]) { cnt++; // flag = true; break; } else if (d > 1) { cnt++; break; } } } cout << n - cnt << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18; const ll MOD = 1e9 + 7; #define REP(i, j, n) for (int i = j; i < n; i++) #define rep(i, n) REP(i, 0, n) vector<int64_t> divisor(int64_t n) { vector<int64_t> ret; for (int64_t i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } // sort(begin(ret), end(ret)); return (ret); } // Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: // You use the default template now. You can remove this line by using your // custom template) int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<int64_t> vec(n); rep(i, n) cin >> vec[i]; sort(vec.begin(), vec.end()); int cnt = 0; rep(i, n) { vector<int64_t> div = divisor(vec[i]); div.push_back(vec[i]); // bool flag = false; for (int j = 0; j < div.size(); j++) { int d = upper_bound(vec.begin(), vec.end(), div[j]) - lower_bound(vec.begin(), vec.end(), div[j]); // cout << vec[i] << " " << div[j] << " " << d << endl; if (d == 1 && div[j] != vec[i]) { cnt++; // flag = true; break; } else if (d > 1) { cnt++; break; } } } cout << n - cnt << endl; }
replace
17
18
17
18
TLE
p02642
C++
Runtime Error
#include <algorithm> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <functional> #include <iostream> #include <limits> #include <sstream> #include <stack> #include <unordered_map> #define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i)) #define reu(i, l, u) for (int(i) = (int)(l); (i) < (int)(u); ++(i)) #define aut(r, v) for (auto r : v) #define each(it, o) for (aut(it, (o).begin()); it != (o).end(); ++it) #define all(o) (o).begin(), (o).end() #define pb(x) push_back(x) #define pc() pop_back() #define ull unsigned long long #define mp(x, y) make_pair((x), (y)) #define mset(m, v) memset(m, v, sizeof(m)) #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3fLL using namespace std; #define endl '\n' #define st stack<int> #define vl vector<long long> #define vi vector<int> #define vb vector<bool> #define vc vector<char> #define pii pair<int, int> #define vpii vector<pii> #define vvi vector<vi> #define vs vector<string> #define mod 1000000007 #define un unordered_map<int, int> #define mii map<int, int> #define Sort(a) sort(all(a)) #define ED(a) \ Sort(a), a.erase(unique(all(a)), a.end()) // removing all duplicates #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define Max(a) *max_element(all(a)) #define Min(a) *min_element(all(a)) #define MaxP(a) max_element(all(a)) - a.begin() #define MinP(a) min_element(all(a)) - a.begin() #define allUpper(a) transform(all(a), a.begin(), ::toupper) #define allLower(a) transform(all(a), a.begin(), ::tolower) #define rev(a) reverse(all(a)) #define ub(v, k) upper_bound(all(v), k) - v.begin() #define lb(v, k) lower_bound(all(v), k) - v.begin() #define adv(a, n) advance(auto it : a, n) #define RSort(a) sort(a.rbegin(), a.rend()) // decending order #define cnt(v, a) count(all(v), a) #define bs(v, a) binary_search(all(v), a) #define mmax(v) *max_element(all(v)) #define mmin(v) *min_element(all(v)) #define popcount(mask) __builtin_popcount(mask) // count set bit #define popcountLL(mask) __builtin_popcountll(mask) // for long long #define X \ real() // useful for working with #include <complex> for computational // geometry #define Y imag() #define ll long long #define ss second #define ff first #define trace1(x) cerr << #x << ": " << x << endl; #define trace2(x, y) \ cerr << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) \ cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl; template <typename T> T gcd(T a, T b) { while (b) b ^= a ^= b ^= a %= b; return a; } template <typename T> T setbit(T mask, T pos) { return mask |= (1 << pos); } template <typename T> T resetbit(T mask, T pos) { return mask &= ~(1 << pos); } template <typename T> T togglebit(T mask, T pos) { return mask ^= (1 << pos); } template <typename T> T checkbit(T mask, T pos) { return (bool)(mask & (1 << pos)); } template <typename T> T lcm(T a, T b) { return (a / gcd(a, b)) * b; } template <typename T> T modu(T a, T b) { return (a < b ? a : a % b); } template <typename T> T mod_neg(T a, T b) { a = mod(a, b); if (a < 0) { a += b; } return a; } template <typename T> T expo(T e, T n) { T x = 1, p = e; while (n) { if (n & 1) x = x * p; p = p * p; n >>= 1; } return x; } template <typename T> T mod_inverse(T a, T n) { T x, y; T d = extended_euclid(a, n, x, y); return (d > 1 ? -1 : mod_neg(x, n)); } template <typename T> T power(T e, T n, T m) { T x = 1, p = e; while (n) { if (n & 1) x = mod(x * p, m); p = mod(p * p, m); n >>= 1; } return x; } template <typename T> T powerL(T e, T n, T m) { T x = 1, p = e; while (n) { if (n & 1) x = mulmod(x, p, m); p = mulmod(p, p, m); n >>= 1; } return x; } bool Pow2(int n) { return n && (!(n & (n - 1))); } void printc(vc &result) { aut(r, result) cout << r << " "; cout << endl; } void printl(vl &result) { aut(r, result) cout << r << " "; cout << endl; } void print(vi &result) { aut(r, result) cout << r << " "; cout << endl; } // Recursively computes the power int binpow(int a, int b) { if (b == 0) return a; int res = binpow(a, b / 2); if (b % 2) return res * res * a; else return res * res; } // iteratively computes the power int pow(int a, int b) { int res = 1; while (b) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } int modpow(int a, int b, int m) { int ans = 1; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; } const int MOD = 1000000000 + 7; const int MXX = 100000 + 69; int fact[MXX], invfact[MXX]; int modinv(int k) { return modpow(k, MOD - 2, MOD); } void combinatorics() { fact[0] = fact[1] = 1; for (int i = 2; i < MXX; i++) { fact[i] = fact[i - 1] * i; fact[i] %= MOD; } invfact[MXX - 1] = modinv(fact[MXX - 1]); for (int i = MXX - 2; i >= 0; i--) { invfact[i] = invfact[i + 1] * (i + 1); invfact[i] %= MOD; } } int nCr(int x, int y) { if (y > x) return 0; int num = fact[x]; num *= invfact[y]; num %= MOD; num *= invfact[x - y]; num %= MOD; return num; } // ifstream cin("b_read_on.txt"); ofstream cout("output3.txt"); // Use (<<) for multiplication // Use (>>) for division // ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout<<fixed;cerr.tie(NULL); // find_by_order -> value at index // order_of_key -> index of value // while using (1<<i) use ((ll)1<<(ll)i) // in Floyd-Warshall Algo, k is outer loop // If an element was not initially in map and if asked mp[a],the element gets // inserted a%=mod take a lot of time... try to use it minimum and use memset // as it reduces a lot of time usage...use if(a>=mod) a%=mod // cout<<(double) can be harmful , always use printf(%.9llf)...take // scanf("%lf",&p[i][j]) as input , not llf; use s.erase(it++) for erasing // iterator and then moving to the next one never use adj.resize(n) as value is // persistent, always erase use __builtin_popcountll() for ll // no of prime numbers in range : (70,19) , (1000,168) , (100000,1229) , // (sqrt(10^9),3409) ; // always check the use of segment tree using bottom-up dp vector<int> factor(int a) { vi ans; for (int i = 1; i * i <= a; i++) { if (a % i == 0) { ans.pb(i); if (a / i != i) ans.pb(a / i); } } return ans; } int count1[100010]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int test; test = 1; // cin >> test; while (test--) { int n; cin >> n; vi v(n); rep(i, n) { cin >> v[i]; count1[v[i]]++; } int cnt = 0; for (int i = 0; i < n; i++) { int flag = 0; for (auto it : factor(v[i])) { if (it == v[i] && count1[v[i]] >= 2) flag = 1; else if (it != v[i] && count1[it] >= 1) flag = 1; } if (flag == 0) cnt++; } cout << cnt << endl; } }
#include <algorithm> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <functional> #include <iostream> #include <limits> #include <sstream> #include <stack> #include <unordered_map> #define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i)) #define reu(i, l, u) for (int(i) = (int)(l); (i) < (int)(u); ++(i)) #define aut(r, v) for (auto r : v) #define each(it, o) for (aut(it, (o).begin()); it != (o).end(); ++it) #define all(o) (o).begin(), (o).end() #define pb(x) push_back(x) #define pc() pop_back() #define ull unsigned long long #define mp(x, y) make_pair((x), (y)) #define mset(m, v) memset(m, v, sizeof(m)) #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3fLL using namespace std; #define endl '\n' #define st stack<int> #define vl vector<long long> #define vi vector<int> #define vb vector<bool> #define vc vector<char> #define pii pair<int, int> #define vpii vector<pii> #define vvi vector<vi> #define vs vector<string> #define mod 1000000007 #define un unordered_map<int, int> #define mii map<int, int> #define Sort(a) sort(all(a)) #define ED(a) \ Sort(a), a.erase(unique(all(a)), a.end()) // removing all duplicates #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define Max(a) *max_element(all(a)) #define Min(a) *min_element(all(a)) #define MaxP(a) max_element(all(a)) - a.begin() #define MinP(a) min_element(all(a)) - a.begin() #define allUpper(a) transform(all(a), a.begin(), ::toupper) #define allLower(a) transform(all(a), a.begin(), ::tolower) #define rev(a) reverse(all(a)) #define ub(v, k) upper_bound(all(v), k) - v.begin() #define lb(v, k) lower_bound(all(v), k) - v.begin() #define adv(a, n) advance(auto it : a, n) #define RSort(a) sort(a.rbegin(), a.rend()) // decending order #define cnt(v, a) count(all(v), a) #define bs(v, a) binary_search(all(v), a) #define mmax(v) *max_element(all(v)) #define mmin(v) *min_element(all(v)) #define popcount(mask) __builtin_popcount(mask) // count set bit #define popcountLL(mask) __builtin_popcountll(mask) // for long long #define X \ real() // useful for working with #include <complex> for computational // geometry #define Y imag() #define ll long long #define ss second #define ff first #define trace1(x) cerr << #x << ": " << x << endl; #define trace2(x, y) \ cerr << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) \ cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl; template <typename T> T gcd(T a, T b) { while (b) b ^= a ^= b ^= a %= b; return a; } template <typename T> T setbit(T mask, T pos) { return mask |= (1 << pos); } template <typename T> T resetbit(T mask, T pos) { return mask &= ~(1 << pos); } template <typename T> T togglebit(T mask, T pos) { return mask ^= (1 << pos); } template <typename T> T checkbit(T mask, T pos) { return (bool)(mask & (1 << pos)); } template <typename T> T lcm(T a, T b) { return (a / gcd(a, b)) * b; } template <typename T> T modu(T a, T b) { return (a < b ? a : a % b); } template <typename T> T mod_neg(T a, T b) { a = mod(a, b); if (a < 0) { a += b; } return a; } template <typename T> T expo(T e, T n) { T x = 1, p = e; while (n) { if (n & 1) x = x * p; p = p * p; n >>= 1; } return x; } template <typename T> T mod_inverse(T a, T n) { T x, y; T d = extended_euclid(a, n, x, y); return (d > 1 ? -1 : mod_neg(x, n)); } template <typename T> T power(T e, T n, T m) { T x = 1, p = e; while (n) { if (n & 1) x = mod(x * p, m); p = mod(p * p, m); n >>= 1; } return x; } template <typename T> T powerL(T e, T n, T m) { T x = 1, p = e; while (n) { if (n & 1) x = mulmod(x, p, m); p = mulmod(p, p, m); n >>= 1; } return x; } bool Pow2(int n) { return n && (!(n & (n - 1))); } void printc(vc &result) { aut(r, result) cout << r << " "; cout << endl; } void printl(vl &result) { aut(r, result) cout << r << " "; cout << endl; } void print(vi &result) { aut(r, result) cout << r << " "; cout << endl; } // Recursively computes the power int binpow(int a, int b) { if (b == 0) return a; int res = binpow(a, b / 2); if (b % 2) return res * res * a; else return res * res; } // iteratively computes the power int pow(int a, int b) { int res = 1; while (b) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } int modpow(int a, int b, int m) { int ans = 1; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; } const int MOD = 1000000000 + 7; const int MXX = 100000 + 69; int fact[MXX], invfact[MXX]; int modinv(int k) { return modpow(k, MOD - 2, MOD); } void combinatorics() { fact[0] = fact[1] = 1; for (int i = 2; i < MXX; i++) { fact[i] = fact[i - 1] * i; fact[i] %= MOD; } invfact[MXX - 1] = modinv(fact[MXX - 1]); for (int i = MXX - 2; i >= 0; i--) { invfact[i] = invfact[i + 1] * (i + 1); invfact[i] %= MOD; } } int nCr(int x, int y) { if (y > x) return 0; int num = fact[x]; num *= invfact[y]; num %= MOD; num *= invfact[x - y]; num %= MOD; return num; } // ifstream cin("b_read_on.txt"); ofstream cout("output3.txt"); // Use (<<) for multiplication // Use (>>) for division // ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout<<fixed;cerr.tie(NULL); // find_by_order -> value at index // order_of_key -> index of value // while using (1<<i) use ((ll)1<<(ll)i) // in Floyd-Warshall Algo, k is outer loop // If an element was not initially in map and if asked mp[a],the element gets // inserted a%=mod take a lot of time... try to use it minimum and use memset // as it reduces a lot of time usage...use if(a>=mod) a%=mod // cout<<(double) can be harmful , always use printf(%.9llf)...take // scanf("%lf",&p[i][j]) as input , not llf; use s.erase(it++) for erasing // iterator and then moving to the next one never use adj.resize(n) as value is // persistent, always erase use __builtin_popcountll() for ll // no of prime numbers in range : (70,19) , (1000,168) , (100000,1229) , // (sqrt(10^9),3409) ; // always check the use of segment tree using bottom-up dp vector<int> factor(int a) { vi ans; for (int i = 1; i * i <= a; i++) { if (a % i == 0) { ans.pb(i); if (a / i != i) ans.pb(a / i); } } return ans; } int count1[1000100]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int test; test = 1; // cin >> test; while (test--) { int n; cin >> n; vi v(n); rep(i, n) { cin >> v[i]; count1[v[i]]++; } int cnt = 0; for (int i = 0; i < n; i++) { int flag = 0; for (auto it : factor(v[i])) { if (it == v[i] && count1[v[i]] >= 2) flag = 1; else if (it != v[i] && count1[it] >= 1) flag = 1; } if (flag == 0) cnt++; } cout << cnt << endl; } }
replace
268
269
268
269
0
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; typedef long long LL; int n, a[N], ans, vis[N]; int main() { cin >> n; ans = n; for (int i = 1; i <= n; i++) { cin >> a[i]; vis[a[i]]++; } for (int i = 1; i <= n; i++) { int ok = 0; for (int j = 2; j <= sqrt(a[i]); j++) if (a[i] % j == 0) if (vis[a[i] / j] || vis[j]) { ans--; ok = 1; break; } if (!ok && (vis[a[i]] > 1 || (vis[1] && a[i] != 1))) ans--; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 5; typedef long long LL; int n, a[N], ans, vis[N]; int main() { cin >> n; ans = n; for (int i = 1; i <= n; i++) { cin >> a[i]; vis[a[i]]++; } for (int i = 1; i <= n; i++) { int ok = 0; for (int j = 2; j <= sqrt(a[i]); j++) if (a[i] % j == 0) if (vis[a[i] / j] || vis[j]) { ans--; ok = 1; break; } if (!ok && (vis[a[i]] > 1 || (vis[1] && a[i] != 1))) ans--; } cout << ans << endl; return 0; }
replace
3
4
3
4
0
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) typedef int64_t Int; typedef pair<Int, Int> P; int main() { int N; cin >> N; set<int> A; vector<int> kosuu(100010, 0); rep(i, N) { int a; cin >> a; A.insert(a); kosuu[a]++; } vector<bool> flag(1000010, true); int ans = 0; for (int x : A) { if (!flag[x]) { continue; } else { int now = x; while (now < 1000010) { flag[now] = false; now += x; } if (kosuu[x] <= 1) ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) typedef int64_t Int; typedef pair<Int, Int> P; int main() { int N; cin >> N; set<int> A; vector<int> kosuu(1000010, 0); rep(i, N) { int a; cin >> a; A.insert(a); kosuu[a]++; } vector<bool> flag(1000010, true); int ans = 0; for (int x : A) { if (!flag[x]) { continue; } else { int now = x; while (now < 1000010) { flag[now] = false; now += x; } if (kosuu[x] <= 1) ans++; } } cout << ans << endl; }
replace
11
12
11
12
0
p02642
C++
Runtime Error
#include <bits/stdc++.h> #define fr(i, n) for (int i = 0; i < (n); ++i) #define foor(i, a, b) for (int i = (a); i <= (b); ++i) #define rf(i, n) for (int i = (n); i-- > 0;) #define roof(i, b, a) for (int i = (b); i >= (a); --i) #define elsif else if #define all(x) x.begin(), x.end() #define Sort(x) sort(all(x)) #define Reverse(x) reverse(all(x)) #define PQ priority_queue #define NP(x) next_permutation(all(x)) #define M_PI 3.14159265358979323846 #define popcount __builtin_popcountll using namespace std; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<int> vi; typedef vector<vi> vvi; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef unsigned long long ull; typedef vector<ull> vu; typedef vector<vu> vvu; typedef double dbl; typedef vector<dbl> vd; typedef vector<vd> vvd; typedef string str; typedef vector<str> vs; typedef vector<vs> vvs; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef map<int, int> mii; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef map<ll, ll> mll; typedef pair<dbl, dbl> pdd; typedef vector<pdd> vpdd; typedef map<dbl, dbl> mdd; typedef pair<str, str> pss; typedef vector<pss> vpss; typedef map<str, str> mss; typedef pair<int, ll> pil; typedef vector<pil> vpil; typedef map<int, ll> mil; typedef pair<ll, int> pli; typedef vector<pli> vpli; typedef map<ll, int> mli; typedef pair<dbl, int> pdi; typedef vector<pdi> vpdi; typedef map<dbl, int> mdi; template <typename T> vector<T> &operator<<(vector<T> &v, const T t) { v.push_back(t); return v; } template <typename T> multiset<T> &operator<<(multiset<T> &m, const T t) { m.insert(t); return m; } template <typename T> set<T> &operator<<(set<T> &s, const T t) { s.insert(t); return s; } template <typename T> stack<T> &operator<<(stack<T> &s, const T t) { s.push(t); return s; } template <typename T> stack<T> &operator>>(stack<T> &s, T &t) { t = s.top(); s.pop(); return s; } template <typename T> queue<T> &operator<<(queue<T> &q, const T t) { q.push(t); return q; } template <typename T> queue<T> &operator>>(queue<T> &q, T &t) { t = q.front(); q.pop(); return q; } template <typename T, typename U> PQ<T, vector<T>, U> &operator<<(PQ<T, vector<T>, U> &q, const T t) { q.push(t); return q; } template <typename T, typename U> PQ<T, vector<T>, U> &operator>>(PQ<T, vector<T>, U> &q, T &t) { t = q.top(); q.pop(); return q; } template <typename T, typename U> istream &operator>>(istream &s, pair<T, U> &p) { return s >> p.first >> p.second; } istream &operator>>(istream &s, _Bit_reference b) { int a; s >> a; assert(a == 0 || a == 1); b = a; return s; } template <typename T> istream &operator>>(istream &s, vector<T> &v) { fr(i, v.size()) { s >> v[i]; } return s; } template <typename T, typename U> ostream &operator<<(ostream &s, const pair<T, U> p) { return s << p.first << " " << p.second; } template <typename T> ostream &operator<<(ostream &s, const vector<T> v) { fr(i, v.size()) { i ? s << " " << v[i] : s << v[i]; } return s; } template <typename T> ostream &operator<<(ostream &s, const deque<T> d) { fr(i, d.size()) { i ? s << " " << d[i] : s << d[i]; } return s; } template <typename T> _Bit_reference operator&=(_Bit_reference b, T t) { return b = b & t; } template <typename T> _Bit_reference operator^=(_Bit_reference b, T t) { return b = b ^ t; } template <typename T> _Bit_reference operator|=(_Bit_reference b, T t) { return b = b | t; } template <typename T, typename U> pair<T, U> operator+(pair<T, U> a, pair<T, U> b) { return {a.first + b.first, a.second + b.second}; } template <typename T, typename U> pair<T, U> operator-(pair<T, U> a, pair<T, U> b) { return {a.first - b.first, a.second - b.second}; } template <typename T, typename U> pair<T, U> &operator+=(pair<T, U> &a, pair<T, U> b) { return a = a + b; } template <typename T, typename U> pair<T, U> &operator-=(pair<T, U> &a, pair<T, U> b) { return a = a - b; } void print(void) { cout << "\n"; } void Print(void) { cout << endl; } template <typename T> void print(T t) { cout << t << "\n"; } template <typename T> void Print(T t) { cout << t << endl; } template <typename T, typename... U> void print(T &&t, U &&...u) { cout << t << " "; print(forward<U>(u)...); } template <typename T, typename... U> void Print(T &&t, U &&...u) { cout << t << " "; Print(forward<U>(u)...); } bool YN(bool b) { print(b ? "YES" : "NO"); return b; } bool PI(bool b) { print(b ? "POSSIBLE" : "IMPOSSIBLE"); return b; } bool Yn(bool b) { print(b ? "Yes" : "No"); return b; } bool Pi(bool b) { print(b ? "Possible" : "Impossible"); return b; } bool yn(bool b) { print(b ? "yes" : "no"); return b; } bool pi(bool b) { print(b ? "possible" : "impossible"); return b; } const int e5 = 1e5; const int e9 = 1e9; const int MD = 1e9 + 7; const int md = 998244353; const ll e18 = 1e18; template <typename T> str to_string(const T &n) { ostringstream s; s << n; return s.str(); } template <typename T> T &chmax(T &a, T b) { return a = max(a, b); } template <typename T> T &chmin(T &a, T b) { return a = min(a, b); } template <typename T, typename U> vector<pair<T, U>> dijkstra(const vector<vector<pair<T, U>>> &E, const U s, const T inf) { using P = pair<T, U>; vector<P> d; fr(i, E.size()) { d << P{inf, i}; } PQ<P, vector<P>, greater<P>> pq; pq << (d[s] = P{0, s}); while (pq.size()) { P a = pq.top(); pq.pop(); U v = a.second; if (d[v].first >= a.first) { for (P e : E[v]) { if (d[v].first + e.first < d[e.second].first) { d[e.second] = P{d[v].first + e.first, v}; pq << P{d[v].first + e.first, e.second}; } } } } return d; } template <typename T, typename U> map<U, pair<T, U>> dijkstra(map<U, vector<pair<T, U>>> E, const U s, const T inf) { using P = pair<T, U>; map<U, P> d; for (pair<U, vector<P>> e : E) { d[e.first] = P{inf, e.first}; } PQ<P, vector<P>, greater<P>> pq; pq << (d[s] = P{0, s}); while (pq.size()) { P a = pq.top(); pq.pop(); U v = a.second; if (d[v].first >= a.first) { for (P e : E[v]) { if (d[v].first + e.first < d[e.second].first) { d[e.second] = P{d[v].first + e.first, v}; pq << P{d[v].first + e.first, e.second}; } } } } return d; } ll maxflow(vector<mil> &E, int s, int t) { ll z = 0; vi b(E.size(), -1); for (int i = 0;; ++i) { static auto dfs = [&](int v, ll f, auto &dfs) -> ll { if (v == t) return f; b[v] = i; for (auto &p : E[v]) { if (b[p.first] < i && p.second) { if (ll r = dfs(p.first, min(f, p.second), dfs)) { p.second -= r; E[p.first][v] += r; return r; } } } return 0; }; ll x = dfs(s, ll(1e18), dfs); z += x; if (x == 0) return z; } } template <typename T> T distsq(pair<T, T> a, pair<T, T> b) { return (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second); } template <typename T> T max(const vector<T> a) { assert(a.size()); T m = a[0]; for (T e : a) { m = max(m, e); } return m; } template <typename T> T min(const vector<T> a) { assert(a.size()); T m = a[0]; for (T e : a) { m = min(m, e); } return m; } template <typename T> T gcd(const T a, const T b) { return a ? gcd(b % a, a) : b; } template <typename T> T gcd(const vector<T> a) { T g = a[0]; for (T e : a) { g = gcd(g, e); } return g; } template <typename T> vector<T> LCS(vector<T> A, vector<T> B) { int N = A.size(), M = B.size(); vector<vector<pair<int, pii>>> d(N + 1, vector<pair<int, pii>>(M + 1)); fr(i, N) { fr(j, M) { if (A[i] == B[j]) { d[i + 1][j + 1] = {d[i][j].first + 1, {i, j}}; } else { d[i + 1][j + 1] = max(d[i][j + 1], d[i + 1][j]); } } } vector<T> r; for (pii p = {N, M}; d[p.first][p.second].first; p = d[p.first][p.second].second) { r << A[d[p.first][p.second].second.first]; } Reverse(r); return r; } str LCS(str S, str T) { vector<char> s = LCS(vector<char>(S.begin(), S.end()), vector<char>(T.begin(), T.end())); return str(s.begin(), s.end()); } template <typename T> vector<pair<T, T>> ConvexHull(vector<pair<T, T>> V) { if (V.size() <= 3) { return V; } Sort(V); rf(i, V.size() - 1) V << V[i]; vector<pair<T, T>> r; for (pair<T, T> p : V) { int s = r.size(); while (s >= 2 && (p.second - r[s - 1].second) * (p.first - r[s - 2].first) < (p.second - r[s - 2].second) * (p.first - r[s - 1].first)) { r.pop_back(); --s; } r << p; } r.pop_back(); return r; } class UnionFind { vi p, s; void extend(int N) { foor(i, p.size(), N) { p << i; s << 1; } } public: UnionFind(void) {} UnionFind(int N) { extend(N - 1); } int find(int i) { extend(i); return p[i] = p[i] == i ? i : find(p[i]); } void unite(int a, int b) { extend(a); extend(b); if ((a = find(a)) != (b = find(b))) { if (s[a] > s[b]) { swap(a, b); } s[b] += s[a]; p[a] = b; } } void unite(pii p) { return unite(p.first, p.second); } bool same(int a, int b) { extend(a); extend(b); return find(a) == find(b); } bool same(pii p) { return same(p.first, p.second); } int size(int x) { extend(x); return s[find(x)]; } }; ll MST(vector<pair<ll, pii>> &E) { Sort(E); UnionFind uf; ll z = 0; for (auto &e : E) { if (!uf.same(e.second)) { z += e.first; uf.unite(e.second); } } return z; } ll strmod(const str &s, const int m) { ll x = 0; fr(i, s.size()) { x = (x * 10 + s[i] - 48) % m; } return x; } vvl mul(const vvl &A, const vvl &B, const int m) { vvl C; fr(y, A.size()) { C << vl(B[y].size()); } fr(y, C.size()) { fr(x, C[y].size()) { fr(i, A[0].size()) { (C[y][x] += A[y][i] * B[i][x]) %= m; } } } return C; } vvl pow(const vvl &A, const ll n, const int m) { vvl B; fr(y, A.size()) { B << vl(A.size()); } if (n == 0) { fr(i, B.size()) { B[i][i] = 1; } } elsif(n % 2) { B = mul(A, pow(A, n - 1, m), m); } else { vvl C = pow(A, n / 2, m); B = mul(C, C, m); } return B; } ll pow(const ll a, const ll n, const int m) { ll t; return n ? (n & 1 ? a >= 0 ? a % m : (m - (-a % m)) % m : 1) * (t = pow(a, n >> 1, m), t * t % m) % m : !!a; } ll inv(const ll x, const int p) { assert(x != 0); return pow(x, p - 2, p); } ll inv(const ll x) { return inv(x, MD); } vpll fact(const int n, const int p) { assert(n < p); vpll v(n + 1); v[0].first = 1; foor(i, 1, n) { v[i].first = v[i - 1].first * i % p; } v[n].second = inv(v[n].first, p); roof(i, n, 1) { v[i - 1].second = v[i].second * i % p; } return v; } class Combination { const vpll f; const int M; public: Combination(int n, int m) : f(fact(n, m)), M(m) {} ll P(int n, int k) { return n < 0 || k < 0 || n < k ? 0ll : f[n].first * f[n - k].second % M; } ll C(int n, int k) { return k < 0 || n < k ? 0ll : P(n, k) * f[k].second % M; } ll H(int n, int k) { return n == 0 && k == 0 ? 1ll : C(n + k - 1, k); } ll F(int n) { return n < 0 ? 0 : f[n].first; } }; ll C2(const int n) { return (ll)n * ~-n / 2; } ll sum(const vi a) { ll s = 0; for (int e : a) { s += e; } return s; } ll sum(const vl a) { ll s = 0; for (ll e : a) { s += e; } return s; } template <typename T> int MSB(T N) { int r = -1; for (; N > 0; N /= 2) { ++r; } return r; } template <typename T> class SegmentTree { vector<T> S; T (*const op)(T a, T b); const T zero; const int B; public: SegmentTree(int N, T (*f)(T a, T b), const T zero) : S(1 << MSB(N - 1) + 2, zero), op(f), zero(zero), B(1 << MSB(N - 1) + 1) {} SegmentTree(vector<T> v, T (*f)(T a, T b), const T zero) : SegmentTree(v.size(), f, zero) { fr(i, v.size()) { S[S.size() / 2 + i] = v[i]; } roof(i, S.size() / 2 - 1, 1) { S[i] = op(S[i * 2], S[i * 2 + 1]); } } T calc(int l, int r) { l += B; r += B; if (l > r) { return zero; } if (l == r) { return S[l]; } T L = S[l], R = S[r]; for (; l / 2 < r / 2; l /= 2, r /= 2) { if (l % 2 == 0) { L = op(L, S[l + 1]); } if (r % 2 == 1) { R = op(S[r - 1], R); } } return op(L, R); } void replace(int i, T x) { for (S[i += B] = x; i != 1; i /= 2) { if (i % 2) { S[i / 2] = op(S[i - 1], S[i]); } else { S[i / 2] = op(S[i], S[i + 1]); } } } void add(int i, T x) { replace(i, op(S[B + i], x)); } T top() { return S[1]; } T get(int i) { return S[i + B]; } }; ll BITsum(vl &B, int i) { ll z = 0; while (i > 0) { z += B[i]; i -= i & -i; } return z; } void BITadd(vl &B, int i, ll x) { while (i < B.size()) { B[i] += x; i += i & -i; } } ll fib(const ll n, const int m) { ll a, b, c, d, A, B, C, D; a = 1; b = 0; c = 0; d = 1; rf(i, 63) { A = a * a + b * c; B = a * b + b * d; C = c * a + d * c; D = c * b + d * d; if (n >> i & 1) { a = A; b = B; c = C; d = D; A = a + b; B = a; C = c + d; D = c; } a = A % m; b = B % m; c = C % m; d = D % m; } return b; } vi primes(int n) { vb b(n + 1); vi p; foor(i, 2, n) { if (!b[i]) { p << i; for (int j = 2 * i; j <= n; j += i) { b[j] = true; } } } return p; } vb isprime(const int n) { vb v(n + 1, true); v[0] = v[1] = false; foor(i, 2, n) { if (v[i]) { for (int j = 2 * i; j <= n; j += i) { v[j] = false; } } } return v; } class LCA { vvi par; vi dep; public: LCA(vvi &E, int root) : par(MSB(E.size()) + 1, vi(E.size())), dep(E.size()) { function<void(int, int)> dfs = [&](int i, int p) { for (int j : E[i]) if (j != p) { par[0][j] = i; dep[j] = dep[i] + 1; dfs(j, i); } }; par[0][root] = root; dfs(root, root); fr(i, par.size() - 1) { fr(j, par[0].size()) { par[i + 1][j] = par[i][par[i][j]]; } } } int operator()(int a, int b) { if (dep[a] > dep[b]) swap(a, b); for (int t = dep[b] - dep[a], i = 0; t; t >>= 1, ++i) { if (t & 1) { b = par[i][b]; } } if (a == b) return a; rf(i, par.size()) { if (par[i][a] != par[i][b]) { a = par[i][a]; b = par[i][b]; } } return par[0][a]; } int dist(int a, int b) { return dep[a] + dep[b] - 2 * dep[operator()(a, b)]; } }; vpli factor(ll N) { vpli r; for (ll i = 2; i * i <= N; ++i) { if (N % i == 0) { r << pli{i, 0}; while (N % i == 0) { N /= i; ++r.back().second; } } } if (N > 1) { r << pli{N, 1}; } return r; } vl divisors(ll n) { vl r; ll m = sqrt(n); foor(i, 1, m) if (n % i == 0) r << ll(i); rf(i, r.size() - (m * m == n)) r << n / r[i]; return r; } vi SuffixArray(str S) { int N = S.size(); vi rank(N + 1), tmp(N + 1), sa(N + 1); fr(i, N) { sa[i] = i; rank[i] = S[i]; } sa[N] = N; rank[N] = -1; int k; auto cmp = [&](int &a, int &b) -> bool { if (rank[a] != rank[b]) return rank[a] < rank[b]; return (a + k <= N ? rank[a + k] : -1) < (b + k <= N ? rank[b + k] : -1); }; for (k = 1; k <= N; k *= 2) { sort(all(sa), cmp); tmp[sa[0]] = 0; foor(i, 1, N) { tmp[sa[i]] = tmp[sa[i - 1]] + cmp(sa[i - 1], sa[i]); } rank = tmp; } return sa; }; template <typename T, typename U> void sort2(vector<T> &a, vector<U> &b) { int N = a.size(); assert(b.size() == N); vector<pair<T, U>> v; fr(i, N) { v << pair<T, U>{a[i], b[i]}; } Sort(v); fr(i, N) { a[i] = v[i].first; b[i] = v[i].second; } } int main() { cin.tie(0); ios::sync_with_stdio(false); int M = 2e5; vvi D(M + 1); foor(i, 1, M) { for (int j = i; j <= M; j += i) { D[j] << i; } } int N; cin >> N; vi A(N); cin >> A; vi B(M + 1); fr(i, N) { ++B[A[i]]; } int z = 0; fr(i, N) { bool x = true; for (int d : D[A[i]]) { x &= B[d] == (d == A[i]); } z += x; } print(z); return 0; }
#include <bits/stdc++.h> #define fr(i, n) for (int i = 0; i < (n); ++i) #define foor(i, a, b) for (int i = (a); i <= (b); ++i) #define rf(i, n) for (int i = (n); i-- > 0;) #define roof(i, b, a) for (int i = (b); i >= (a); --i) #define elsif else if #define all(x) x.begin(), x.end() #define Sort(x) sort(all(x)) #define Reverse(x) reverse(all(x)) #define PQ priority_queue #define NP(x) next_permutation(all(x)) #define M_PI 3.14159265358979323846 #define popcount __builtin_popcountll using namespace std; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<int> vi; typedef vector<vi> vvi; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef unsigned long long ull; typedef vector<ull> vu; typedef vector<vu> vvu; typedef double dbl; typedef vector<dbl> vd; typedef vector<vd> vvd; typedef string str; typedef vector<str> vs; typedef vector<vs> vvs; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef map<int, int> mii; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef map<ll, ll> mll; typedef pair<dbl, dbl> pdd; typedef vector<pdd> vpdd; typedef map<dbl, dbl> mdd; typedef pair<str, str> pss; typedef vector<pss> vpss; typedef map<str, str> mss; typedef pair<int, ll> pil; typedef vector<pil> vpil; typedef map<int, ll> mil; typedef pair<ll, int> pli; typedef vector<pli> vpli; typedef map<ll, int> mli; typedef pair<dbl, int> pdi; typedef vector<pdi> vpdi; typedef map<dbl, int> mdi; template <typename T> vector<T> &operator<<(vector<T> &v, const T t) { v.push_back(t); return v; } template <typename T> multiset<T> &operator<<(multiset<T> &m, const T t) { m.insert(t); return m; } template <typename T> set<T> &operator<<(set<T> &s, const T t) { s.insert(t); return s; } template <typename T> stack<T> &operator<<(stack<T> &s, const T t) { s.push(t); return s; } template <typename T> stack<T> &operator>>(stack<T> &s, T &t) { t = s.top(); s.pop(); return s; } template <typename T> queue<T> &operator<<(queue<T> &q, const T t) { q.push(t); return q; } template <typename T> queue<T> &operator>>(queue<T> &q, T &t) { t = q.front(); q.pop(); return q; } template <typename T, typename U> PQ<T, vector<T>, U> &operator<<(PQ<T, vector<T>, U> &q, const T t) { q.push(t); return q; } template <typename T, typename U> PQ<T, vector<T>, U> &operator>>(PQ<T, vector<T>, U> &q, T &t) { t = q.top(); q.pop(); return q; } template <typename T, typename U> istream &operator>>(istream &s, pair<T, U> &p) { return s >> p.first >> p.second; } istream &operator>>(istream &s, _Bit_reference b) { int a; s >> a; assert(a == 0 || a == 1); b = a; return s; } template <typename T> istream &operator>>(istream &s, vector<T> &v) { fr(i, v.size()) { s >> v[i]; } return s; } template <typename T, typename U> ostream &operator<<(ostream &s, const pair<T, U> p) { return s << p.first << " " << p.second; } template <typename T> ostream &operator<<(ostream &s, const vector<T> v) { fr(i, v.size()) { i ? s << " " << v[i] : s << v[i]; } return s; } template <typename T> ostream &operator<<(ostream &s, const deque<T> d) { fr(i, d.size()) { i ? s << " " << d[i] : s << d[i]; } return s; } template <typename T> _Bit_reference operator&=(_Bit_reference b, T t) { return b = b & t; } template <typename T> _Bit_reference operator^=(_Bit_reference b, T t) { return b = b ^ t; } template <typename T> _Bit_reference operator|=(_Bit_reference b, T t) { return b = b | t; } template <typename T, typename U> pair<T, U> operator+(pair<T, U> a, pair<T, U> b) { return {a.first + b.first, a.second + b.second}; } template <typename T, typename U> pair<T, U> operator-(pair<T, U> a, pair<T, U> b) { return {a.first - b.first, a.second - b.second}; } template <typename T, typename U> pair<T, U> &operator+=(pair<T, U> &a, pair<T, U> b) { return a = a + b; } template <typename T, typename U> pair<T, U> &operator-=(pair<T, U> &a, pair<T, U> b) { return a = a - b; } void print(void) { cout << "\n"; } void Print(void) { cout << endl; } template <typename T> void print(T t) { cout << t << "\n"; } template <typename T> void Print(T t) { cout << t << endl; } template <typename T, typename... U> void print(T &&t, U &&...u) { cout << t << " "; print(forward<U>(u)...); } template <typename T, typename... U> void Print(T &&t, U &&...u) { cout << t << " "; Print(forward<U>(u)...); } bool YN(bool b) { print(b ? "YES" : "NO"); return b; } bool PI(bool b) { print(b ? "POSSIBLE" : "IMPOSSIBLE"); return b; } bool Yn(bool b) { print(b ? "Yes" : "No"); return b; } bool Pi(bool b) { print(b ? "Possible" : "Impossible"); return b; } bool yn(bool b) { print(b ? "yes" : "no"); return b; } bool pi(bool b) { print(b ? "possible" : "impossible"); return b; } const int e5 = 1e5; const int e9 = 1e9; const int MD = 1e9 + 7; const int md = 998244353; const ll e18 = 1e18; template <typename T> str to_string(const T &n) { ostringstream s; s << n; return s.str(); } template <typename T> T &chmax(T &a, T b) { return a = max(a, b); } template <typename T> T &chmin(T &a, T b) { return a = min(a, b); } template <typename T, typename U> vector<pair<T, U>> dijkstra(const vector<vector<pair<T, U>>> &E, const U s, const T inf) { using P = pair<T, U>; vector<P> d; fr(i, E.size()) { d << P{inf, i}; } PQ<P, vector<P>, greater<P>> pq; pq << (d[s] = P{0, s}); while (pq.size()) { P a = pq.top(); pq.pop(); U v = a.second; if (d[v].first >= a.first) { for (P e : E[v]) { if (d[v].first + e.first < d[e.second].first) { d[e.second] = P{d[v].first + e.first, v}; pq << P{d[v].first + e.first, e.second}; } } } } return d; } template <typename T, typename U> map<U, pair<T, U>> dijkstra(map<U, vector<pair<T, U>>> E, const U s, const T inf) { using P = pair<T, U>; map<U, P> d; for (pair<U, vector<P>> e : E) { d[e.first] = P{inf, e.first}; } PQ<P, vector<P>, greater<P>> pq; pq << (d[s] = P{0, s}); while (pq.size()) { P a = pq.top(); pq.pop(); U v = a.second; if (d[v].first >= a.first) { for (P e : E[v]) { if (d[v].first + e.first < d[e.second].first) { d[e.second] = P{d[v].first + e.first, v}; pq << P{d[v].first + e.first, e.second}; } } } } return d; } ll maxflow(vector<mil> &E, int s, int t) { ll z = 0; vi b(E.size(), -1); for (int i = 0;; ++i) { static auto dfs = [&](int v, ll f, auto &dfs) -> ll { if (v == t) return f; b[v] = i; for (auto &p : E[v]) { if (b[p.first] < i && p.second) { if (ll r = dfs(p.first, min(f, p.second), dfs)) { p.second -= r; E[p.first][v] += r; return r; } } } return 0; }; ll x = dfs(s, ll(1e18), dfs); z += x; if (x == 0) return z; } } template <typename T> T distsq(pair<T, T> a, pair<T, T> b) { return (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second); } template <typename T> T max(const vector<T> a) { assert(a.size()); T m = a[0]; for (T e : a) { m = max(m, e); } return m; } template <typename T> T min(const vector<T> a) { assert(a.size()); T m = a[0]; for (T e : a) { m = min(m, e); } return m; } template <typename T> T gcd(const T a, const T b) { return a ? gcd(b % a, a) : b; } template <typename T> T gcd(const vector<T> a) { T g = a[0]; for (T e : a) { g = gcd(g, e); } return g; } template <typename T> vector<T> LCS(vector<T> A, vector<T> B) { int N = A.size(), M = B.size(); vector<vector<pair<int, pii>>> d(N + 1, vector<pair<int, pii>>(M + 1)); fr(i, N) { fr(j, M) { if (A[i] == B[j]) { d[i + 1][j + 1] = {d[i][j].first + 1, {i, j}}; } else { d[i + 1][j + 1] = max(d[i][j + 1], d[i + 1][j]); } } } vector<T> r; for (pii p = {N, M}; d[p.first][p.second].first; p = d[p.first][p.second].second) { r << A[d[p.first][p.second].second.first]; } Reverse(r); return r; } str LCS(str S, str T) { vector<char> s = LCS(vector<char>(S.begin(), S.end()), vector<char>(T.begin(), T.end())); return str(s.begin(), s.end()); } template <typename T> vector<pair<T, T>> ConvexHull(vector<pair<T, T>> V) { if (V.size() <= 3) { return V; } Sort(V); rf(i, V.size() - 1) V << V[i]; vector<pair<T, T>> r; for (pair<T, T> p : V) { int s = r.size(); while (s >= 2 && (p.second - r[s - 1].second) * (p.first - r[s - 2].first) < (p.second - r[s - 2].second) * (p.first - r[s - 1].first)) { r.pop_back(); --s; } r << p; } r.pop_back(); return r; } class UnionFind { vi p, s; void extend(int N) { foor(i, p.size(), N) { p << i; s << 1; } } public: UnionFind(void) {} UnionFind(int N) { extend(N - 1); } int find(int i) { extend(i); return p[i] = p[i] == i ? i : find(p[i]); } void unite(int a, int b) { extend(a); extend(b); if ((a = find(a)) != (b = find(b))) { if (s[a] > s[b]) { swap(a, b); } s[b] += s[a]; p[a] = b; } } void unite(pii p) { return unite(p.first, p.second); } bool same(int a, int b) { extend(a); extend(b); return find(a) == find(b); } bool same(pii p) { return same(p.first, p.second); } int size(int x) { extend(x); return s[find(x)]; } }; ll MST(vector<pair<ll, pii>> &E) { Sort(E); UnionFind uf; ll z = 0; for (auto &e : E) { if (!uf.same(e.second)) { z += e.first; uf.unite(e.second); } } return z; } ll strmod(const str &s, const int m) { ll x = 0; fr(i, s.size()) { x = (x * 10 + s[i] - 48) % m; } return x; } vvl mul(const vvl &A, const vvl &B, const int m) { vvl C; fr(y, A.size()) { C << vl(B[y].size()); } fr(y, C.size()) { fr(x, C[y].size()) { fr(i, A[0].size()) { (C[y][x] += A[y][i] * B[i][x]) %= m; } } } return C; } vvl pow(const vvl &A, const ll n, const int m) { vvl B; fr(y, A.size()) { B << vl(A.size()); } if (n == 0) { fr(i, B.size()) { B[i][i] = 1; } } elsif(n % 2) { B = mul(A, pow(A, n - 1, m), m); } else { vvl C = pow(A, n / 2, m); B = mul(C, C, m); } return B; } ll pow(const ll a, const ll n, const int m) { ll t; return n ? (n & 1 ? a >= 0 ? a % m : (m - (-a % m)) % m : 1) * (t = pow(a, n >> 1, m), t * t % m) % m : !!a; } ll inv(const ll x, const int p) { assert(x != 0); return pow(x, p - 2, p); } ll inv(const ll x) { return inv(x, MD); } vpll fact(const int n, const int p) { assert(n < p); vpll v(n + 1); v[0].first = 1; foor(i, 1, n) { v[i].first = v[i - 1].first * i % p; } v[n].second = inv(v[n].first, p); roof(i, n, 1) { v[i - 1].second = v[i].second * i % p; } return v; } class Combination { const vpll f; const int M; public: Combination(int n, int m) : f(fact(n, m)), M(m) {} ll P(int n, int k) { return n < 0 || k < 0 || n < k ? 0ll : f[n].first * f[n - k].second % M; } ll C(int n, int k) { return k < 0 || n < k ? 0ll : P(n, k) * f[k].second % M; } ll H(int n, int k) { return n == 0 && k == 0 ? 1ll : C(n + k - 1, k); } ll F(int n) { return n < 0 ? 0 : f[n].first; } }; ll C2(const int n) { return (ll)n * ~-n / 2; } ll sum(const vi a) { ll s = 0; for (int e : a) { s += e; } return s; } ll sum(const vl a) { ll s = 0; for (ll e : a) { s += e; } return s; } template <typename T> int MSB(T N) { int r = -1; for (; N > 0; N /= 2) { ++r; } return r; } template <typename T> class SegmentTree { vector<T> S; T (*const op)(T a, T b); const T zero; const int B; public: SegmentTree(int N, T (*f)(T a, T b), const T zero) : S(1 << MSB(N - 1) + 2, zero), op(f), zero(zero), B(1 << MSB(N - 1) + 1) {} SegmentTree(vector<T> v, T (*f)(T a, T b), const T zero) : SegmentTree(v.size(), f, zero) { fr(i, v.size()) { S[S.size() / 2 + i] = v[i]; } roof(i, S.size() / 2 - 1, 1) { S[i] = op(S[i * 2], S[i * 2 + 1]); } } T calc(int l, int r) { l += B; r += B; if (l > r) { return zero; } if (l == r) { return S[l]; } T L = S[l], R = S[r]; for (; l / 2 < r / 2; l /= 2, r /= 2) { if (l % 2 == 0) { L = op(L, S[l + 1]); } if (r % 2 == 1) { R = op(S[r - 1], R); } } return op(L, R); } void replace(int i, T x) { for (S[i += B] = x; i != 1; i /= 2) { if (i % 2) { S[i / 2] = op(S[i - 1], S[i]); } else { S[i / 2] = op(S[i], S[i + 1]); } } } void add(int i, T x) { replace(i, op(S[B + i], x)); } T top() { return S[1]; } T get(int i) { return S[i + B]; } }; ll BITsum(vl &B, int i) { ll z = 0; while (i > 0) { z += B[i]; i -= i & -i; } return z; } void BITadd(vl &B, int i, ll x) { while (i < B.size()) { B[i] += x; i += i & -i; } } ll fib(const ll n, const int m) { ll a, b, c, d, A, B, C, D; a = 1; b = 0; c = 0; d = 1; rf(i, 63) { A = a * a + b * c; B = a * b + b * d; C = c * a + d * c; D = c * b + d * d; if (n >> i & 1) { a = A; b = B; c = C; d = D; A = a + b; B = a; C = c + d; D = c; } a = A % m; b = B % m; c = C % m; d = D % m; } return b; } vi primes(int n) { vb b(n + 1); vi p; foor(i, 2, n) { if (!b[i]) { p << i; for (int j = 2 * i; j <= n; j += i) { b[j] = true; } } } return p; } vb isprime(const int n) { vb v(n + 1, true); v[0] = v[1] = false; foor(i, 2, n) { if (v[i]) { for (int j = 2 * i; j <= n; j += i) { v[j] = false; } } } return v; } class LCA { vvi par; vi dep; public: LCA(vvi &E, int root) : par(MSB(E.size()) + 1, vi(E.size())), dep(E.size()) { function<void(int, int)> dfs = [&](int i, int p) { for (int j : E[i]) if (j != p) { par[0][j] = i; dep[j] = dep[i] + 1; dfs(j, i); } }; par[0][root] = root; dfs(root, root); fr(i, par.size() - 1) { fr(j, par[0].size()) { par[i + 1][j] = par[i][par[i][j]]; } } } int operator()(int a, int b) { if (dep[a] > dep[b]) swap(a, b); for (int t = dep[b] - dep[a], i = 0; t; t >>= 1, ++i) { if (t & 1) { b = par[i][b]; } } if (a == b) return a; rf(i, par.size()) { if (par[i][a] != par[i][b]) { a = par[i][a]; b = par[i][b]; } } return par[0][a]; } int dist(int a, int b) { return dep[a] + dep[b] - 2 * dep[operator()(a, b)]; } }; vpli factor(ll N) { vpli r; for (ll i = 2; i * i <= N; ++i) { if (N % i == 0) { r << pli{i, 0}; while (N % i == 0) { N /= i; ++r.back().second; } } } if (N > 1) { r << pli{N, 1}; } return r; } vl divisors(ll n) { vl r; ll m = sqrt(n); foor(i, 1, m) if (n % i == 0) r << ll(i); rf(i, r.size() - (m * m == n)) r << n / r[i]; return r; } vi SuffixArray(str S) { int N = S.size(); vi rank(N + 1), tmp(N + 1), sa(N + 1); fr(i, N) { sa[i] = i; rank[i] = S[i]; } sa[N] = N; rank[N] = -1; int k; auto cmp = [&](int &a, int &b) -> bool { if (rank[a] != rank[b]) return rank[a] < rank[b]; return (a + k <= N ? rank[a + k] : -1) < (b + k <= N ? rank[b + k] : -1); }; for (k = 1; k <= N; k *= 2) { sort(all(sa), cmp); tmp[sa[0]] = 0; foor(i, 1, N) { tmp[sa[i]] = tmp[sa[i - 1]] + cmp(sa[i - 1], sa[i]); } rank = tmp; } return sa; }; template <typename T, typename U> void sort2(vector<T> &a, vector<U> &b) { int N = a.size(); assert(b.size() == N); vector<pair<T, U>> v; fr(i, N) { v << pair<T, U>{a[i], b[i]}; } Sort(v); fr(i, N) { a[i] = v[i].first; b[i] = v[i].second; } } int main() { cin.tie(0); ios::sync_with_stdio(false); int M = 1e6; vvi D(M + 1); foor(i, 1, M) { for (int j = i; j <= M; j += i) { D[j] << i; } } int N; cin >> N; vi A(N); cin >> A; vi B(M + 1); fr(i, N) { ++B[A[i]]; } int z = 0; fr(i, N) { bool x = true; for (int d : D[A[i]]) { x &= B[d] == (d == A[i]); } z += x; } print(z); return 0; }
replace
692
693
692
693
0
p02642
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = int64_t; using pint = pair<int, int>; int main() { int n; cin >> n; vector<bool> era(200001, false); vector<int> a(n); vector<int> check; rep(i, n) { cin >> a[i]; if (era[a[i]]) check.emplace_back(a[i]); era[a[i]] = true; } sort(a.begin(), a.end()); for (int i : check) era[i] = false; int ans = 0; for (int t : a) { if (era[t]) ++ans; for (int i = t + t; i <= a[n - 1]; i += t) era[i] = false; } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = int64_t; using pint = pair<int, int>; int main() { int n; cin >> n; vector<bool> era(1000001, false); vector<int> a(n); vector<int> check; rep(i, n) { cin >> a[i]; if (era[a[i]]) check.emplace_back(a[i]); era[a[i]] = true; } sort(a.begin(), a.end()); for (int i : check) era[i] = false; int ans = 0; for (int t : a) { if (era[t]) ++ans; for (int i = t + t; i <= a[n - 1]; i += t) era[i] = false; } cout << ans << endl; }
replace
10
11
10
11
0
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef map<int, int> mii; typedef vector<int> vi; #define pb push_back #define sc(n) scanf("%d", &n) #define lsc(n) scanf("%lld", &n) #define all(x) x.begin(), x.end() #define rep(i, n) for (i = 0; i < n; i++) #define rep1(i, n) for (i = 1; i <= n; i++) #define rev(i, n) for (i = n - 1; i >= 0; i--) #define rev1(i, n) for (i = n; i > 0; i--) #define in insert #define pr(n) printf("%d\n", n) #define lpr(n) printf("%lld\n", n); int main() { ll n, i, j; cin >> n; vector<ll> v, vv; map<ll, ll> mp; map<ll, ll>::iterator it; ll mx = 0, mn = 1e9; rep(i, n) { ll m; lsc(m); mp[m]++; vv.pb(m); mx = max(mx, m); mn = min(mn, m); } if (n == 1) { cout << 1 << endl; return 0; } if (mn == mx) { cout << 0 << endl; return 0; } for (it = mp.begin(); it != mp.end(); it++) { if ((it->second) == 1) { v.pb(it->first); } } ll sz = v.size(); for (i = 0; i < n; i++) { ll k = v[i]; for (j = (2LL * k); j <= mx; j += k) { if (mp[j] == 1) { sz--; mp[j] = 0; } } } cout << sz << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef map<int, int> mii; typedef vector<int> vi; #define pb push_back #define sc(n) scanf("%d", &n) #define lsc(n) scanf("%lld", &n) #define all(x) x.begin(), x.end() #define rep(i, n) for (i = 0; i < n; i++) #define rep1(i, n) for (i = 1; i <= n; i++) #define rev(i, n) for (i = n - 1; i >= 0; i--) #define rev1(i, n) for (i = n; i > 0; i--) #define in insert #define pr(n) printf("%d\n", n) #define lpr(n) printf("%lld\n", n); int main() { ll n, i, j; cin >> n; vector<ll> v, vv; map<ll, ll> mp; map<ll, ll>::iterator it; ll mx = 0, mn = 1e9; rep(i, n) { ll m; lsc(m); mp[m]++; vv.pb(m); mx = max(mx, m); mn = min(mn, m); } if (n == 1) { cout << 1 << endl; return 0; } if (mn == mx) { cout << 0 << endl; return 0; } for (it = mp.begin(); it != mp.end(); it++) { if ((it->second) == 1) { v.pb(it->first); } } ll sz = v.size(); for (i = 0; i < n; i++) { ll k = vv[i]; for (j = (2LL * k); j <= mx; j += k) { if (mp[j] == 1) { sz--; mp[j] = 0; } } } cout << sz << endl; return 0; }
replace
49
50
49
50
0
p02642
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (ll i = 0; i < n; ++i) #define FOR(i, b, n) for (ll i = b; i < n; ++i) using namespace std; using ll = long long; using P = pair<int, int>; void solve(ll N, vector<ll> A) { sort(A.begin(), A.end()); vector<bool> prime(A.back(), false); REP(i, N) prime[A[i]] = true; REP(i, N) { if (!prime[A[i]]) continue; if (i < N - 1 && A[i] == A[i + 1]) prime[A[i]] = false; FOR(j, 2, A.back() / A[i] + 1) prime[A[i] * j] = false; } ll ans(0); REP(i, N) { if (prime[A[i]]) ans++; } cout << ans << endl; } int main() { // int 3E4 long 2E9 ll 9E18 cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; vector<ll> A(N); REP(i, N) { cin >> A[i]; } solve(N, move(A)); return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (ll i = 0; i < n; ++i) #define FOR(i, b, n) for (ll i = b; i < n; ++i) using namespace std; using ll = long long; using P = pair<int, int>; void solve(ll N, vector<ll> A) { sort(A.begin(), A.end()); vector<bool> prime(A.back() + 1, false); REP(i, N) prime[A[i]] = true; REP(i, N) { if (!prime[A[i]]) continue; if (i < N - 1 && A[i] == A[i + 1]) prime[A[i]] = false; FOR(j, 2, A.back() / A[i] + 1) prime[A[i] * j] = false; } ll ans(0); REP(i, N) { if (prime[A[i]]) ans++; } cout << ans << endl; } int main() { // int 3E4 long 2E9 ll 9E18 cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; vector<ll> A(N); REP(i, N) { cin >> A[i]; } solve(N, move(A)); return 0; }
replace
11
12
11
12
0
p02642
C++
Time Limit Exceeded
#define _USE_MATH_DEFINES #include <algorithm> #include <array> #include <bitset> #include <climits> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <time.h> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> #define lnd '\n' // #define reverse(i, n) for(ll i = n-1; i >= 0; --i) #define from(i, n) for (ll i = 0; i < n; ++i) #define loop(i, n) for (ll i = 0; i < n; i++) #define REPN(i, n) for (ll i = 1; i <= n; ++i) #define ALL(s) (s).begin(), (s).end() #define rALL(s) (s).rbegin(), (s).rend() #define sz(s) (int)(s).size() #define mk make_pair #define pb push_back #define sqr(s) ((s) * (s)) using namespace std; typedef long long ll; typedef long long int lli; typedef long double ld; typedef unsigned long long ull; typedef unsigned int ui; template <class T> T GCD(T a, T b) { if (a == 0) return b; return GCD(b % a, a); } template <class T> T LCM(T a, T b) { return a * b / GCM(a, b); } template <class T> T modpow(T x, T p) { T res = 1; while (p > 0) { if (p & 1) res *= x; x *= x; p /= 2; } return res; } template <class T> T modpow(T x, T p, ll mod) { T res = 1; while (p > 0) { if (p & 1) res = (res * x) % mod; x = (x * x) % mod; p /= 2; } return res % mod; } template <class T> void print(T a[], ll n) { for (ll i = 0; i < n; i++) std::cout << a[i] << ' '; cout << endl; } template <class T> void printc(T c) { for (auto const &v : c) std::cout << v << ' '; cout << endl; } struct HASH { size_t operator()(const pair<long, long> &x) const { return hash<long long>()(((long long)x.first) ^ (((long long)x.second) << 32)); } }; bool pair_sort(const pair<int, int> &p1, const pair<int, int> &p2) { if (p1.first != p2.first) return p1.first < p2.first; else return p1.second < p2.second; } const int INF = std::numeric_limits<int>::max(); const ll M_INF = std::numeric_limits<ll>::min(); const ll LL_INF = std::numeric_limits<ll>::max(); void solution(); int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solution(); return 0; } void solution() { ll n; cin >> n; ll m = 1e6 + 1; vector<ll> b(m, 0); vector<ll> a(n); loop(i, n) { cin >> a[i]; b[a[i]] = 1; } for (auto i : a) { for (ll j = i; j < m; j += i) { b[j]++; } } ll count = 0; for (ll i = 0; i < n; i++) { if (b[a[i]] == 2) { count++; } } cout << count << endl; }
#define _USE_MATH_DEFINES #include <algorithm> #include <array> #include <bitset> #include <climits> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <time.h> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> #define lnd '\n' // #define reverse(i, n) for(ll i = n-1; i >= 0; --i) #define from(i, n) for (ll i = 0; i < n; ++i) #define loop(i, n) for (ll i = 0; i < n; i++) #define REPN(i, n) for (ll i = 1; i <= n; ++i) #define ALL(s) (s).begin(), (s).end() #define rALL(s) (s).rbegin(), (s).rend() #define sz(s) (int)(s).size() #define mk make_pair #define pb push_back #define sqr(s) ((s) * (s)) using namespace std; typedef long long ll; typedef long long int lli; typedef long double ld; typedef unsigned long long ull; typedef unsigned int ui; template <class T> T GCD(T a, T b) { if (a == 0) return b; return GCD(b % a, a); } template <class T> T LCM(T a, T b) { return a * b / GCM(a, b); } template <class T> T modpow(T x, T p) { T res = 1; while (p > 0) { if (p & 1) res *= x; x *= x; p /= 2; } return res; } template <class T> T modpow(T x, T p, ll mod) { T res = 1; while (p > 0) { if (p & 1) res = (res * x) % mod; x = (x * x) % mod; p /= 2; } return res % mod; } template <class T> void print(T a[], ll n) { for (ll i = 0; i < n; i++) std::cout << a[i] << ' '; cout << endl; } template <class T> void printc(T c) { for (auto const &v : c) std::cout << v << ' '; cout << endl; } struct HASH { size_t operator()(const pair<long, long> &x) const { return hash<long long>()(((long long)x.first) ^ (((long long)x.second) << 32)); } }; bool pair_sort(const pair<int, int> &p1, const pair<int, int> &p2) { if (p1.first != p2.first) return p1.first < p2.first; else return p1.second < p2.second; } const int INF = std::numeric_limits<int>::max(); const ll M_INF = std::numeric_limits<ll>::min(); const ll LL_INF = std::numeric_limits<ll>::max(); void solution(); int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solution(); return 0; } void solution() { ll n; cin >> n; ll m = 1e6 + 1; vector<ll> b(m, 0); vector<ll> a(n); loop(i, n) { cin >> a[i]; b[a[i]] = 1; } for (auto i : a) { if (b[i] >= 2) { b[i]++; continue; } for (ll j = i; j < m; j += i) { b[j]++; } } ll count = 0; for (ll i = 0; i < n; i++) { if (b[a[i]] == 2) { count++; } } cout << count << endl; }
insert
127
127
127
131
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define ll long long #define pii pair<int, int> #define sz(x) (int)x.size() #define f first #define s second using namespace std; const int N = 1e3 + 2; const int M = 1e8; int cnt[N]; int a[N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int x; for (int i = 0; i < n; i++) { cin >> a[i]; x = a[i]; cnt[x]++; } int ans = 0; for (int i = 0; i < n; i++) { ll how = 0; cnt[a[i]]--; for (int j = 1; j * j <= a[i]; j++) { if (a[i] % j) continue; if (j * j == x) { how += cnt[j]; } else { how += cnt[j]; how += cnt[a[i] / j]; } } ans += (how == 0); cnt[a[i]]++; // cout<<how<<" "; } // ll ans1=0; // for(int i=0;i<n;i++){ // bool ok=1; // for(int j=0;j<n;j++){ // if(i==j) continue; // if(a[j]%a[i]==0){ // ok=0; // break; // } // } // ans1+=ok; // } cout << ans; return 0; } // abcd
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define ll long long #define pii pair<int, int> #define sz(x) (int)x.size() #define f first #define s second using namespace std; const int N = 1e6 + 2; const int M = 1e8; int cnt[N]; int a[N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int x; for (int i = 0; i < n; i++) { cin >> a[i]; x = a[i]; cnt[x]++; } int ans = 0; for (int i = 0; i < n; i++) { ll how = 0; cnt[a[i]]--; for (int j = 1; j * j <= a[i]; j++) { if (a[i] % j) continue; if (j * j == x) { how += cnt[j]; } else { how += cnt[j]; how += cnt[a[i] / j]; } } ans += (how == 0); cnt[a[i]]++; // cout<<how<<" "; } // ll ans1=0; // for(int i=0;i<n;i++){ // bool ok=1; // for(int j=0;j<n;j++){ // if(i==j) continue; // if(a[j]%a[i]==0){ // ok=0; // break; // } // } // ans1+=ok; // } cout << ans; return 0; } // abcd
replace
8
9
8
9
0
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> #ifdef LOCAL_DEBUG #define DEBUG 1 #define CERR \ if (DEBUG) \ cerr #define MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, NAME, ...) NAME #define pr(...) \ CERR << MACRO(__VA_ARGS__, pr10, pr9, pr8, pr7, pr6, pr5, pr4, pr3, pr2, \ pr1)(__VA_ARGS__) \ << endl #define pr1(a) (#a) << "=" << (a) << " " #define pr2(a, b) pr1(a) << pr1(b) #define pr3(a, b, c) pr1(a) << pr2(b, c) #define pr4(a, b, c, d) pr1(a) << pr3(b, c, d) #define pr5(a, b, c, d, e) pr1(a) << pr4(b, c, d, e) #define pr6(a, b, c, d, e, f) pr1(a) << pr5(b, c, d, e, f) #define pr7(a, b, c, d, e, f, g) pr1(a) << pr6(b, c, d, e, f, g) #define pr8(a, b, c, d, e, f, g, h) pr1(a) << pr7(b, c, d, e, f, g, h) #define pr9(a, b, c, d, e, f, g, h, i) pr1(a) << pr8(b, c, d, e, f, g, h, i) #define pr10(a, b, c, d, e, f, g, h, i, j) \ pr1(a) << pr9(b, c, d, e, f, g, h, i, j) #define prArr(a) \ { \ CERR << (#a) << "={"; \ int i = 0; \ for (auto t : (a)) \ CERR << (i++ ? ", " : "") << t; \ CERR << "}" << endl; \ } #else #define DEBUG 0 #define pr(...) #define prArr(a) #endif using namespace std; using Int = long long; using _int = int; using ll = long long; using Double = long double; const Int INF = (1LL << 60) + 1e9; // ~ 1.15 * 1e18 const Int mod = (1e9) + 7; const Double EPS = 1e-8; const Double PI = 6.0 * asin((Double)0.5); using P = pair<Int, Int>; template <class T> T Max(T &a, T b) { return a = max(a, b); } template <class T> T Min(T &a, T b) { return a = min(a, b); } template <class T1, class T2> ostream &operator<<(ostream &o, pair<T1, T2> p) { return o << "(" << p.first << "," << p.second << ")"; } template <class T1, class T2, class T3> ostream &operator<<(ostream &o, tuple<T1, T2, T3> t) { return o << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")"; } template <class T1, class T2> istream &operator>>(istream &i, pair<T1, T2> &p) { return i >> p.first >> p.second; } template <class T> ostream &operator<<(ostream &o, vector<T> a) { Int i = 0; for (T t : a) o << (i++ ? " " : "") << t; return o; } template <class T> istream &operator>>(istream &i, vector<T> &a) { for (T &t : a) i >> t; return i; } // INSERT ABOVE HERE signed main() { srand((unsigned)time(NULL)); cin.tie(0); ios_base::sync_with_stdio(0); cout << fixed << setprecision(12); Int N; cin >> N; vector<Int> A(N); cin >> A; vector<Int> cnt(1000010); for (Int a : A) cnt[a]++; for (Int a : A) { for (Int j = 2; a * j < (Int)cnt.size(); j++) cnt[a * j] = 0; } Int ans = 0; for (Int c : cnt) if (c == 1) ans += c; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #ifdef LOCAL_DEBUG #define DEBUG 1 #define CERR \ if (DEBUG) \ cerr #define MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, NAME, ...) NAME #define pr(...) \ CERR << MACRO(__VA_ARGS__, pr10, pr9, pr8, pr7, pr6, pr5, pr4, pr3, pr2, \ pr1)(__VA_ARGS__) \ << endl #define pr1(a) (#a) << "=" << (a) << " " #define pr2(a, b) pr1(a) << pr1(b) #define pr3(a, b, c) pr1(a) << pr2(b, c) #define pr4(a, b, c, d) pr1(a) << pr3(b, c, d) #define pr5(a, b, c, d, e) pr1(a) << pr4(b, c, d, e) #define pr6(a, b, c, d, e, f) pr1(a) << pr5(b, c, d, e, f) #define pr7(a, b, c, d, e, f, g) pr1(a) << pr6(b, c, d, e, f, g) #define pr8(a, b, c, d, e, f, g, h) pr1(a) << pr7(b, c, d, e, f, g, h) #define pr9(a, b, c, d, e, f, g, h, i) pr1(a) << pr8(b, c, d, e, f, g, h, i) #define pr10(a, b, c, d, e, f, g, h, i, j) \ pr1(a) << pr9(b, c, d, e, f, g, h, i, j) #define prArr(a) \ { \ CERR << (#a) << "={"; \ int i = 0; \ for (auto t : (a)) \ CERR << (i++ ? ", " : "") << t; \ CERR << "}" << endl; \ } #else #define DEBUG 0 #define pr(...) #define prArr(a) #endif using namespace std; using Int = long long; using _int = int; using ll = long long; using Double = long double; const Int INF = (1LL << 60) + 1e9; // ~ 1.15 * 1e18 const Int mod = (1e9) + 7; const Double EPS = 1e-8; const Double PI = 6.0 * asin((Double)0.5); using P = pair<Int, Int>; template <class T> T Max(T &a, T b) { return a = max(a, b); } template <class T> T Min(T &a, T b) { return a = min(a, b); } template <class T1, class T2> ostream &operator<<(ostream &o, pair<T1, T2> p) { return o << "(" << p.first << "," << p.second << ")"; } template <class T1, class T2, class T3> ostream &operator<<(ostream &o, tuple<T1, T2, T3> t) { return o << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")"; } template <class T1, class T2> istream &operator>>(istream &i, pair<T1, T2> &p) { return i >> p.first >> p.second; } template <class T> ostream &operator<<(ostream &o, vector<T> a) { Int i = 0; for (T t : a) o << (i++ ? " " : "") << t; return o; } template <class T> istream &operator>>(istream &i, vector<T> &a) { for (T &t : a) i >> t; return i; } // INSERT ABOVE HERE signed main() { srand((unsigned)time(NULL)); cin.tie(0); ios_base::sync_with_stdio(0); cout << fixed << setprecision(12); Int N; cin >> N; vector<Int> A(N); cin >> A; vector<Int> cnt(1000010); for (Int a : A) cnt[a]++; sort(A.begin(), A.end()); A.erase(unique(A.begin(), A.end()), A.end()); for (Int a : A) { for (Int j = 2; a * j < (Int)cnt.size(); j++) cnt[a * j] = 0; } Int ans = 0; for (Int c : cnt) if (c == 1) ans += c; cout << ans << endl; return 0; }
insert
84
84
84
86
TLE
p02642
C++
Time Limit Exceeded
#include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <vector> using namespace std; /* using PAIR = pair<string, int>; sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){ return l.first<r.first || (l.first==r.first && l.second > r.second); }); */ typedef long long ll; #define fi first #define se second #define rep(i, n) for (ll i = 0; i < n; i++) #define debugA() cerr << "AAAAA" << endl #define debug_() cerr << "-------------" << endl #define debug(x) cerr << #x << ": " << x << endl #define debug_vec(v) \ cout << #v << endl; \ for (int i = 0; i < v.size(); i++) { \ cout << v[i] << " "; \ } \ cout << endl; #define debug_vec2(v) \ cout << #v << endl; \ for (int i = 0; i < v.size(); i++) { \ for (int j = 0; j < v[i].size(); j++) { \ cout << v[i][j] << " "; \ } \ cout << endl; \ } using Graph = vector<vector<int>>; using P = pair<int, int>; using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, // to}}的に使う。 const int INF = 1001001001; const double pi = acos(-1); int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> vec(1000000 + 1, 0); sort(a.begin(), a.end()); for (int i = 0; i < n; i++) { for (int j = a[i]; j < 1000000 + 1; j += a[i]) { vec[j]++; } } int ans = 0; for (int i = 0; i < n; i++) { if (vec[a[i]] == 1) { ans++; } } cout << ans << endl; return 0; }
#include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <vector> using namespace std; /* using PAIR = pair<string, int>; sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){ return l.first<r.first || (l.first==r.first && l.second > r.second); }); */ typedef long long ll; #define fi first #define se second #define rep(i, n) for (ll i = 0; i < n; i++) #define debugA() cerr << "AAAAA" << endl #define debug_() cerr << "-------------" << endl #define debug(x) cerr << #x << ": " << x << endl #define debug_vec(v) \ cout << #v << endl; \ for (int i = 0; i < v.size(); i++) { \ cout << v[i] << " "; \ } \ cout << endl; #define debug_vec2(v) \ cout << #v << endl; \ for (int i = 0; i < v.size(); i++) { \ for (int j = 0; j < v[i].size(); j++) { \ cout << v[i][j] << " "; \ } \ cout << endl; \ } using Graph = vector<vector<int>>; using P = pair<int, int>; using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, // to}}的に使う。 const int INF = 1001001001; const double pi = acos(-1); int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> vec(1000000 + 1, 0); sort(a.begin(), a.end()); for (int i = 0; i < n; i++) { if (vec[a[i]] == 0) { for (int j = a[i]; j <= a.back(); j += a[i]) { vec[j]++; } } else { vec[a[i]]++; } } int ans = 0; for (int i = 0; i < n; i++) { if (vec[a[i]] == 1) { ans++; } } cout << ans << endl; return 0; }
replace
67
69
67
73
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i < (n); ++i) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define maxs(a, b) a = max(a, b) #define mins(a, b) a = min(a, b) using namespace std; typedef long long ll; typedef pair<int, int> P; const ll linf = (1ll << 61); const int inf = 1001001001; const int mod = 1000000007; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end()); vector<int> b = a; vector<bool> mp(200005); rrep(i, n) { if (a[i] == a[i - 1]) mp[a[i]] = true; } int ans = 0; for (int i = n - 1; i >= 0; --i) { int x = a[i]; b.pop_back(); if (mp[a[i]]) { ans++; continue; } vector<int> rec; for (int j = 1; j * j <= x; ++j) { if (x % j == 0) { rec.push_back(j); if (j * j != x) rec.push_back(x / j); } } bool ok = false; for (int c : rec) { if (binary_search(all(b), c)) { ok = true; break; } } if (ok) ans++; } cout << n - ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i < (n); ++i) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define maxs(a, b) a = max(a, b) #define mins(a, b) a = min(a, b) using namespace std; typedef long long ll; typedef pair<int, int> P; const ll linf = (1ll << 61); const int inf = 1001001001; const int mod = 1000000007; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end()); vector<int> b = a; vector<bool> mp(1000005); rrep(i, n) { if (a[i] == a[i - 1]) mp[a[i]] = true; } int ans = 0; for (int i = n - 1; i >= 0; --i) { int x = a[i]; b.pop_back(); if (mp[a[i]]) { ans++; continue; } vector<int> rec; for (int j = 1; j * j <= x; ++j) { if (x % j == 0) { rec.push_back(j); if (j * j != x) rec.push_back(x / j); } } bool ok = false; for (int c : rec) { if (binary_search(all(b), c)) { ok = true; break; } } if (ok) ans++; } cout << n - ans << endl; return 0; }
replace
23
24
23
24
0
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> const long long INF = 1LL << 60; const long long MOD = 1000000007; const double PI = acos(-1.0); #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep1(i, n) for (ll i = 1; i <= (n); ++i) #define rrep(i, n) for (ll i = (n - 1); i >= 0; --i) #define perm(c) \ sort(ALL(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c))) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define pb push_back #define to_s to_string #define len(v) (ll) v.size() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define print(x) cout << (x) << '\n' #define drop(x) cout << (x) << '\n', exit(0) #define debug(x) cout << #x << ": " << (x) << '\n' using namespace std; using ll = long long; typedef pair<ll, ll> P; typedef vector<ll> vec; typedef vector<vector<ll>> vec2; typedef vector<vector<vector<ll>>> vec3; template <class S, class T> inline bool chmax(S &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class S, class T> inline bool chmin(S &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } inline ll msb(ll v) { return 1 << (31 - __builtin_clzll(v)); } inline ll devc(ll x, ll y) { return (x + y - 1) / y; } inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); } struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << " " << p.second; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T1, typename T2, typename T3> ostream &operator<<(ostream &os, const tuple<T1, T2, T3> &t) { os << get<0>(t) << " " << get<1>(t) << " " << get<2>(t); return os; } template <typename T1, typename T2, typename T3> istream &operator>>(istream &is, tuple<T1, T2, T3> &t) { is >> get<0>(t) >> get<1>(t) >> get<2>(t); return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); ++i) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } /*--------------------------------- Tools * ------------------------------------------*/ template <typename T> vector<T> cumsum(const vector<T> &X) { vector<T> res(X.size() + 1, 0); for (int i = 0; i < X.size(); ++i) res[i + 1] += res[i] + X[i]; return res; } template <typename S, typename T, typename F> pair<T, T> bisearch(S left, T right, F f) { while (abs(right - left) > 1) { T mid = (right + left) / 2; if (f(mid)) right = mid; else left = mid; } return {left, right}; } template <typename S, typename T, typename F> double trisearch(S left, T right, F f, int maxLoop = 90) { double low = left, high = right; while (maxLoop--) { double mid_left = high / 3 + low * 2 / 3; double mid_right = high * 2 / 3 + low / 3; if (f(mid_left) >= f(mid_right)) low = mid_left; else high = mid_right; } return (low + high) * 0.5; } template <typename F> ll ternarySearch(ll L, ll R, F f) { //[L, R) ll lo = L - 1, hi = R - 1; while (lo + 1 != hi) { ll mi = (lo + hi) / 2; if (f(mi) <= f(mi + 1)) hi = mi; else lo = mi; } return hi; } struct UnionFind { vector<int> par; vector<int> rank; vector<int> num; UnionFind(int N) : par(N), rank(N), num(N) { for (int i = 0; i < N; i++) { par[i] = i; rank[i] = 0; num[i] = 1; } } void init(int N) { for (int i = 0; i < N; i++) { par[i] = i; rank[i] = 0; num[i] = 1; } } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } int ranker(int x) { x = root(x); return rank[x]; } int number(int x) { x = root(x); return num[x]; } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; if (rank[rx] < rank[ry]) { par[rx] = ry; num[ry] += num[rx]; num[rx] = 0; } else { par[ry] = rx; num[rx] += num[ry]; num[ry] = 0; if (rank[rx] == rank[ry]) rank[rx]++; } } bool same(int x, int y) { return root(x) == root(y); } }; /*------------------------------- Main Code Here * -----------------------------------------*/ int main() { ll N; cin >> N; vec A(N); cin >> A; map<ll, ll> mp; rep(i, N) mp[A[i]]++; multiset<ll> st; rep(i, N) st.insert(A[i]); for (auto s : st) { ll k = 2; while (k * s <= 1e6) { st.erase(k * s); ++k; } } multiset<ll> ans = st; for (auto s : st) { if (mp[s] > 1) { ans.erase(s); } } print(len(ans)); return 0; }
#include <bits/stdc++.h> const long long INF = 1LL << 60; const long long MOD = 1000000007; const double PI = acos(-1.0); #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep1(i, n) for (ll i = 1; i <= (n); ++i) #define rrep(i, n) for (ll i = (n - 1); i >= 0; --i) #define perm(c) \ sort(ALL(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c))) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define pb push_back #define to_s to_string #define len(v) (ll) v.size() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define print(x) cout << (x) << '\n' #define drop(x) cout << (x) << '\n', exit(0) #define debug(x) cout << #x << ": " << (x) << '\n' using namespace std; using ll = long long; typedef pair<ll, ll> P; typedef vector<ll> vec; typedef vector<vector<ll>> vec2; typedef vector<vector<vector<ll>>> vec3; template <class S, class T> inline bool chmax(S &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class S, class T> inline bool chmin(S &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } inline ll msb(ll v) { return 1 << (31 - __builtin_clzll(v)); } inline ll devc(ll x, ll y) { return (x + y - 1) / y; } inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); } struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << " " << p.second; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T1, typename T2, typename T3> ostream &operator<<(ostream &os, const tuple<T1, T2, T3> &t) { os << get<0>(t) << " " << get<1>(t) << " " << get<2>(t); return os; } template <typename T1, typename T2, typename T3> istream &operator>>(istream &is, tuple<T1, T2, T3> &t) { is >> get<0>(t) >> get<1>(t) >> get<2>(t); return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); ++i) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } /*--------------------------------- Tools * ------------------------------------------*/ template <typename T> vector<T> cumsum(const vector<T> &X) { vector<T> res(X.size() + 1, 0); for (int i = 0; i < X.size(); ++i) res[i + 1] += res[i] + X[i]; return res; } template <typename S, typename T, typename F> pair<T, T> bisearch(S left, T right, F f) { while (abs(right - left) > 1) { T mid = (right + left) / 2; if (f(mid)) right = mid; else left = mid; } return {left, right}; } template <typename S, typename T, typename F> double trisearch(S left, T right, F f, int maxLoop = 90) { double low = left, high = right; while (maxLoop--) { double mid_left = high / 3 + low * 2 / 3; double mid_right = high * 2 / 3 + low / 3; if (f(mid_left) >= f(mid_right)) low = mid_left; else high = mid_right; } return (low + high) * 0.5; } template <typename F> ll ternarySearch(ll L, ll R, F f) { //[L, R) ll lo = L - 1, hi = R - 1; while (lo + 1 != hi) { ll mi = (lo + hi) / 2; if (f(mi) <= f(mi + 1)) hi = mi; else lo = mi; } return hi; } struct UnionFind { vector<int> par; vector<int> rank; vector<int> num; UnionFind(int N) : par(N), rank(N), num(N) { for (int i = 0; i < N; i++) { par[i] = i; rank[i] = 0; num[i] = 1; } } void init(int N) { for (int i = 0; i < N; i++) { par[i] = i; rank[i] = 0; num[i] = 1; } } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } int ranker(int x) { x = root(x); return rank[x]; } int number(int x) { x = root(x); return num[x]; } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; if (rank[rx] < rank[ry]) { par[rx] = ry; num[ry] += num[rx]; num[rx] = 0; } else { par[ry] = rx; num[rx] += num[ry]; num[ry] = 0; if (rank[rx] == rank[ry]) rank[rx]++; } } bool same(int x, int y) { return root(x) == root(y); } }; /*------------------------------- Main Code Here * -----------------------------------------*/ int main() { ll N; cin >> N; vec A(N); cin >> A; map<ll, ll> mp; rep(i, N) mp[A[i]]++; multiset<ll> st; rep(i, N) st.insert(A[i]); if (st.count(1)) { if (mp[1] > 1) drop(0); else drop(1); } set<ll> visited; for (auto s : st) { ll k = 2; while (k * s <= 1e6) { st.erase(k * s); ++k; } } multiset<ll> ans = st; for (auto s : st) { if (mp[s] > 1) { ans.erase(s); } } print(len(ans)); return 0; }
insert
210
210
210
218
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define gc getchar_unlocked #define foi(i, n) for (int i = 0; i < n; i++) #define Foi(i, k, n) \ for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) #define fol(i, n) for (ll i = 0; i < n; i++) #define Fol(i, k, n) \ for (ll i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) #define ll long long #define si(x) scanf("%d", &x) #define sl(x) scanf("%lld", &x) #define ss(s) scanf("%s", s) #define pi(x) printf("%d\n", x) #define pl(x) printf("%lld\n", x) #define ps(s) printf("%s\n", s) #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; int mpow(int base, int exp); void ipgraph(int m); void dfs(int u, int par); const int mod = 1000000007; const int N = 3e5, M = N; //======================= vi g[N]; int a[N]; int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = ((ll)result * base) % mod; base = ((ll)base * base) % mod; exp >>= 1; } return result; } void ipgraph(int n, int m) { int i, u, v; while (m--) { cin >> u >> v; g[u - 1].pb(v - 1); g[v - 1].pb(u - 1); } } void dfs(int u, int par) { for (int v : g[u]) { if (v == par) continue; dfs(v, u); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<ll> x(n); int check[400005] = {0}; map<ll, int> m; for (int i = 0; i < n; i++) { cin >> x[i]; m[x[i]]++; } int max_ele = *max_element(all(x)); for (int i = 0; i < n; i++) { if (!check[x[i]]) { for (int j = x[i] + x[i]; j <= max_ele; j += x[i]) check[j] = 1; } } int count = 0; for (int i = 0; i < n; i++) { if (!check[x[i]] && m[x[i]] == 1) { count++; } } cout << count; }
#include <bits/stdc++.h> using namespace std; #define gc getchar_unlocked #define foi(i, n) for (int i = 0; i < n; i++) #define Foi(i, k, n) \ for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) #define fol(i, n) for (ll i = 0; i < n; i++) #define Fol(i, k, n) \ for (ll i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) #define ll long long #define si(x) scanf("%d", &x) #define sl(x) scanf("%lld", &x) #define ss(s) scanf("%s", s) #define pi(x) printf("%d\n", x) #define pl(x) printf("%lld\n", x) #define ps(s) printf("%s\n", s) #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; int mpow(int base, int exp); void ipgraph(int m); void dfs(int u, int par); const int mod = 1000000007; const int N = 3e5, M = N; //======================= vi g[N]; int a[N]; int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = ((ll)result * base) % mod; base = ((ll)base * base) % mod; exp >>= 1; } return result; } void ipgraph(int n, int m) { int i, u, v; while (m--) { cin >> u >> v; g[u - 1].pb(v - 1); g[v - 1].pb(u - 1); } } void dfs(int u, int par) { for (int v : g[u]) { if (v == par) continue; dfs(v, u); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<ll> x(n); int check[1000001] = {0}; map<ll, int> m; for (int i = 0; i < n; i++) { cin >> x[i]; m[x[i]]++; } int max_ele = *max_element(all(x)); for (int i = 0; i < n; i++) { if (!check[x[i]]) { for (int j = x[i] + x[i]; j <= max_ele; j += x[i]) check[j] = 1; } } int count = 0; for (int i = 0; i < n; i++) { if (!check[x[i]] && m[x[i]] == 1) { count++; } } cout << count; }
replace
83
84
83
84
0
p02642
C++
Runtime Error
#include <algorithm> #include <bitset> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, MAXN = 100010, i, j, k, ans, x; cin >> n; vector<int> ct(MAXN, 0); vector<bool> valid(MAXN, true); for (i = 0; i < n; i++) { cin >> x; ct[x]++; } ans = 0; for (i = 0; i < MAXN; i++) { if (valid[i] && (ct[i] == 1)) ans++; if (ct[i] > 0) { for (j = i + i; j < MAXN; j += i) valid[j] = false; } } cout << ans << "\n"; return 0; }
#include <algorithm> #include <bitset> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, MAXN = 1000010, i, j, k, ans, x; cin >> n; vector<int> ct(MAXN, 0); vector<bool> valid(MAXN, true); for (i = 0; i < n; i++) { cin >> x; ct[x]++; } ans = 0; for (i = 0; i < MAXN; i++) { if (valid[i] && (ct[i] == 1)) ans++; if (ct[i] > 0) { for (j = i + i; j < MAXN; j += i) valid[j] = false; } } cout << ans << "\n"; return 0; }
replace
24
25
24
25
0
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define endl '\n' typedef pair<int, int> P; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> v(n); rep(i, n) { cin >> v[i]; } sort(v.begin(), v.end()); vector<bool> dp(1000010, true); int ans = 0; rep(i, n) { if (i + 1 < n && v[i] == v[i + 1]) { dp[v[i]] = false; } ans += dp[v[i]]; for (int j = v[i]; j <= 1000000; j += v[i]) { dp[j] = false; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define endl '\n' typedef pair<int, int> P; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> v(n); rep(i, n) { cin >> v[i]; } sort(v.begin(), v.end()); vector<bool> dp(1000010, true); int ans = 0; rep(i, n) { if (dp[v[i]] == false) { continue; } if (i + 1 < n && v[i] == v[i + 1]) { dp[v[i]] = false; } ans += dp[v[i]]; for (int j = v[i]; j <= 1000000; j += v[i]) { dp[j] = false; } } cout << ans << endl; }
insert
18
18
18
21
TLE
p02642
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define REP(i, N) for (int i = 0; i < (int)N; i++) #define FOR(i, a, b) for (int i = a; i < (int)b; i++) #define ALL(x) (x).begin(), (x).end() #define INF (1 << 30) #define LLINF (1LL << 62) #define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__) constexpr int MOD = 1000000007; using ll = long long; using Pii = pair<int, int>; using Pll = pair<ll, ll>; inline int popcount(ll x) { return __builtin_popcountll(x); } inline int div2num(ll x) { return __builtin_ctzll(x); } inline bool bit(ll x, int b) { return (x >> b) & 1; } template <class T> string to_string(T s); template <class S, class T> string to_string(pair<S, T> p); string to_string(string s) { return s; } string to_string(const char s[]) { return to_string(string(s)); } template <class T> string to_string(T v) { if (v.empty()) return "{}"; string ret = "{"; for (auto x : v) ret += to_string(x) + ","; ret.back() = '}'; return ret; } template <class S, class T> string to_string(pair<S, T> p) { return "{" + to_string(p.first) + ":" + to_string(p.second) + "}"; } void debug() { cerr << endl; } template <class Head, class... Tail> void debug(Head head, Tail... tail) { cerr << to_string(head) << " "; debug(tail...); } struct IO { #ifdef _WIN32 inline char getchar_unlocked() { return getchar(); } inline void putchar_unlocked(char c) { putchar(c); } #endif std::string separator = " "; template <class T> inline void read(T &x) { char c; do { c = getchar_unlocked(); } while (c != '-' && (c < '0' || '9' < c)); bool minus = 0; if (c == '-') { minus = 1; c = getchar_unlocked(); } x = 0; while ('0' <= c && c <= '9') { x *= 10; x += c - '0'; c = getchar_unlocked(); } if (minus) x = -x; } inline void read(std::string &x) { char c; do { c = getchar_unlocked(); } while (c == ' ' || c == '\n'); x.clear(); do { x += c; c = getchar_unlocked(); } while (c != ' ' && c != '\n' && c != EOF); } template <class T> inline void read(std::vector<T> &v) { for (auto &x : v) read(x); } template <class S, class T> inline void read(std::pair<S, T> &p) { read(p.first); read(p.second); } template <class Head, class... Tail> inline void read(Head &head, Tail &...tail) { read(head); read(tail...); } template <class T> inline void write(T x) { char buf[32]; int p = 0; if (x < 0) { x = -x; putchar_unlocked('-'); } if (x == 0) putchar_unlocked('0'); while (x > 0) { buf[p++] = (x % 10) + '0'; x /= 10; } while (p) { putchar_unlocked(buf[--p]); } } inline void write(std::string x) { for (char c : x) putchar_unlocked(c); } inline void write(const char s[]) { for (int i = 0; s[i] != 0; ++i) putchar_unlocked(s[i]); } template <class T> inline void write(std::vector<T> v) { if (v.empty()) return; for (auto itr = v.begin(); itr + 1 != v.end(); ++itr) { write(*itr); write(separator); } write(v.back()); } template <class Head, class... Tail> inline void write(Head head, Tail... tail) { write(head); write(separator); write(tail...); } template <class Head, class... Tail> inline void writeln(Head head, Tail... tail) { write(head, tail...); write("\n"); } void set_separator(std::string s) { separator = s; } } io; struct Prime { int n; vector<int> table; vector<int> primes; Prime(int _n = 100000) { n = _n + 1; table.resize(n, -1); table[0] = 0; table[1] = -1; for (int i = 2; i * i < n; ++i) { if (table[i] == -1) { for (int j = i * i; j < n; j += i) { table[j] = i; } } } } void enumerate_primes() { primes.clear(); for (int i = 2; i < n; ++i) { if (table[i] == -1) primes.push_back(i); } } vector<pair<long long, int>> prime_factor(long long x) { map<long long, int> mp; long long div = 2; int p = 0; while (n <= x && div * div <= x) { if (x % div == 0) { mp[div]++; x /= div; } else { if (p + 1 < primes.size()) { div = primes[++p]; } else { div++; } } } if (x < n) { while (table[x] != -1) { mp[table[x]]++; x /= table[x]; } } if (x > 1) mp[x]++; vector<pair<long long, int>> ret; for (auto p : mp) ret.push_back(p); return ret; } }; template <int MOD = 1000000007> struct Math { vector<long long> fact, factinv, inv; Math(int n = 100000) { fact.resize(n + 1); factinv.resize(n + 1); inv.resize(n + 1); fact[0] = fact[1] = 1; factinv[0] = factinv[1] = 1; inv[1] = 1; for (int i = 2; i <= n; ++i) { fact[i] = fact[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; factinv[i] = factinv[i - 1] * inv[i] % MOD; } } long long C(int n, int r) { if (n < r || n < 0 || r < 0) { return 0; } else { return fact[n] * (factinv[r] * factinv[n - r] % MOD) % MOD; } } long long P(int n, int r) { if (n < r || n < 0 || r < 0) { return 0; } else { return fact[n] * factinv[n - r] % MOD; } } long long H(int n, int r) { return C(n + r - 1, r); } }; struct UnionFind { vector<int> data; vector<vector<int>> groups; UnionFind(int n) : data(n, -1) {} int root(int v) { return data[v] < 0 ? v : data[v] = root(data[v]); } bool unite(int u, int v) { if ((u = root(u)) == (v = root(v))) { return 1; } else { if (-data[u] < -data[v]) swap(u, v); data[u] += data[v]; data[v] = u; return 0; } } int size(int v) { return -data[root(v)]; } void make_groups() { map<int, vector<int>> mp; for (int i = 0; i < data.size(); ++i) mp[root(i)].push_back(i); groups.clear(); for (auto p : mp) groups.push_back(p.second); } }; int main() { int N; cin >> N; vector<int> A(N); REP(i, N) cin >> A[i]; int SZ = 1000001; vector<int> table(SZ); REP(i, N) for (int j = A[i]; j < SZ; j += A[i]) table[j]++; int ans = 0; REP(i, N) if (table[A[i]] <= 1) ans++; cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define REP(i, N) for (int i = 0; i < (int)N; i++) #define FOR(i, a, b) for (int i = a; i < (int)b; i++) #define ALL(x) (x).begin(), (x).end() #define INF (1 << 30) #define LLINF (1LL << 62) #define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__) constexpr int MOD = 1000000007; using ll = long long; using Pii = pair<int, int>; using Pll = pair<ll, ll>; inline int popcount(ll x) { return __builtin_popcountll(x); } inline int div2num(ll x) { return __builtin_ctzll(x); } inline bool bit(ll x, int b) { return (x >> b) & 1; } template <class T> string to_string(T s); template <class S, class T> string to_string(pair<S, T> p); string to_string(string s) { return s; } string to_string(const char s[]) { return to_string(string(s)); } template <class T> string to_string(T v) { if (v.empty()) return "{}"; string ret = "{"; for (auto x : v) ret += to_string(x) + ","; ret.back() = '}'; return ret; } template <class S, class T> string to_string(pair<S, T> p) { return "{" + to_string(p.first) + ":" + to_string(p.second) + "}"; } void debug() { cerr << endl; } template <class Head, class... Tail> void debug(Head head, Tail... tail) { cerr << to_string(head) << " "; debug(tail...); } struct IO { #ifdef _WIN32 inline char getchar_unlocked() { return getchar(); } inline void putchar_unlocked(char c) { putchar(c); } #endif std::string separator = " "; template <class T> inline void read(T &x) { char c; do { c = getchar_unlocked(); } while (c != '-' && (c < '0' || '9' < c)); bool minus = 0; if (c == '-') { minus = 1; c = getchar_unlocked(); } x = 0; while ('0' <= c && c <= '9') { x *= 10; x += c - '0'; c = getchar_unlocked(); } if (minus) x = -x; } inline void read(std::string &x) { char c; do { c = getchar_unlocked(); } while (c == ' ' || c == '\n'); x.clear(); do { x += c; c = getchar_unlocked(); } while (c != ' ' && c != '\n' && c != EOF); } template <class T> inline void read(std::vector<T> &v) { for (auto &x : v) read(x); } template <class S, class T> inline void read(std::pair<S, T> &p) { read(p.first); read(p.second); } template <class Head, class... Tail> inline void read(Head &head, Tail &...tail) { read(head); read(tail...); } template <class T> inline void write(T x) { char buf[32]; int p = 0; if (x < 0) { x = -x; putchar_unlocked('-'); } if (x == 0) putchar_unlocked('0'); while (x > 0) { buf[p++] = (x % 10) + '0'; x /= 10; } while (p) { putchar_unlocked(buf[--p]); } } inline void write(std::string x) { for (char c : x) putchar_unlocked(c); } inline void write(const char s[]) { for (int i = 0; s[i] != 0; ++i) putchar_unlocked(s[i]); } template <class T> inline void write(std::vector<T> v) { if (v.empty()) return; for (auto itr = v.begin(); itr + 1 != v.end(); ++itr) { write(*itr); write(separator); } write(v.back()); } template <class Head, class... Tail> inline void write(Head head, Tail... tail) { write(head); write(separator); write(tail...); } template <class Head, class... Tail> inline void writeln(Head head, Tail... tail) { write(head, tail...); write("\n"); } void set_separator(std::string s) { separator = s; } } io; struct Prime { int n; vector<int> table; vector<int> primes; Prime(int _n = 100000) { n = _n + 1; table.resize(n, -1); table[0] = 0; table[1] = -1; for (int i = 2; i * i < n; ++i) { if (table[i] == -1) { for (int j = i * i; j < n; j += i) { table[j] = i; } } } } void enumerate_primes() { primes.clear(); for (int i = 2; i < n; ++i) { if (table[i] == -1) primes.push_back(i); } } vector<pair<long long, int>> prime_factor(long long x) { map<long long, int> mp; long long div = 2; int p = 0; while (n <= x && div * div <= x) { if (x % div == 0) { mp[div]++; x /= div; } else { if (p + 1 < primes.size()) { div = primes[++p]; } else { div++; } } } if (x < n) { while (table[x] != -1) { mp[table[x]]++; x /= table[x]; } } if (x > 1) mp[x]++; vector<pair<long long, int>> ret; for (auto p : mp) ret.push_back(p); return ret; } }; template <int MOD = 1000000007> struct Math { vector<long long> fact, factinv, inv; Math(int n = 100000) { fact.resize(n + 1); factinv.resize(n + 1); inv.resize(n + 1); fact[0] = fact[1] = 1; factinv[0] = factinv[1] = 1; inv[1] = 1; for (int i = 2; i <= n; ++i) { fact[i] = fact[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; factinv[i] = factinv[i - 1] * inv[i] % MOD; } } long long C(int n, int r) { if (n < r || n < 0 || r < 0) { return 0; } else { return fact[n] * (factinv[r] * factinv[n - r] % MOD) % MOD; } } long long P(int n, int r) { if (n < r || n < 0 || r < 0) { return 0; } else { return fact[n] * factinv[n - r] % MOD; } } long long H(int n, int r) { return C(n + r - 1, r); } }; struct UnionFind { vector<int> data; vector<vector<int>> groups; UnionFind(int n) : data(n, -1) {} int root(int v) { return data[v] < 0 ? v : data[v] = root(data[v]); } bool unite(int u, int v) { if ((u = root(u)) == (v = root(v))) { return 1; } else { if (-data[u] < -data[v]) swap(u, v); data[u] += data[v]; data[v] = u; return 0; } } int size(int v) { return -data[root(v)]; } void make_groups() { map<int, vector<int>> mp; for (int i = 0; i < data.size(); ++i) mp[root(i)].push_back(i); groups.clear(); for (auto p : mp) groups.push_back(p.second); } }; int main() { int N; cin >> N; vector<int> A(N); REP(i, N) cin >> A[i]; int SZ = 1000001; vector<int> table(SZ); REP(i, N) if (table[A[i]] < 2) for (int j = A[i]; j < SZ; j += A[i]) table[j]++; int ans = 0; REP(i, N) if (table[A[i]] <= 1) ans++; cout << ans << endl; return 0; }
replace
280
282
280
283
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #define debug(...) __VA_ARGS__ #else #define endl '\n' #define debug(...) #endif #define debugf(...) debug(printf(__VA_ARGS__)) const int N = 2e5 + 5; int a[N]; int f[N], F[N]; int(((((main)))))() <% ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; f[a[i]]++; } for (int x = 1; x < N; x++) { for (int y = x; y < N; y += x) { F[y] += f[x]; } } int ans = 0; for (int i = 0; i < n; i++) { int x = a[i]; if (F[x] == 1) ans++; } cout << ans << endl; return 0; %>
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #define debug(...) __VA_ARGS__ #else #define endl '\n' #define debug(...) #endif #define debugf(...) debug(printf(__VA_ARGS__)) const int N = 1e6 + 5; int a[N]; int f[N], F[N]; int(((((main)))))() <% ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; f[a[i]]++; } for (int x = 1; x < N; x++) { for (int y = x; y < N; y += x) { F[y] += f[x]; } } int ans = 0; for (int i = 0; i < n; i++) { int x = a[i]; if (F[x] == 1) ans++; } cout << ans << endl; return 0; %>
replace
11
12
11
12
0
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, a) for (int i = 0; i < (a); i++) typedef long long ll; template <typename T> struct edge { int src, to; T cost; edge(int to, T cost) : src(-1), to(to), cost(cost) {} edge(int src, int to, T cost) : src(src), to(to), cost(cost) {} edge &operator=(const int &x) { to = x; return *this; } operator int() const { return to; } }; template <typename T> using Edges = vector<edge<T>>; template <typename T> using WeightedGraph = vector<Edges<T>>; using UnWeightedGraph = vector<vector<int>>; template <typename T> using Matrix = vector<vector<T>>; ///////////////////////////////////////////////////////////////////// const ll inf = 1LL << 60; const ll MAXN = 200010; int main() { ll n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; map<ll, ll> mp; rep(i, n) { mp[a[i]]++; } vector<ll> d(MAXN); for (auto v : mp) { for (int i = 1; i * v.first < MAXN; i++) { d[i * v.first] += v.second; } } ll ans = 0; rep(i, n) { if (d[a[i]] < 2) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a) for (int i = 0; i < (a); i++) typedef long long ll; template <typename T> struct edge { int src, to; T cost; edge(int to, T cost) : src(-1), to(to), cost(cost) {} edge(int src, int to, T cost) : src(src), to(to), cost(cost) {} edge &operator=(const int &x) { to = x; return *this; } operator int() const { return to; } }; template <typename T> using Edges = vector<edge<T>>; template <typename T> using WeightedGraph = vector<Edges<T>>; using UnWeightedGraph = vector<vector<int>>; template <typename T> using Matrix = vector<vector<T>>; ///////////////////////////////////////////////////////////////////// const ll inf = 1LL << 60; const ll MAXN = 1000010; int main() { ll n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; map<ll, ll> mp; rep(i, n) { mp[a[i]]++; } vector<ll> d(MAXN); for (auto v : mp) { for (int i = 1; i * v.first < MAXN; i++) { d[i * v.first] += v.second; } } ll ans = 0; rep(i, n) { if (d[a[i]] < 2) ans++; } cout << ans << endl; return 0; }
replace
23
24
23
24
0
p02642
C++
Time Limit Exceeded
// #pragma GCC optimize ("-O3") #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <type_traits> #include <typeinfo> #include <unordered_map> #include <vector> #ifdef _MSC_VER #include <intrin.h> #define popcnt __popcnt64 // # define __builtin_popcount __popcnt #else #define popcnt __builtin_popcountll #endif // #include "boost/variant.hpp" using namespace std; typedef long long ll; constexpr ll MOD = 1000000007LL; constexpr ll INF = 1LL << 60; #define rep(i, N, M) for (ll i = N, i##_len = (M); i < i##_len; ++i) #define rep_skip(i, N, M, ...) \ for (ll i = N, i##_len = (M); i < i##_len; i += (skip)) #define rrep(i, N, M) for (ll i = (M)-1, i##_len = (N - 1); i > i##_len; --i) #define repbit(bit, N, DIG) rep(bit, (N), (1LL << (DIG))) #define pb push_back #define fir first #define sec second #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define perm(c) \ sort(all(c)); \ for (bool c##perm = 1; c##perm; \ c##perm = next_permutation( \ all(c))) // perm(c){write(c)} writes all permutation of c constexpr ll dceil(ll x, ll y) { if (y < 0) { x *= -1; y *= -1; }; return x > 0 ? (x + y - 1) / y : x / y; } // ceil for x/y constexpr ll dfloor(ll x, ll y) { if (y < 0) { x *= -1; y *= -1; }; return x > 0 ? x / y : -dceil((-x), y); } // floor for x/y typedef pair<double, double> pd; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<pll> vpll; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<string> vs; template <typename T> using pq_greater = priority_queue<T, vector<T>, greater<T>>; template <typename T> using vpt = vector<complex<T>>; template <int n> struct tll_impl { using type = decltype(tuple_cat(tuple<ll>(), declval<typename tll_impl<n - 1>::type>())); }; template <> struct tll_impl<1> { using type = tuple<ll>; }; template <int n> using tll = typename tll_impl<n>::type; template <class T> constexpr ll SZ(T &v) { return static_cast<ll>(v.size()); }; template <int n, typename T> struct vec_t_impl { using type = vector<typename vec_t_impl<n - 1, T>::type>; }; template <typename T> struct vec_t_impl<1, T> { using type = vector<T>; }; template <int n, typename T> using vec_t = typename vec_t_impl<n, T>::type; // check static_assert(is_same<vec_t<3, ll>, vector<vector<vector<ll>>>>::value, ""); // decompose vector into basetype and dimension. template <typename T> struct vec_dec { static constexpr int dim = 0; using type = T; }; template <typename T> struct vec_dec<vector<T>> { static constexpr int dim = vec_dec<T>::dim + 1; using type = typename vec_dec<T>::type; }; static_assert(is_same<typename vec_dec<vec_t<3, ll>>::type, ll>::value, ""); static_assert(vec_dec<vec_t<3, ll>>::dim == 3, ""); template <typename T = ll> vector<T> makev(size_t a) { return vector<T>(a); } template <typename T = ll, typename... Ts> auto makev(size_t a, Ts... ts) { return vector<decltype(makev<T>(ts...))>(a, makev<T>(ts...)); } // ex: auto dp = makev<ll>(4,5) => vector<vector<ll>> dp(4,vector<ll>(5)); template <typename T> struct is_vector : std::false_type {}; // check if T is vector template <typename T> struct is_vector<vector<T>> : std::true_type {}; static_assert(is_vector<vector<ll>>::value == true && is_vector<ll>::value == false, ""); // check if T is vector template <typename T> struct is_pair : std::false_type {}; template <typename T, typename S> struct is_pair<pair<T, S>> : std::true_type {}; static_assert(is_pair<pll>::value == true && is_pair<ll>::value == false, ""); template <typename T, typename V, typename enable_if<!is_vector<T>::value, nullptr_t>::type = nullptr> void fill_v(T &t, const V &v) { t = v; } template <typename T, typename V, typename enable_if<is_vector<T>::value, nullptr_t>::type = nullptr> void fill_v(T &t, const V &v) { for (auto &&x : t) fill_v(x, v); } // ex: fill_v(dp, INF); namespace std { template <class T> bool operator<(const complex<T> &a, const complex<T> &b) { return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real(); } }; // namespace std template <typename T, typename S> istream &operator>>(istream &istr, pair<T, S> &x) { return istr >> x.first >> x.second; } template <typename T> istream &operator>>(istream &istr, vector<T> &x) { rep(i, 0, x.size()) istr >> x[i]; return istr; } template <typename T> istream &operator>>(istream &istr, complex<T> &x) { T r, i; istr >> r >> i; x.real(r); x.imag(i); return istr; } template <typename T, typename Delim_t = string, typename enable_if<!is_vector<T>::value, nullptr_t>::type = nullptr> void write(T &x, Delim_t delim = " ") { cout << x << delim; } template <typename T, typename Delim_t = string, typename enable_if<is_vector<T>::value, nullptr_t>::type = nullptr> void write(T &x, Delim_t delim = " ") { rep(i, 0, x.size()) write(x[i], (i == (x.size() - 1) ? "" : delim)); cout << '\n'; } template <typename T> void chmin(T &a, T b) { if (a > b) a = b; } template <typename T> void chmax(T &a, T b) { if (a < b) a = b; } vll seq(ll i, ll j) { vll res(j - i); rep(k, i, j) res[k] = i + k; return res; } constexpr ll POW_0(ll x, ll y) { if (y == 0) return 1; if (y == 1) return x; if (y == 2) return x * x; if (y % 2 == 0) return POW_0(POW_0(x, y / 2), 2LL); return ((POW_0(POW_0(x, y / 2), 2LL)) * (x)); } constexpr ll POW(ll x, ll y, ll mod = 0) { if (mod == 0) return POW_0(x, y); if (y == 0) return 1; if (y == 1) return x % mod; if (y == 2) return x * x % mod; if (y % 2 == 0) return POW(POW(x, y / 2, mod), 2LL, mod) % mod; return ((POW(POW(x, y / 2, mod), 2LL, mod)) * (x % mod)) % mod; } template <typename Inputs, typename Functor, typename T = typename Inputs::value_type> void sort_by(Inputs &inputs, Functor f) { std::sort(std::begin(inputs), std::end(inputs), [&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); }); } template <int pos, typename Inputs, typename T = typename Inputs::value_type> void sort_by(Inputs &inputs) { std::sort( std::begin(inputs), std::end(inputs), [](const T &lhs, const T &rhs) { return get<pos>(lhs) < get<pos>(rhs); }); } template <typename Inputs, typename Functor, typename T = typename Inputs::value_type> void stable_sort_by(Inputs &inputs, Functor f) { std::stable_sort( std::begin(inputs), std::end(inputs), [&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); }); } template <typename Inputs> void sort_uniq(Inputs &inputs) { sort(all(inputs)); inputs.erase(unique(all(inputs)), inputs.end()); } vector<string> split(const string &s, char delim) { vector<string> elems; stringstream ss(s); string item; if (s.size() > 0 && s.front() == delim) { elems.push_back(""); } while (getline(ss, item, delim)) { if (!item.empty()) { elems.push_back(item); } } if (s.size() > 0 && s.back() == delim) { elems.push_back(""); } return elems; } template <class T> map<T, ll> inv_map(vector<T> &x) { map<T, ll> res; rep(i, 0, x.size()) { res[x[i]] = i; } return res; } template <class K, class V> map<V, K> inv_map(map<K, V> &m) { map<V, K> res; for (const auto &x : m) { res[x.second] = x.first; } return res; } template <class T, class val_t = typename T::value_type, enable_if_t<!is_same<T, set<val_t>>::value> * = nullptr> constexpr bool exist(const T &container, val_t val) { return find(all(container), val) != container.end(); } template <class T, class val_t = typename T::value_type, enable_if_t<is_same<T, set<val_t>>::value> * = nullptr> constexpr bool exist(const T &container, val_t val) { return container.find(val) != container.end(); } // inner prod: |a||b|cos(theta) template <class T> T dot(complex<T> a, complex<T> b) { return a.real() * b.real() + a.imag() * b.imag(); } // outer prod |a||b|sin(theta) template <class T> T cross(complex<T> a, complex<T> b) { return a.real() * b.imag() - a.imag() * b.real(); } ll div_ferm(ll val, ll b, ll mod) { return (val * POW(b, mod - 2, mod)) % mod; } // === Modint === // static uint_fast64_t runtime_modulus = MOD; template <ll modulus = MOD> class modint { public: ll val; constexpr modint() : val(0) {} constexpr modint(ll x) : val((x %= mod()) < 0 ? x + mod() : x) {} constexpr modint(ll x, ll modulus_) { set_modulo(modulus_); val = (x %= mod()) < 0 ? x + mod() : x; } template <class Ret = ll &> static auto modulo() -> std::enable_if_t<(modulus <= 0), Ret> { static ll runtime_modulus = numeric_limits<ll>::max(); return runtime_modulus; // singleton technique } template <class Ret = const ll> static auto mod() -> std::enable_if_t<(modulus <= 0), Ret> { return modulo(); } template <class Ret = const ll> static constexpr auto mod() -> std::enable_if_t<(modulus > 0), Ret> { return modulus; } template <ll modulus_ = modulus, enable_if_t<(modulus_ <= 0), nullptr_t> = nullptr> static void set_modulo(ll mod) { modulo() = mod; } void reset_modulo(ll modulus_) { modulo() = modulus_; val %= mod(); } constexpr modint inv() { return pow(mod() - 2); } constexpr ll value() const noexcept { return val; } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } modint &operator+=(const modint rhs) noexcept { val += rhs.val; if (val >= mod()) { val -= mod(); } return *this; } modint &operator-=(const modint rhs) noexcept { if (val < rhs.val) { val += mod(); } val -= rhs.val; return *this; } modint &operator*=(const modint rhs) noexcept { val = val * rhs.val % mod(); return *this; } modint &operator/=(modint rhs) noexcept { ll exp = mod() - 2; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } modint &operator++() noexcept { return *this += modint(1); } modint operator++(int) noexcept { modint t = *this; *this += modint(1); return t; } modint &operator--() noexcept { return *this -= modint(1); } modint operator--(int) noexcept { modint t = *this; *this -= modint(1); return t; } constexpr modint operator-() { return val ? mod() - val : val; } constexpr bool operator==(const modint rhs) const noexcept { return val == rhs.value(); } constexpr bool operator!=(const modint rhs) const noexcept { return val != rhs.value(); } constexpr bool operator<(const modint rhs) const noexcept { return val < rhs.value(); } static constexpr modint zero() { return modint(0); } static constexpr modint unit() { return modint(1); } modint pow(long long k) const { modint v = *this; modint res(1), tmp(v); while (k) { if (k & 1) res *= tmp; tmp *= tmp; k >>= 1; } return res; } ll log(modint b) { modint val = *this; const ll sq = 40000; map<modint, ll> dp; // dp.reserve(sq); modint res(1); for (ll r = 0; r < sq; r++) { if (!dp.count(res)) dp[res] = r; res *= val; } modint p = val.inv().pow(sq); res = b; for (ll q = 0; q <= mod() / sq + 1; q++) { if (dp.count(res)) { ll idx = q * sq + dp[res]; if (idx > 0) return idx; } res *= p; } return INF; } friend ostream &operator<<(ostream &o, const modint<modulus> &t) { o << t.value(); return o; } friend istream &operator>>(istream &in, modint<modulus> &t) { ll x; in >> x; t = modint<modulus>(x); return in; } friend modint<modulus> POW(modint<modulus> x, ll n) { return modint<modulus>(POW(x.value(), n, mod())); } }; // user defined literal modint<MOD> operator"" _mod(unsigned long long x) { return modint<MOD>(x); } template <class T = modint<>> class Combination { // this calculates combination (nCk). // Constructor runs in O(MAX). // get(n,k) returns nCk in O(1). ll N_MAX; vector<T> fac, finv; public: Combination(ll N_MAX = 210000) : N_MAX(N_MAX), fac(N_MAX), finv(N_MAX) { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; pre_process(2, N_MAX); } T operator()(ll n, ll k) { // choose k from n if (N_MAX < n) pre_process(N_MAX, n); if (0 <= n && n < k) return 0; if (k == 0) return 1; if (n < 0) return operator()(-n + k - 1, k) * (k % 2 ? -1 : 0); return fac[n] * (finv[k] * finv[n - k]); } T H(ll n, ll k) { // 1) 区間[0, k) を(空を許して)n個に分割する場合の数 // 2) n個の中からk個を重複を許して選ぶ return operator()(n + k - 1, k); } T P(ll n, ll k) { // n (n-1) ... (n-k+1) if (N_MAX < n) pre_process(N_MAX, n); return (n < k || n < 0) ? T(0) : fac[n] * finv[n - k]; } T Fac(ll n) { return P(n, n); } T FacInv(ll n) { if (N_MAX < n) pre_process(N_MAX, n); return n < 0 ? T(0) : finv[n]; } private: void pre_process(ll m, ll n) { if (N_MAX < n) { fac.resize(n); finv.resize(n); } rep(i, m, n) { fac[i] = fac[i - 1] * i; finv[i] = finv[i - 1] / i; } } }; ll choose(int n, int r) { // O(r) for small n ll acc = 1; rep(i, 0, r) acc = acc * (n - i) / (i + 1); return acc; } ll gcd(ll val, ll b) { if (val < 0) val *= -1; if (b < 0) b *= -1; if (val == 0) return b; if (b == 0) return val; if (val % b == 0) return b; else return gcd(b, val % b); } vll divisor(ll n) { // returns common divisors in O(sqrt(min(n,m))) vll res; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { res.push_back(i); res.push_back(n / i); } if (i * i == n) res.push_back(i); } sort(res.begin(), res.end()); return res; } vll divisor(ll n, ll m) { // returns common divisors in O(sqrt(min(n,m))) if (n > m) swap(n, m); vll res; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { if (m % i == 0) res.push_back(i); if (m % (n / i) == 0) res.push_back(n / i); } if (i * i == n && m % i == 0) res.push_back(i); } sort(res.begin(), res.end()); return res; } vpll prime_factorize(ll n) { // returns prime factorization of n in O(sprt(n)) vector<pll> res; for (ll p = 2; p * p <= n; ++p) { if (n % p != 0) continue; ll num = 0; while (n % p == 0) { ++num; n /= p; } res.push_back({p, num}); } if (n != 1) res.push_back(make_pair(n, 1)); return res; } ll eulers_phi(ll n) { // returns the number of coprime integers in O(sqrt(n) + n^(1.4/log log n)) [ // the number of prime divisors <= O(log(n^(1.4/log log n) ) ] ll res = 0; auto primes = prime_factorize(n); ll psize = primes.size(); rep(bit, 1, 1LL << psize) { ll bitsize = popcnt(bit); ll arg = (bitsize % 2 ? 1 : -1); ll base = 1; rep(i, 0, primes.size()) { ll p = primes[i].first; if (bit & (1LL << i)) base *= p; } res += arg * (n / base); } return n - res; } // ビット bit に i 番目のフラグが立っているかどうか if (bit & (1 << i)) // ビット bit に i 番目のフラグが消えているかどうか if (!(bit & (1 << i))) // ビット bit に i 番目のフラグを立てる bit| = (1 << i) // ビット bit に i 番目のフラグを消す bit &= ~(1 << i) // ビット bit に何個のフラグが立っているか __builtin_popcount(bit) // ビット bit に i 番目のフラグを立てたもの bit|(1 << i) // ビット bit に i 番目のフラグを消したもの bit & ~(1 << i) template <ll bit = 2LL> ll at_bit(ll n, ll i) { return n / POW(bit, i) % bit; } template <> ll at_bit<2>(ll n, ll i) { return (n >> i) % 2LL; } template <ll bit> ll get_bit(ll i) { return POW(bit, i); } template <> ll get_bit<2>(ll i) { return 1LL << i; } template <ll bit = 2> ll get_max_bit(ll n) { ll tmp = bit; ll at = 0; while (tmp <= n) { at++; tmp *= bit; } return at; } template <> ll get_max_bit<2>(ll n) { ll tmp = 2; ll at = 0; while (tmp <= n) { at++; tmp <<= 1; } return at; } ll check_bit(ll N, int POS) { return (N & (1LL << POS)); } // Function to return maximum XOR subset in set by gaussian elimination ll max_subset_xor(vector<ll> &v) { int n = v.size(); int ind = 0; // Array index for (int bit = 61; bit >= 0; bit--) { int x = ind; while (x < n && check_bit(v[x], bit) == 0) x++; if (x == n) continue; // skip if there is no number below ind where current bit is 1 swap(v[ind], v[x]); for (int j = 0; j < n; j++) { if (j != ind && check_bit(v[j], bit)) v[j] ^= v[ind]; } ind++; } return accumulate(all(v), 0LL, [](ll x, ll y) { return x ^ y; }); } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); ll n; cin >> n; vll a(n); cin >> a; sort(all(a)); ll mx = POW(10, 6) + 10; vll visited(mx, 0); ll res = 0; rep(i, 0, n) { if (visited[a[i]] || ((i < n - 1) && (a[i] == a[i + 1]))) { res++; } for (ll j = a[i]; j < mx; j += a[i]) { visited[j] = 1; } } cout << n - res << endl; return 0; }
// #pragma GCC optimize ("-O3") #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <type_traits> #include <typeinfo> #include <unordered_map> #include <vector> #ifdef _MSC_VER #include <intrin.h> #define popcnt __popcnt64 // # define __builtin_popcount __popcnt #else #define popcnt __builtin_popcountll #endif // #include "boost/variant.hpp" using namespace std; typedef long long ll; constexpr ll MOD = 1000000007LL; constexpr ll INF = 1LL << 60; #define rep(i, N, M) for (ll i = N, i##_len = (M); i < i##_len; ++i) #define rep_skip(i, N, M, ...) \ for (ll i = N, i##_len = (M); i < i##_len; i += (skip)) #define rrep(i, N, M) for (ll i = (M)-1, i##_len = (N - 1); i > i##_len; --i) #define repbit(bit, N, DIG) rep(bit, (N), (1LL << (DIG))) #define pb push_back #define fir first #define sec second #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define perm(c) \ sort(all(c)); \ for (bool c##perm = 1; c##perm; \ c##perm = next_permutation( \ all(c))) // perm(c){write(c)} writes all permutation of c constexpr ll dceil(ll x, ll y) { if (y < 0) { x *= -1; y *= -1; }; return x > 0 ? (x + y - 1) / y : x / y; } // ceil for x/y constexpr ll dfloor(ll x, ll y) { if (y < 0) { x *= -1; y *= -1; }; return x > 0 ? x / y : -dceil((-x), y); } // floor for x/y typedef pair<double, double> pd; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<pll> vpll; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<string> vs; template <typename T> using pq_greater = priority_queue<T, vector<T>, greater<T>>; template <typename T> using vpt = vector<complex<T>>; template <int n> struct tll_impl { using type = decltype(tuple_cat(tuple<ll>(), declval<typename tll_impl<n - 1>::type>())); }; template <> struct tll_impl<1> { using type = tuple<ll>; }; template <int n> using tll = typename tll_impl<n>::type; template <class T> constexpr ll SZ(T &v) { return static_cast<ll>(v.size()); }; template <int n, typename T> struct vec_t_impl { using type = vector<typename vec_t_impl<n - 1, T>::type>; }; template <typename T> struct vec_t_impl<1, T> { using type = vector<T>; }; template <int n, typename T> using vec_t = typename vec_t_impl<n, T>::type; // check static_assert(is_same<vec_t<3, ll>, vector<vector<vector<ll>>>>::value, ""); // decompose vector into basetype and dimension. template <typename T> struct vec_dec { static constexpr int dim = 0; using type = T; }; template <typename T> struct vec_dec<vector<T>> { static constexpr int dim = vec_dec<T>::dim + 1; using type = typename vec_dec<T>::type; }; static_assert(is_same<typename vec_dec<vec_t<3, ll>>::type, ll>::value, ""); static_assert(vec_dec<vec_t<3, ll>>::dim == 3, ""); template <typename T = ll> vector<T> makev(size_t a) { return vector<T>(a); } template <typename T = ll, typename... Ts> auto makev(size_t a, Ts... ts) { return vector<decltype(makev<T>(ts...))>(a, makev<T>(ts...)); } // ex: auto dp = makev<ll>(4,5) => vector<vector<ll>> dp(4,vector<ll>(5)); template <typename T> struct is_vector : std::false_type {}; // check if T is vector template <typename T> struct is_vector<vector<T>> : std::true_type {}; static_assert(is_vector<vector<ll>>::value == true && is_vector<ll>::value == false, ""); // check if T is vector template <typename T> struct is_pair : std::false_type {}; template <typename T, typename S> struct is_pair<pair<T, S>> : std::true_type {}; static_assert(is_pair<pll>::value == true && is_pair<ll>::value == false, ""); template <typename T, typename V, typename enable_if<!is_vector<T>::value, nullptr_t>::type = nullptr> void fill_v(T &t, const V &v) { t = v; } template <typename T, typename V, typename enable_if<is_vector<T>::value, nullptr_t>::type = nullptr> void fill_v(T &t, const V &v) { for (auto &&x : t) fill_v(x, v); } // ex: fill_v(dp, INF); namespace std { template <class T> bool operator<(const complex<T> &a, const complex<T> &b) { return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real(); } }; // namespace std template <typename T, typename S> istream &operator>>(istream &istr, pair<T, S> &x) { return istr >> x.first >> x.second; } template <typename T> istream &operator>>(istream &istr, vector<T> &x) { rep(i, 0, x.size()) istr >> x[i]; return istr; } template <typename T> istream &operator>>(istream &istr, complex<T> &x) { T r, i; istr >> r >> i; x.real(r); x.imag(i); return istr; } template <typename T, typename Delim_t = string, typename enable_if<!is_vector<T>::value, nullptr_t>::type = nullptr> void write(T &x, Delim_t delim = " ") { cout << x << delim; } template <typename T, typename Delim_t = string, typename enable_if<is_vector<T>::value, nullptr_t>::type = nullptr> void write(T &x, Delim_t delim = " ") { rep(i, 0, x.size()) write(x[i], (i == (x.size() - 1) ? "" : delim)); cout << '\n'; } template <typename T> void chmin(T &a, T b) { if (a > b) a = b; } template <typename T> void chmax(T &a, T b) { if (a < b) a = b; } vll seq(ll i, ll j) { vll res(j - i); rep(k, i, j) res[k] = i + k; return res; } constexpr ll POW_0(ll x, ll y) { if (y == 0) return 1; if (y == 1) return x; if (y == 2) return x * x; if (y % 2 == 0) return POW_0(POW_0(x, y / 2), 2LL); return ((POW_0(POW_0(x, y / 2), 2LL)) * (x)); } constexpr ll POW(ll x, ll y, ll mod = 0) { if (mod == 0) return POW_0(x, y); if (y == 0) return 1; if (y == 1) return x % mod; if (y == 2) return x * x % mod; if (y % 2 == 0) return POW(POW(x, y / 2, mod), 2LL, mod) % mod; return ((POW(POW(x, y / 2, mod), 2LL, mod)) * (x % mod)) % mod; } template <typename Inputs, typename Functor, typename T = typename Inputs::value_type> void sort_by(Inputs &inputs, Functor f) { std::sort(std::begin(inputs), std::end(inputs), [&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); }); } template <int pos, typename Inputs, typename T = typename Inputs::value_type> void sort_by(Inputs &inputs) { std::sort( std::begin(inputs), std::end(inputs), [](const T &lhs, const T &rhs) { return get<pos>(lhs) < get<pos>(rhs); }); } template <typename Inputs, typename Functor, typename T = typename Inputs::value_type> void stable_sort_by(Inputs &inputs, Functor f) { std::stable_sort( std::begin(inputs), std::end(inputs), [&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); }); } template <typename Inputs> void sort_uniq(Inputs &inputs) { sort(all(inputs)); inputs.erase(unique(all(inputs)), inputs.end()); } vector<string> split(const string &s, char delim) { vector<string> elems; stringstream ss(s); string item; if (s.size() > 0 && s.front() == delim) { elems.push_back(""); } while (getline(ss, item, delim)) { if (!item.empty()) { elems.push_back(item); } } if (s.size() > 0 && s.back() == delim) { elems.push_back(""); } return elems; } template <class T> map<T, ll> inv_map(vector<T> &x) { map<T, ll> res; rep(i, 0, x.size()) { res[x[i]] = i; } return res; } template <class K, class V> map<V, K> inv_map(map<K, V> &m) { map<V, K> res; for (const auto &x : m) { res[x.second] = x.first; } return res; } template <class T, class val_t = typename T::value_type, enable_if_t<!is_same<T, set<val_t>>::value> * = nullptr> constexpr bool exist(const T &container, val_t val) { return find(all(container), val) != container.end(); } template <class T, class val_t = typename T::value_type, enable_if_t<is_same<T, set<val_t>>::value> * = nullptr> constexpr bool exist(const T &container, val_t val) { return container.find(val) != container.end(); } // inner prod: |a||b|cos(theta) template <class T> T dot(complex<T> a, complex<T> b) { return a.real() * b.real() + a.imag() * b.imag(); } // outer prod |a||b|sin(theta) template <class T> T cross(complex<T> a, complex<T> b) { return a.real() * b.imag() - a.imag() * b.real(); } ll div_ferm(ll val, ll b, ll mod) { return (val * POW(b, mod - 2, mod)) % mod; } // === Modint === // static uint_fast64_t runtime_modulus = MOD; template <ll modulus = MOD> class modint { public: ll val; constexpr modint() : val(0) {} constexpr modint(ll x) : val((x %= mod()) < 0 ? x + mod() : x) {} constexpr modint(ll x, ll modulus_) { set_modulo(modulus_); val = (x %= mod()) < 0 ? x + mod() : x; } template <class Ret = ll &> static auto modulo() -> std::enable_if_t<(modulus <= 0), Ret> { static ll runtime_modulus = numeric_limits<ll>::max(); return runtime_modulus; // singleton technique } template <class Ret = const ll> static auto mod() -> std::enable_if_t<(modulus <= 0), Ret> { return modulo(); } template <class Ret = const ll> static constexpr auto mod() -> std::enable_if_t<(modulus > 0), Ret> { return modulus; } template <ll modulus_ = modulus, enable_if_t<(modulus_ <= 0), nullptr_t> = nullptr> static void set_modulo(ll mod) { modulo() = mod; } void reset_modulo(ll modulus_) { modulo() = modulus_; val %= mod(); } constexpr modint inv() { return pow(mod() - 2); } constexpr ll value() const noexcept { return val; } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } modint &operator+=(const modint rhs) noexcept { val += rhs.val; if (val >= mod()) { val -= mod(); } return *this; } modint &operator-=(const modint rhs) noexcept { if (val < rhs.val) { val += mod(); } val -= rhs.val; return *this; } modint &operator*=(const modint rhs) noexcept { val = val * rhs.val % mod(); return *this; } modint &operator/=(modint rhs) noexcept { ll exp = mod() - 2; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } modint &operator++() noexcept { return *this += modint(1); } modint operator++(int) noexcept { modint t = *this; *this += modint(1); return t; } modint &operator--() noexcept { return *this -= modint(1); } modint operator--(int) noexcept { modint t = *this; *this -= modint(1); return t; } constexpr modint operator-() { return val ? mod() - val : val; } constexpr bool operator==(const modint rhs) const noexcept { return val == rhs.value(); } constexpr bool operator!=(const modint rhs) const noexcept { return val != rhs.value(); } constexpr bool operator<(const modint rhs) const noexcept { return val < rhs.value(); } static constexpr modint zero() { return modint(0); } static constexpr modint unit() { return modint(1); } modint pow(long long k) const { modint v = *this; modint res(1), tmp(v); while (k) { if (k & 1) res *= tmp; tmp *= tmp; k >>= 1; } return res; } ll log(modint b) { modint val = *this; const ll sq = 40000; map<modint, ll> dp; // dp.reserve(sq); modint res(1); for (ll r = 0; r < sq; r++) { if (!dp.count(res)) dp[res] = r; res *= val; } modint p = val.inv().pow(sq); res = b; for (ll q = 0; q <= mod() / sq + 1; q++) { if (dp.count(res)) { ll idx = q * sq + dp[res]; if (idx > 0) return idx; } res *= p; } return INF; } friend ostream &operator<<(ostream &o, const modint<modulus> &t) { o << t.value(); return o; } friend istream &operator>>(istream &in, modint<modulus> &t) { ll x; in >> x; t = modint<modulus>(x); return in; } friend modint<modulus> POW(modint<modulus> x, ll n) { return modint<modulus>(POW(x.value(), n, mod())); } }; // user defined literal modint<MOD> operator"" _mod(unsigned long long x) { return modint<MOD>(x); } template <class T = modint<>> class Combination { // this calculates combination (nCk). // Constructor runs in O(MAX). // get(n,k) returns nCk in O(1). ll N_MAX; vector<T> fac, finv; public: Combination(ll N_MAX = 210000) : N_MAX(N_MAX), fac(N_MAX), finv(N_MAX) { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; pre_process(2, N_MAX); } T operator()(ll n, ll k) { // choose k from n if (N_MAX < n) pre_process(N_MAX, n); if (0 <= n && n < k) return 0; if (k == 0) return 1; if (n < 0) return operator()(-n + k - 1, k) * (k % 2 ? -1 : 0); return fac[n] * (finv[k] * finv[n - k]); } T H(ll n, ll k) { // 1) 区間[0, k) を(空を許して)n個に分割する場合の数 // 2) n個の中からk個を重複を許して選ぶ return operator()(n + k - 1, k); } T P(ll n, ll k) { // n (n-1) ... (n-k+1) if (N_MAX < n) pre_process(N_MAX, n); return (n < k || n < 0) ? T(0) : fac[n] * finv[n - k]; } T Fac(ll n) { return P(n, n); } T FacInv(ll n) { if (N_MAX < n) pre_process(N_MAX, n); return n < 0 ? T(0) : finv[n]; } private: void pre_process(ll m, ll n) { if (N_MAX < n) { fac.resize(n); finv.resize(n); } rep(i, m, n) { fac[i] = fac[i - 1] * i; finv[i] = finv[i - 1] / i; } } }; ll choose(int n, int r) { // O(r) for small n ll acc = 1; rep(i, 0, r) acc = acc * (n - i) / (i + 1); return acc; } ll gcd(ll val, ll b) { if (val < 0) val *= -1; if (b < 0) b *= -1; if (val == 0) return b; if (b == 0) return val; if (val % b == 0) return b; else return gcd(b, val % b); } vll divisor(ll n) { // returns common divisors in O(sqrt(min(n,m))) vll res; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { res.push_back(i); res.push_back(n / i); } if (i * i == n) res.push_back(i); } sort(res.begin(), res.end()); return res; } vll divisor(ll n, ll m) { // returns common divisors in O(sqrt(min(n,m))) if (n > m) swap(n, m); vll res; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { if (m % i == 0) res.push_back(i); if (m % (n / i) == 0) res.push_back(n / i); } if (i * i == n && m % i == 0) res.push_back(i); } sort(res.begin(), res.end()); return res; } vpll prime_factorize(ll n) { // returns prime factorization of n in O(sprt(n)) vector<pll> res; for (ll p = 2; p * p <= n; ++p) { if (n % p != 0) continue; ll num = 0; while (n % p == 0) { ++num; n /= p; } res.push_back({p, num}); } if (n != 1) res.push_back(make_pair(n, 1)); return res; } ll eulers_phi(ll n) { // returns the number of coprime integers in O(sqrt(n) + n^(1.4/log log n)) [ // the number of prime divisors <= O(log(n^(1.4/log log n) ) ] ll res = 0; auto primes = prime_factorize(n); ll psize = primes.size(); rep(bit, 1, 1LL << psize) { ll bitsize = popcnt(bit); ll arg = (bitsize % 2 ? 1 : -1); ll base = 1; rep(i, 0, primes.size()) { ll p = primes[i].first; if (bit & (1LL << i)) base *= p; } res += arg * (n / base); } return n - res; } // ビット bit に i 番目のフラグが立っているかどうか if (bit & (1 << i)) // ビット bit に i 番目のフラグが消えているかどうか if (!(bit & (1 << i))) // ビット bit に i 番目のフラグを立てる bit| = (1 << i) // ビット bit に i 番目のフラグを消す bit &= ~(1 << i) // ビット bit に何個のフラグが立っているか __builtin_popcount(bit) // ビット bit に i 番目のフラグを立てたもの bit|(1 << i) // ビット bit に i 番目のフラグを消したもの bit & ~(1 << i) template <ll bit = 2LL> ll at_bit(ll n, ll i) { return n / POW(bit, i) % bit; } template <> ll at_bit<2>(ll n, ll i) { return (n >> i) % 2LL; } template <ll bit> ll get_bit(ll i) { return POW(bit, i); } template <> ll get_bit<2>(ll i) { return 1LL << i; } template <ll bit = 2> ll get_max_bit(ll n) { ll tmp = bit; ll at = 0; while (tmp <= n) { at++; tmp *= bit; } return at; } template <> ll get_max_bit<2>(ll n) { ll tmp = 2; ll at = 0; while (tmp <= n) { at++; tmp <<= 1; } return at; } ll check_bit(ll N, int POS) { return (N & (1LL << POS)); } // Function to return maximum XOR subset in set by gaussian elimination ll max_subset_xor(vector<ll> &v) { int n = v.size(); int ind = 0; // Array index for (int bit = 61; bit >= 0; bit--) { int x = ind; while (x < n && check_bit(v[x], bit) == 0) x++; if (x == n) continue; // skip if there is no number below ind where current bit is 1 swap(v[ind], v[x]); for (int j = 0; j < n; j++) { if (j != ind && check_bit(v[j], bit)) v[j] ^= v[ind]; } ind++; } return accumulate(all(v), 0LL, [](ll x, ll y) { return x ^ y; }); } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); ll n; cin >> n; vll a(n); cin >> a; sort(all(a)); ll mx = POW(10, 6) + 10; vll visited(mx, 0); ll res = 0; rep(i, 0, n) { if (visited[a[i]] || ((i < n - 1) && (a[i] == a[i + 1]))) { res++; } if (!((i > 0) && (a[i - 1] == a[i]))) { for (ll j = a[i]; j < mx; j += a[i]) { visited[j] = 1; } } } cout << n - res << endl; return 0; }
replace
685
687
685
689
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> V(N); for (int a = 0; a < N; a++) cin >> V.at(a); vector<int> W(1000000, 0); for (int i = 0; i < N; i++) { for (int i2 = 1; i2 * V.at(i) <= 1000000; i2++) W.at(i2 * V.at(i) - 1)++; } int ans = 0; for (int j = 0; j < N; j++) { if (W.at(V.at(j) - 1) == 1) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> V(N); for (int a = 0; a < N; a++) cin >> V.at(a); vector<int> W(1000000, 0); for (int i = 0; i < N; i++) { if (W.at(V.at(i) - 1) >= 1) W.at(V.at(i) - 1)++; else { for (int i2 = 1; i2 * V.at(i) <= 1000000; i2++) W.at(i2 * V.at(i) - 1)++; } } int ans = 0; for (int j = 0; j < N; j++) { if (W.at(V.at(j) - 1) == 1) ans++; } cout << ans << endl; }
replace
12
14
12
19
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimization("Ofast") #pragma GCC optimization("unroll-loops") typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef pair<string, string> pss; typedef vector<ll> vll; typedef vector<pll> vpll; typedef vector<vll> vvll; typedef vector<vpll> vvpll; typedef unordered_map<ll, ll> um; typedef unordered_set<ll> us; #define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #define ts \ ll t; \ in(t) while (t--) solve(); #define ks \ ll t; \ in(t)FOR(i, 1, t + 1) out("Case #" << i << ": " << solve()); #define endl '\n' #define ln cout << endl; #define in(x) cin >> x; #define out(x) cout << x << endl; #define flush cout << flush; #define reset(a, b) memset(a, b, sizeof(a)); #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define FOR(i, a, b) for (ll i = a; i < b; i++) #define FORI(i, a, b, c) for (ll i = a; i < b; i += c) #define FORD(i, a, b) for (ll i = a; i > b; i--) #define FOREACH(it, v, r) for (auto it = v.begin() + r; it != v.end(); it++) #define FORALL(it, v) for (auto it : v) #define F first #define S second #define mp make_pair #define pb push_back #define vin(v, x) \ vll v(x); \ FOR(i, 0, x) in(v[i]) #define all(v) v.begin(), v.end() #define allr(v, r) v.begin(), v.begin() + r #define showv(v) \ FORALL(it, v) cout << it << ' '; \ ln #define printv(v) FORALL(it, v) out(it) #define show2d(v) \ FORALL(it, v) { \ FORALL(j, it) cout << j << ' '; \ ln \ } #define showm(v) \ FORALL(it, v) cout << it.F << ": " << it.S << ' '; \ ln #define sortv(v) sort(all(v)); #define revv(v) reverse(all(v)); #define maxv(v) *max_element(all(v)) #define minv(v) *min_element(all(v)) #define gcd __gcd #define checkbit(n, i) (n >> i) & 1 // check ith bit #define bitcount __builtin_popcount // count set bits #define firstbitindex __builtin_ctz // count trailing zeros #define lastbitindex __builtin_clz // count leading zeros #define bitparity __builtin_parity // check set bits are even or odd #define findv(v, x) (find(all(v), x) != v.end()) // find in a vector #define findsm(u, x) (u.find(x) != u.end()) // find in a set / map #define findstr(s, x) (s.find(x) != string::npos) // find in a string #define sz(a) a.size() #define precise(x) cout << fixed << setprecision(x); const ll MAXN = 1e6 + 1, MOD = 998244353, SIZE = 2e5, INF = 0x7f7f7f7f7f7f7f7f, ROOT = 998; const double EPS = 1e-9, PI = acos(-1); const int INFi = 0x7f7f7f7f; //<<------Declare Variables Here----->>// int n, c, f, i, j, a[SIZE], vis[MAXN], spf[MAXN] = {2}; //<<-----Implement Functions Here---->>// //<<----------Start of Main---------->>// int main() { fastio for (i = 3; i < 1e6; i += 2) spf[i] = i; for (i = 3; i < 998; i += 2) if (spf[i] == i) for (j = i * i; j < 1e6; j += i) if (spf[j] == j) spf[j] = i; in(n) for (i = 0; i < n; i++) cin >> a[i], vis[a[i]]++; if (vis[1]) { if (vis[1] == 1) out(1) else out(0) return 0; } for (i = 0; i < n; i++) if (vis[a[i]] == 1) { if (spf[a[i]] == a[i]) c++; else { f = 1; for (j = spf[a[i]]; j * j <= a[i]; j++) if (!(a[i] % j)) if (vis[a[i] / j] || vis[j]) { f = 0; break; } if (f) c++; } } out(c) return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimization("Ofast") #pragma GCC optimization("unroll-loops") typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef pair<string, string> pss; typedef vector<ll> vll; typedef vector<pll> vpll; typedef vector<vll> vvll; typedef vector<vpll> vvpll; typedef unordered_map<ll, ll> um; typedef unordered_set<ll> us; #define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #define ts \ ll t; \ in(t) while (t--) solve(); #define ks \ ll t; \ in(t)FOR(i, 1, t + 1) out("Case #" << i << ": " << solve()); #define endl '\n' #define ln cout << endl; #define in(x) cin >> x; #define out(x) cout << x << endl; #define flush cout << flush; #define reset(a, b) memset(a, b, sizeof(a)); #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define FOR(i, a, b) for (ll i = a; i < b; i++) #define FORI(i, a, b, c) for (ll i = a; i < b; i += c) #define FORD(i, a, b) for (ll i = a; i > b; i--) #define FOREACH(it, v, r) for (auto it = v.begin() + r; it != v.end(); it++) #define FORALL(it, v) for (auto it : v) #define F first #define S second #define mp make_pair #define pb push_back #define vin(v, x) \ vll v(x); \ FOR(i, 0, x) in(v[i]) #define all(v) v.begin(), v.end() #define allr(v, r) v.begin(), v.begin() + r #define showv(v) \ FORALL(it, v) cout << it << ' '; \ ln #define printv(v) FORALL(it, v) out(it) #define show2d(v) \ FORALL(it, v) { \ FORALL(j, it) cout << j << ' '; \ ln \ } #define showm(v) \ FORALL(it, v) cout << it.F << ": " << it.S << ' '; \ ln #define sortv(v) sort(all(v)); #define revv(v) reverse(all(v)); #define maxv(v) *max_element(all(v)) #define minv(v) *min_element(all(v)) #define gcd __gcd #define checkbit(n, i) (n >> i) & 1 // check ith bit #define bitcount __builtin_popcount // count set bits #define firstbitindex __builtin_ctz // count trailing zeros #define lastbitindex __builtin_clz // count leading zeros #define bitparity __builtin_parity // check set bits are even or odd #define findv(v, x) (find(all(v), x) != v.end()) // find in a vector #define findsm(u, x) (u.find(x) != u.end()) // find in a set / map #define findstr(s, x) (s.find(x) != string::npos) // find in a string #define sz(a) a.size() #define precise(x) cout << fixed << setprecision(x); const ll MAXN = 1e6 + 1, MOD = 998244353, SIZE = 2e5, INF = 0x7f7f7f7f7f7f7f7f, ROOT = 998; const double EPS = 1e-9, PI = acos(-1); const int INFi = 0x7f7f7f7f; //<<------Declare Variables Here----->>// int n, c, f, i, j, a[SIZE], vis[MAXN]; vll spf(MAXN, 2); //<<-----Implement Functions Here---->>// //<<----------Start of Main---------->>// int main() { fastio for (i = 3; i < 1e6; i += 2) spf[i] = i; for (i = 3; i < 998; i += 2) if (spf[i] == i) for (j = i * i; j < 1e6; j += i) if (spf[j] == j) spf[j] = i; in(n) for (i = 0; i < n; i++) cin >> a[i], vis[a[i]]++; if (vis[1]) { if (vis[1] == 1) out(1) else out(0) return 0; } for (i = 0; i < n; i++) if (vis[a[i]] == 1) { if (spf[a[i]] == a[i]) c++; else { f = 1; for (j = spf[a[i]]; j * j <= a[i]; j++) if (!(a[i] % j)) if (vis[a[i] / j] || vis[j]) { f = 0; break; } if (f) c++; } } out(c) return 0; }
replace
87
88
87
89
-8
p02642
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <chrono> #include <cmath> #include <complex> #include <cstdint> #include <cstdlib> #include <deque> #include <fstream> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> #define _USE_CMATH_DEFINES const long INF = (1l << 30); const long LINF = (1l << 60); // 1.15*10^18 const long MAX = 1000000; int main() { long n; scanf("%ld", &n); std::vector<long> a(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; } std::vector<bool> cieve(MAX + 1); std::sort(a.begin(), a.end()); long ans = 0; for (long i = 0; i < n; i++) { if (i == n - 1 || a[i + 1] != a[i]) { if (!cieve[a[i]]) { ans++; } } for (long j = 1; a[i] * j <= MAX; j++) { cieve[a[i] * j] = true; } } printf("%ld\n", ans); }
#include <algorithm> #include <bitset> #include <chrono> #include <cmath> #include <complex> #include <cstdint> #include <cstdlib> #include <deque> #include <fstream> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> #define _USE_CMATH_DEFINES const long INF = (1l << 30); const long LINF = (1l << 60); // 1.15*10^18 const long MAX = 1000000; int main() { long n; scanf("%ld", &n); std::vector<long> a(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; } std::vector<bool> cieve(MAX + 1); std::sort(a.begin(), a.end()); long ans = 0; for (long i = 0; i < n; i++) { if (i == n - 1 || a[i + 1] != a[i]) { if (!cieve[a[i]]) { ans++; } } if (!cieve[a[i]]) { for (long j = 1; a[i] * j <= MAX; j++) { cieve[a[i] * j] = true; } } } printf("%ld\n", ans); }
replace
43
45
43
47
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, a, b) for (int i = a; i < b; ++i) #define FORR(i, a, b) for (int i = b - 1; i >= a; --i) #define SORT(v) sort(v.begin(), v.end()) #define SORTR(v) sort(v.rbegin(), v.rend()) #define REV(v) reverse(v.begin(), v.end()) #define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr) #define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin()) #define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin()) #define SZ(v) (int)v.size() using namespace std; using ll = long long; using P = pair<int, int>; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<int> A(N); vector<int> memo(200001); REP(i, N) { cin >> A[i]; memo[A[i]]++; } int res = 0; REP(i, N) { if (memo[A[i]] > 1) continue; if (A[i] == 1) { ++res; continue; } if (memo[1]) { continue; } bool ok = true; for (ll j = 2; j * j <= A[i]; ++j) { if (A[i] % j == 0 && (memo[j] || memo[A[i] / j])) { ok = false; break; } } if (ok) ++res; } cout << res << endl; return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, a, b) for (int i = a; i < b; ++i) #define FORR(i, a, b) for (int i = b - 1; i >= a; --i) #define SORT(v) sort(v.begin(), v.end()) #define SORTR(v) sort(v.rbegin(), v.rend()) #define REV(v) reverse(v.begin(), v.end()) #define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr) #define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin()) #define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin()) #define SZ(v) (int)v.size() using namespace std; using ll = long long; using P = pair<int, int>; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<int> A(N); vector<int> memo(1000001); REP(i, N) { cin >> A[i]; memo[A[i]]++; } int res = 0; REP(i, N) { if (memo[A[i]] > 1) continue; if (A[i] == 1) { ++res; continue; } if (memo[1]) { continue; } bool ok = true; for (ll j = 2; j * j <= A[i]; ++j) { if (A[i] % j == 0 && (memo[j] || memo[A[i] / j])) { ok = false; break; } } if (ok) ++res; } cout << res << endl; return 0; }
replace
23
24
23
24
0
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <map> #include <queue> #include <set> #include <stack> #include <string.h> #include <vector> #define endl "\n" #define ll long long #define int long long #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cin.exceptions(cin.failbit); \ cout.tie(NULL); using namespace std; bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i += 6) { if ((n % i == 0) || (n % (i + 2) == 0)) return false; } return true; } int32_t main() { fast; ll n; cin >> n; ll a[n]; set<ll> s; map<ll, ll> mp; for (ll i = 0; i < n; i++) { cin >> a[i]; s.insert(a[i]); mp[a[i]]++; } ll c = 0; for (ll i = 0; i < n; i++) { if (mp[a[i]] > 1) { continue; } ll x = a[i]; ll raj = 0; for (ll j = 1; j <= sqrt(x); j++) { if (x % j == 0) { if (x / j == j) { if (j != x && s.find(j) != s.end()) { raj = 1; break; } } else { if (j != x && s.find(j) != s.end()) { raj = 1; break; } if (x / j != x && s.find(x / j) != s.end()) { raj = 1; break; } } } } if (raj == 0) c++; } cout << c; }
#include <bits/stdc++.h> #include <map> #include <queue> #include <set> #include <stack> #include <string.h> #include <vector> #define endl "\n" #define ll long long #define int long long #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cin.exceptions(cin.failbit); \ cout.tie(NULL); using namespace std; bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i += 6) { if ((n % i == 0) || (n % (i + 2) == 0)) return false; } return true; } int32_t main() { fast; ll n; cin >> n; ll a[n]; set<ll> s; unordered_map<ll, ll> mp; for (ll i = 0; i < n; i++) { cin >> a[i]; s.insert(a[i]); mp[a[i]]++; } ll c = 0; for (ll i = 0; i < n; i++) { if (mp[a[i]] > 1) { continue; } ll x = a[i]; ll raj = 0; for (ll j = 1; j <= sqrt(x); j++) { if (x % j == 0) { if (x / j == j) { if (j != x && s.find(j) != s.end()) { raj = 1; break; } } else { if (j != x && s.find(j) != s.end()) { raj = 1; break; } if (x / j != x && s.find(x / j) != s.end()) { raj = 1; break; } } } } if (raj == 0) c++; } cout << c; }
replace
35
36
35
36
TLE