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>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll mod(ll a, ll b) {
ll ret = a % b;
if (ret < 0)
ret += b;
return ret;
}
ll modpow(ll a, ll b, ll c) {
ll res = 1;
while (b > 0) {
if (b & 1)
res = mod(res * a, c);
a = mod(a * a, c);
b >>= 1;
}
return res;
}
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
bool b[1000001];
for (int i = 0; i < 1000001; i++) {
b[i] = true;
}
int ans = 0;
for (int i = 0; i < n; i++) {
bool temp = true;
if (n != n - 1) {
if (a[i] == a[i + 1])
temp = false;
}
if (b[a[i]] and temp)
ans++;
for (int j = a[i]; j <= 1000000; j += a[i]) {
b[j] = false;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll mod(ll a, ll b) {
ll ret = a % b;
if (ret < 0)
ret += b;
return ret;
}
ll modpow(ll a, ll b, ll c) {
ll res = 1;
while (b > 0) {
if (b & 1)
res = mod(res * a, c);
a = mod(a * a, c);
b >>= 1;
}
return res;
}
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
bool b[1000001];
for (int i = 0; i < 1000001; i++) {
b[i] = true;
}
int ans = 0;
for (int i = 0; i < n; i++) {
bool temp = true;
if (n != n - 1) {
if (a[i] == a[i + 1])
temp = false;
}
if (b[a[i]] and temp)
ans++;
if (!b[a[i]])
continue;
for (int j = a[i]; j <= 1000000; j += a[i]) {
b[j] = false;
}
}
cout << ans << endl;
return 0;
}
| insert | 45 | 45 | 45 | 47 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define sws \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for (int i = 0; i < n; i++)
int main() {
int n;
cin >> n;
bool divs[1000005];
map<int, int> m;
vi a(n);
memset(divs, true, sizeof(divs));
fo(i, n) {
cin >> a[i];
m[a[i]]++;
for (int j = a[i] * 2; j < 1000005; j += a[i]) {
divs[j] = false;
}
}
int ans = 0;
fo(i, n) if (divs[a[i]] and m[a[i]] == 1) {
// cout << a[i] << endl;
ans++;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define sws \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for (int i = 0; i < n; i++)
int main() {
int n;
cin >> n;
bool divs[1000005];
map<int, int> m;
vi a(n);
memset(divs, true, sizeof(divs));
fo(i, n) {
cin >> a[i];
if (++m[a[i]] > 1)
continue;
for (int j = a[i] * 2; j < 1000005; j += a[i]) {
divs[j] = false;
}
}
int ans = 0;
fo(i, n) if (divs[a[i]] and m[a[i]] == 1) {
// cout << a[i] << endl;
ans++;
}
cout << ans << endl;
return 0;
} | replace | 29 | 30 | 29 | 31 | TLE | |
p02642 | C++ | Runtime Error | // #include<bits/stdc++.h>
// #define IOS ios::sync_with_stdio(0);cin.tie(0);
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORE(i, a, b) for (int i = (a); i <= (b); i++)
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
bool dp[100010];
int arr[20010];
int main() {
// IOS
int n;
cin >> n;
int p;
int max = -1;
for (int i = 1; i <= n; i++) {
cin >> p;
if (p > max)
max = p;
arr[i] = p;
}
sort(arr + 1, arr + 1 + n);
for (int i = 1; i <= n; i++) {
if (arr[i] == arr[i - 1]) {
dp[arr[i]] = true;
}
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (dp[arr[i]] == false) {
cnt++;
}
if (arr[i] != arr[i - 1]) {
for (int j = 2 * arr[i]; j <= max; j += arr[i]) {
dp[j] = true;
}
}
}
cout << cnt << endl;
return 0;
} | // #include<bits/stdc++.h>
// #define IOS ios::sync_with_stdio(0);cin.tie(0);
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORE(i, a, b) for (int i = (a); i <= (b); i++)
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
bool dp[10000010];
int arr[2000010];
int main() {
// IOS
int n;
cin >> n;
int p;
int max = -1;
for (int i = 1; i <= n; i++) {
cin >> p;
if (p > max)
max = p;
arr[i] = p;
}
sort(arr + 1, arr + 1 + n);
for (int i = 1; i <= n; i++) {
if (arr[i] == arr[i - 1]) {
dp[arr[i]] = true;
}
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (dp[arr[i]] == false) {
cnt++;
}
if (arr[i] != arr[i - 1]) {
for (int j = 2 * arr[i]; j <= max; j += arr[i]) {
dp[j] = true;
}
}
}
cout << cnt << endl;
return 0;
} | replace | 13 | 15 | 13 | 15 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pii pair<int, int>
int N;
int A[200010];
int mem[1000010];
int num[1000010];
signed main() {
cin >> N;
rep(i, N) {
cin >> A[i];
num[A[i]]++;
}
sort(A, A + N);
int ans = 0;
rep(i, N) {
if (mem[A[i]] == 0 && num[A[i]] == 1)
ans++;
for (int j = A[i]; j <= 1000000; j += A[i])
mem[j] = 1;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pii pair<int, int>
int N;
int A[200010];
int mem[1000010];
int num[1000010];
signed main() {
cin >> N;
rep(i, N) {
cin >> A[i];
num[A[i]]++;
}
sort(A, A + N);
int ans = 0;
rep(i, N) {
if (mem[A[i]] == 0 && num[A[i]] == 1)
ans++;
if (mem[A[i]] == 0)
for (int j = A[i]; j <= 1000000; j += A[i])
mem[j] = 1;
}
cout << ans << endl;
return 0;
}
| replace | 25 | 27 | 25 | 28 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#include <math.h>
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 int64_t INF = 1LL << 60;
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
int m = *max_element(A.begin(), A.end());
sort(A.begin(), A.end());
vector<bool> ok(999999, true);
for (int i = 0; i < N; i++) {
if (A[i] == A[i + 1]) {
ok[A[i]] = false;
}
for (int j = 2; j <= (m + A[i] - 1) / A[i]; j++) {
ok[A[i] * j] = false;
}
}
int cnt = 0;
for (int i = 0; i < N; i++) {
if (ok[A[i]]) {
cnt++;
}
}
cout << cnt << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#include <math.h>
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 int64_t INF = 1LL << 60;
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
int m = *max_element(A.begin(), A.end());
sort(A.begin(), A.end());
vector<bool> ok(10000000, true);
for (int i = 0; i < N; i++) {
if (A[i] == A[i + 1]) {
ok[A[i]] = false;
}
for (int j = 2; j <= (m + A[i] - 1) / A[i]; j++) {
ok[A[i] * j] = false;
}
}
int cnt = 0;
for (int i = 0; i < N; i++) {
if (ok[A[i]]) {
cnt++;
}
}
cout << cnt << endl;
return 0;
}
| replace | 29 | 30 | 29 | 30 | 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++)
int main() {
int n;
cin >> n;
int m = 100000001;
vector<int> ans(m, 0), a(n, 0);
int maxidx = 0;
rep(i, n) {
cin >> a[i];
maxidx = max(a[i], maxidx);
}
set<int> nums;
for (auto i : a) {
if (ans[i] != 0) {
ans[i] = 2;
continue;
}
for (int j = i; j < m; j += i) {
ans[j] += 1;
}
}
int cnt = 0;
for (auto i : a)
if (ans[i] == 1)
cnt++;
cout << cnt << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
int main() {
int n;
cin >> n;
int m = 1000005;
vector<int> ans(m, 0), a(n, 0);
int maxidx = 0;
rep(i, n) {
cin >> a[i];
maxidx = max(a[i], maxidx);
}
set<int> nums;
for (auto i : a) {
if (ans[i] != 0) {
ans[i] = 2;
continue;
}
for (int j = i; j < m; j += i) {
ans[j] += 1;
}
}
int cnt = 0;
for (auto i : a)
if (ans[i] == 1)
cnt++;
cout << cnt << endl;
}
| replace | 7 | 8 | 7 | 8 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e5 + 555;
const int MOD = 1e9 + 7;
int mp[maxn];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout.precision(10);
cout << fixed;
int n;
cin >> n;
vector<int> V(n);
for (int &i : V) {
cin >> i;
mp[i]++;
}
int ans = 0;
for (int i : V) {
mp[i]--;
bool ok = true;
for (int j = 1; j * j <= i && ok; j++) {
if (i % j == 0) {
ok &= !mp[j];
ok &= !mp[i / j];
}
}
ans += ok;
mp[i]++;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e6 + 555;
const int MOD = 1e9 + 7;
int mp[maxn];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout.precision(10);
cout << fixed;
int n;
cin >> n;
vector<int> V(n);
for (int &i : V) {
cin >> i;
mp[i]++;
}
int ans = 0;
for (int i : V) {
mp[i]--;
bool ok = true;
for (int j = 1; j * j <= i && ok; j++) {
if (i % j == 0) {
ok &= !mp[j];
ok &= !mp[i / j];
}
}
ans += ok;
mp[i]++;
}
cout << ans << endl;
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02642 | C++ | Runtime Error | #define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) \
cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) \
cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << endl
#define debug_4(x1, x2, x3, x4) \
cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) \
cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...) \
CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index, num) for (int index = 0; index < (int)num; index++)
#define rep1(index, num) for (int index = 1; index <= (int)num; index++)
#define brep(index, num) for (int index = (int)num - 1; index >= 0; index--)
#define brep1(index, num) for (int index = (int)num; index > 0; index--)
#define scan(argument) cin >> argument
#define prin(argument) cout << argument << endl
#define kaigyo cout << endl
#define eps 1e-7
#define mp(a1, a2) make_pair(a1, a2)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl = (ll)1e+18 + 1;
int INF = 1e+9 + 1;
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(begin(ret), end(ret));
return (ret);
}
int cnt[100001] = {};
int main() {
int N;
int A[200001];
int ans = 0;
scan(N);
rep(i, N) {
scan(A[i]);
cnt[A[i]]++;
}
rep(i, N) {
vll yaku = divisor(A[i]);
bool flag = 1;
for (auto x : yaku) {
if (x != A[i] && cnt[x] > 0) {
flag = 0;
break;
} else if (x == A[i] && cnt[x] > 1) {
flag = 0;
break;
}
}
if (flag)
ans++;
}
prin(ans);
return 0;
}
| #define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) \
cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) \
cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << endl
#define debug_4(x1, x2, x3, x4) \
cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) \
cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...) \
CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index, num) for (int index = 0; index < (int)num; index++)
#define rep1(index, num) for (int index = 1; index <= (int)num; index++)
#define brep(index, num) for (int index = (int)num - 1; index >= 0; index--)
#define brep1(index, num) for (int index = (int)num; index > 0; index--)
#define scan(argument) cin >> argument
#define prin(argument) cout << argument << endl
#define kaigyo cout << endl
#define eps 1e-7
#define mp(a1, a2) make_pair(a1, a2)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl = (ll)1e+18 + 1;
int INF = 1e+9 + 1;
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(begin(ret), end(ret));
return (ret);
}
int cnt[1000001] = {};
int main() {
int N;
int A[200001];
int ans = 0;
scan(N);
rep(i, N) {
scan(A[i]);
cnt[A[i]]++;
}
rep(i, N) {
vll yaku = divisor(A[i]);
bool flag = 1;
for (auto x : yaku) {
if (x != A[i] && cnt[x] > 0) {
flag = 0;
break;
} else if (x == A[i] && cnt[x] > 1) {
flag = 0;
break;
}
}
if (flag)
ans++;
}
prin(ans);
return 0;
}
| replace | 57 | 58 | 57 | 58 | 0 | |
p02642 | C++ | Time Limit Exceeded | // インクルード(アルファベット順)
#include <algorithm> //sort,二分探索,など
#include <bitset> //固定長bit集合
#include <cmath> //pow,logなど
#include <complex> //複素数
#include <deque> //両端アクセスのキュー
#include <functional> //sortのgreater
#include <iomanip> //setprecision(浮動小数点の出力の誤差)
#include <iostream> //入出力
#include <iterator> //集合演算(積集合,和集合,差集合など)
#include <map> //map(辞書)
#include <numeric> //iota(整数列の生成),gcdとlcm(c++17)
#include <queue> //キュー
#include <set> //集合
#include <stack> //スタック
#include <string> //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility> //pair
#include <vector> //可変長配列
using namespace std;
typedef long long ll;
// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) // 最大値を求める
#define MIN(x) *min_element(ALL(x)) // 最小値を求める
// 定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007 // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first // pairの一つ目の要素
#define S second // pairの二つ目の要素
vector<ll> divosor(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);
}
}
return ret;
}
bool IsPrime(ll num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // 偶数はあらかじめ除く
double sqrtNum = sqrt(num);
for (ll i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// 素数ではない
return false;
}
}
// 素数である
return true;
}
signed main() {
int N;
cin >> N;
vector<ll> num_list(N);
vector<bool> bool_list(1000001, true);
for (ll i = 0; i < N; i++) {
cin >> num_list[i];
}
sort(num_list.begin(), num_list.end());
int ans = 0;
for (int i = 0; i < N; i++) {
if (bool_list[num_list[i]]) {
if (i + 1 < N) {
if (num_list[i] != num_list[i + 1]) {
ans++;
}
} else {
ans++;
}
}
ll index = 1;
while (index * num_list[i] < 1000001) {
bool_list[index * num_list[i]] = false;
index++;
}
}
cout << ans << endl;
} | // インクルード(アルファベット順)
#include <algorithm> //sort,二分探索,など
#include <bitset> //固定長bit集合
#include <cmath> //pow,logなど
#include <complex> //複素数
#include <deque> //両端アクセスのキュー
#include <functional> //sortのgreater
#include <iomanip> //setprecision(浮動小数点の出力の誤差)
#include <iostream> //入出力
#include <iterator> //集合演算(積集合,和集合,差集合など)
#include <map> //map(辞書)
#include <numeric> //iota(整数列の生成),gcdとlcm(c++17)
#include <queue> //キュー
#include <set> //集合
#include <stack> //スタック
#include <string> //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility> //pair
#include <vector> //可変長配列
using namespace std;
typedef long long ll;
// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) // 最大値を求める
#define MIN(x) *min_element(ALL(x)) // 最小値を求める
// 定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007 // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first // pairの一つ目の要素
#define S second // pairの二つ目の要素
vector<ll> divosor(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);
}
}
return ret;
}
bool IsPrime(ll num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // 偶数はあらかじめ除く
double sqrtNum = sqrt(num);
for (ll i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// 素数ではない
return false;
}
}
// 素数である
return true;
}
signed main() {
int N;
cin >> N;
vector<ll> num_list(N);
vector<bool> bool_list(1000001, true);
for (ll i = 0; i < N; i++) {
cin >> num_list[i];
}
sort(num_list.begin(), num_list.end());
int ans = 0;
for (int i = 0; i < N; i++) {
if (bool_list[num_list[i]]) {
if (i + 1 < N) {
if (num_list[i] != num_list[i + 1]) {
ans++;
}
} else {
ans++;
}
} else {
continue;
}
ll index = 1;
while (index * num_list[i] < 1000001) {
bool_list[index * num_list[i]] = false;
index++;
}
}
cout << ans << endl;
} | insert | 99 | 99 | 99 | 102 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template <typename T> using pq = priority_queue<T>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
template <class T> ostream &operator<<(ostream &out, const vector<T> &list) {
ll n = list.size();
rep(i, n) out << list[i] << ' ';
return out;
}
template <class T> istream &operator>>(istream &in, vector<T> &list) {
ll n = list.size();
rep(i, n) in >> list[i];
return in;
}
template <class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
ll n = list.size();
rep(i, n) out << list[i] << '\n';
return out;
}
/* ------------- ANSWER ------------- */
/* ---------------------------------- */
// 素因数分解
map<ll, ll> prime_factor(ll n) {
map<ll, ll> mp;
for (ll i = 2; i * i <= n; ++i) {
while (n % i == 0) {
mp[i]++;
n /= i;
}
}
if (n != 1)
mp[n]++;
return mp;
}
// 素数判定
bool is_prime(ll n) {
for (int i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return n != 1;
}
// 約数列挙
vector<ll> divisor(ll n) {
vector<ll> res;
for (ll i = 1; i * i <= n; ++i) {
if (n % i == 0) {
res.emplace_back(i);
if (i != n / i)
res.emplace_back(n / i);
}
}
return res;
}
void solve() {
ll n;
cin >> n;
vl a(n);
cin >> a;
map<ll, ll> mp;
rep(i, n) { mp[a[i]]++; }
ll ans = 0;
rep(i, n) {
vl div = divisor(a[i]);
bool plus = true;
each(e, div) {
if (e == a[i] && mp[e] > 1) {
plus = false;
break;
} else if (e != a[i] && mp[e] > 0) {
plus = false;
break;
}
}
if (plus)
ans++;
}
cout << ans << '\n';
}
int main() {
#ifdef MY_DEBUG
while (true) {
#endif
solve();
#ifdef MY_DEBUG
}
#endif
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template <typename T> using pq = priority_queue<T>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
template <class T> ostream &operator<<(ostream &out, const vector<T> &list) {
ll n = list.size();
rep(i, n) out << list[i] << ' ';
return out;
}
template <class T> istream &operator>>(istream &in, vector<T> &list) {
ll n = list.size();
rep(i, n) in >> list[i];
return in;
}
template <class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
ll n = list.size();
rep(i, n) out << list[i] << '\n';
return out;
}
/* ------------- ANSWER ------------- */
/* ---------------------------------- */
// 素因数分解
map<ll, ll> prime_factor(ll n) {
map<ll, ll> mp;
for (ll i = 2; i * i <= n; ++i) {
while (n % i == 0) {
mp[i]++;
n /= i;
}
}
if (n != 1)
mp[n]++;
return mp;
}
// 素数判定
bool is_prime(ll n) {
for (int i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return n != 1;
}
// 約数列挙
vector<ll> divisor(ll n) {
vector<ll> res;
for (ll i = 1; i * i <= n; ++i) {
if (n % i == 0) {
res.emplace_back(i);
if (i != n / i)
res.emplace_back(n / i);
}
}
return res;
}
void solve() {
ll n;
cin >> n;
vl a(n);
cin >> a;
unordered_map<ll, ll> mp;
rep(i, n) { mp[a[i]]++; }
ll ans = 0;
rep(i, n) {
vl div = divisor(a[i]);
bool plus = true;
each(e, div) {
if (e == a[i] && mp[e] > 1) {
plus = false;
break;
} else if (e != a[i] && mp[e] > 0) {
plus = false;
break;
}
}
if (plus)
ans++;
}
cout << ans << '\n';
}
int main() {
#ifdef MY_DEBUG
while (true) {
#endif
solve();
#ifdef MY_DEBUG
}
#endif
return 0;
}
| replace | 89 | 90 | 89 | 90 | TLE | |
p02642 | C++ | Time Limit Exceeded | // #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod = 1e+9 + 7;
const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
const ll INF = 1e10;
int main() {
ll n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
vector<ll> cnt(1e6 + 10, 0);
for (auto x : a) {
/*if(cnt[x]!=0){
cnt[x]=2;
continue;
}*/
for (ll i = x; i < 1e6 + 10; i += x) {
cnt[i]++;
}
}
ll ans = 0;
for (auto x : a) {
if (cnt[x] == 1) {
// cout<<x<<" ";
ans++;
}
}
// cout<<endl;
cout << ans << endl;
}
| // #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod = 1e+9 + 7;
const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
const ll INF = 1e10;
int main() {
ll n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
vector<ll> cnt(1e6 + 10, 0);
for (auto x : a) {
if (cnt[x] != 0) {
cnt[x] = 2;
continue;
}
for (ll i = x; i < 1e6 + 10; i += x) {
cnt[i]++;
}
}
ll ans = 0;
for (auto x : a) {
if (cnt[x] == 1) {
// cout<<x<<" ";
ans++;
}
}
// cout<<endl;
cout << ans << endl;
}
| replace | 21 | 25 | 21 | 26 | TLE | |
p02642 | C++ | Runtime Error | /*
Created by Ezio112
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
ll inf(1e18);
#define mod ll(1e9 + 7)
// #define mod ll(998244353)
#define ff first
#define ss second
ll power(ll a, ll b) {
if (!b)
return 1;
ll dp = power(a, b / 2) % mod;
if (b & 1)
return (((dp * dp) % mod) * a) % mod;
return (dp * dp) % mod;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll test = 1;
// cin>>test;
while (test--) {
ll n;
cin >> n;
vector<ll> vec(n);
for (ll &x : vec)
cin >> x;
vector<short int> dp(200005);
for (ll x : vec)
++dp[x];
for (ll i = 1; i < dp.size(); ++i) {
if (dp[i] == 0)
continue;
for (ll j = 2 * i; j < dp.size(); j += i)
dp[j] = 0;
}
ll sum = 0;
for (ll x : dp)
if (x == 1)
sum += x;
cout << sum;
}
return 0;
}
| /*
Created by Ezio112
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
ll inf(1e18);
#define mod ll(1e9 + 7)
// #define mod ll(998244353)
#define ff first
#define ss second
ll power(ll a, ll b) {
if (!b)
return 1;
ll dp = power(a, b / 2) % mod;
if (b & 1)
return (((dp * dp) % mod) * a) % mod;
return (dp * dp) % mod;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll test = 1;
// cin>>test;
while (test--) {
ll n;
cin >> n;
vector<ll> vec(n);
for (ll &x : vec)
cin >> x;
vector<short int> dp(2000005);
for (ll x : vec)
++dp[x];
for (ll i = 1; i < dp.size(); ++i) {
if (dp[i] == 0)
continue;
for (ll j = 2 * i; j < dp.size(); j += i)
dp[j] = 0;
}
ll sum = 0;
for (ll x : dp)
if (x == 1)
sum += x;
cout << sum;
}
return 0;
}
| replace | 38 | 39 | 38 | 39 | 0 | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 998244353;
int parent[N];
int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
ll pow(ll x, ll y, ll p) {
if (y == 0)
return 1;
ll res = 1;
x %= p;
if (x == 0)
return 0LL;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y >>= 1;
x = (x * x) % p;
}
return res;
}
int find(int x) { return x == parent[x] ? x : parent[x] = find(parent[x]); }
void Union(int x, int y) {
int xPar = find(x), yPar = find(y);
if (xPar != yPar)
parent[xPar] = yPar;
}
int main() {
IOS int n;
cin >> n;
ll mx = 0;
vector<ll> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
mx = max(mx, a[i]);
}
vector<int> cnt(N);
for (auto val : a) {
if (cnt[val]) {
cnt[val] = 2;
continue;
}
for (int j = val; j <= mx; j += val)
cnt[j]++;
}
int res = 0;
for (auto val : a)
if (cnt[val] == 1)
res++;
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 998244353;
int parent[N];
int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
ll pow(ll x, ll y, ll p) {
if (y == 0)
return 1;
ll res = 1;
x %= p;
if (x == 0)
return 0LL;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y >>= 1;
x = (x * x) % p;
}
return res;
}
int find(int x) { return x == parent[x] ? x : parent[x] = find(parent[x]); }
void Union(int x, int y) {
int xPar = find(x), yPar = find(y);
if (xPar != yPar)
parent[xPar] = yPar;
}
int main() {
IOS int n;
cin >> n;
ll mx = 0;
vector<ll> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
mx = max(mx, a[i]);
}
vector<int> cnt(mx + 1);
for (auto val : a) {
if (cnt[val]) {
cnt[val] = 2;
continue;
}
for (int j = val; j <= mx; j += val)
cnt[j]++;
}
int res = 0;
for (auto val : a)
if (cnt[val] == 1)
res++;
cout << res << endl;
return 0;
}
| replace | 57 | 58 | 57 | 58 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(nullptr);
#define all(x) x.begin(), x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for (int x = 0; x < n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define ctoi(x) (x - '0')
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
int n, ans;
vi v(200010);
map<int, int> M;
int main() {
fastio;
cin >> n;
FOR(i, n) {
cin >> v[i + 1];
M[v[i + 1]]++;
}
for (int i = 1; i <= n; i++) {
int flag = 1;
for (ll j = 1; j * j <= v[i]; j++) {
if (v[i] % j == 0) {
// v[i]/j, j
if (j == v[i] && M[j] >= 2 || j != v[i] && M[j] >= 1 ||
v[i] / j == v[i] && M[v[i] / j] >= 2 ||
v[i] / j != v[i] && M[v[i] / j] >= 1) {
flag = 0;
break;
}
}
}
if (flag)
ans++;
}
cout << ans;
} | #include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(nullptr);
#define all(x) x.begin(), x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for (int x = 0; x < n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define ctoi(x) (x - '0')
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
int n, ans;
vi v(200010);
unordered_map<int, int> M;
int main() {
fastio;
cin >> n;
FOR(i, n) {
cin >> v[i + 1];
M[v[i + 1]]++;
}
for (int i = 1; i <= n; i++) {
int flag = 1;
for (ll j = 1; j * j <= v[i]; j++) {
if (v[i] % j == 0) {
// v[i]/j, j
if (j == v[i] && M[j] >= 2 || j != v[i] && M[j] >= 1 ||
v[i] / j == v[i] && M[v[i] / j] >= 2 ||
v[i] / j != v[i] && M[v[i] / j] >= 1) {
flag = 0;
break;
}
}
}
if (flag)
ans++;
}
cout << ans;
} | replace | 29 | 30 | 29 | 30 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template <typename TYPE> void print_vec(const vector<TYPE> &v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i] << " ";
}
cout << endl;
}
template <typename TYPE> void print_vec2(const vector<vector<TYPE>> &v) {
cout << endl;
for (int i = 0; i < v[0].size(); i++)
cout << i << " ";
cout << endl;
for (int i = 0; i < v.size(); i++) {
cout << "i=" << i << ": " << endl;
for (int j = 0; j < v[i].size(); j++) {
if (v[i][j] == 0)
cout << "\x1B[0m" << v[i][j] << " ";
else
cout << "\x1B[31m" << v[i][j]
<< " "; // https://stackoverrun.com/ja/q/12618775
}
cout << "\x1B[0m" << endl;
}
}
int main() {
ll N;
cin >> N;
vector<ll> A(N);
for (int i = 0; i < N; i++)
cin >> A[i];
// const ll MAX_A = 1e6;
ll MAX_A = 1e6;
for (int i = 0; i < N; i++) {
MAX_A = max(MAX_A, A[i]);
}
vector<ll> vec(MAX_A + 5, 0);
for (ll a : A) {
for (ll j = 1; a * j <= MAX_A; j++) {
vec[a * j]++;
}
}
ll ans = 0;
for (ll a : A) {
if (vec[a] == 1)
ans++;
}
cout << ans << endl;
}
| #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template <typename TYPE> void print_vec(const vector<TYPE> &v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i] << " ";
}
cout << endl;
}
template <typename TYPE> void print_vec2(const vector<vector<TYPE>> &v) {
cout << endl;
for (int i = 0; i < v[0].size(); i++)
cout << i << " ";
cout << endl;
for (int i = 0; i < v.size(); i++) {
cout << "i=" << i << ": " << endl;
for (int j = 0; j < v[i].size(); j++) {
if (v[i][j] == 0)
cout << "\x1B[0m" << v[i][j] << " ";
else
cout << "\x1B[31m" << v[i][j]
<< " "; // https://stackoverrun.com/ja/q/12618775
}
cout << "\x1B[0m" << endl;
}
}
int main() {
ll N;
cin >> N;
vector<ll> A(N);
for (int i = 0; i < N; i++)
cin >> A[i];
// const ll MAX_A = 1e6;
ll MAX_A = 0;
for (int i = 0; i < N; i++) {
MAX_A = max(MAX_A, A[i]);
}
vector<ll> vec(MAX_A + 5, 0);
for (ll a : A) {
for (ll j = 1; a * j <= MAX_A; j++) {
vec[a * j]++;
}
}
ll ans = 0;
for (ll a : A) {
if (vec[a] == 1)
ans++;
}
cout << ans << endl;
}
| replace | 37 | 38 | 37 | 38 | TLE | |
p02642 | C++ | Runtime Error | #include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
int N;
cin >> N;
int M = 1000005;
int cnt[M];
for (int i = 0; i < M; i++) {
cnt[i] = 0;
}
int A[N];
for (int i = 0; i < N; i++) {
cin >> A[i];
if (cnt[A[i]] > 1) {
break;
} else {
for (int j = A[i]; j < M; j += A[i]) {
cnt[j]++;
}
}
}
int ans = 0;
for (int i = 0; i < N; i++) {
if (cnt[A[i]] == 1) {
ans++;
}
}
cout << ans << endl;
return 0;
} | #include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
int N;
cin >> N;
int M = 1000005;
int cnt[M];
for (int i = 0; i < M; i++) {
cnt[i] = 0;
}
int A[N];
for (int i = 0; i < N; i++) {
cin >> A[i];
if (cnt[A[i]] > 1) {
continue;
} else {
for (int j = A[i]; j < M; j += A[i]) {
cnt[j]++;
}
}
}
int ans = 0;
for (int i = 0; i < N; i++) {
if (cnt[A[i]] == 1) {
ans++;
}
}
cout << ans << endl;
return 0;
} | replace | 18 | 19 | 18 | 19 | 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++)
int64_t MOD = 1000000007;
int main() {
int N, ans = 0;
cin >> N;
vector<int64_t> A(N);
vector<bool> div(1000050, true);
rep(i, N) cin >> A.at(i);
sort(A.begin(), A.end());
rep(i, N) {
int64_t k = A.at(i), l = 2;
if (div.at(k)) {
while (k * l <= 1000010) {
div.at(k * l) = false;
l++;
}
}
}
rep(i, N - 1) {
if (A.at(i) == A.at(i + 1))
div.at(A.at(i)) = false;
}
rep(i, N) {
if (div.at(A.at(i)))
ans++;
}
cout << ans;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD = 1000000007;
int main() {
int N, ans = 0;
cin >> N;
vector<int64_t> A(N);
vector<bool> div(1000050, true);
rep(i, N) cin >> A.at(i);
sort(A.begin(), A.end());
rep(i, N) {
int64_t k = A.at(i), l = 2;
if (div.at(k)) {
while (k * l <= 1000010) {
div.at(k * l) = false;
l++;
}
}
if (i > 0 && k == A.at(i - 1))
div.at(k) = false;
}
rep(i, N) {
if (div.at(A.at(i)))
ans++;
}
cout << ans;
}
| replace | 19 | 23 | 19 | 21 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
template <typename T>
void print_vec(const vector<T> &v, bool is_reverse = false, ll num = 0) {
if (num == 0)
num = (ll)v.size();
cout << endl;
cout << "i= ";
for (ll i = 0; i < num; i++)
cout << i << " ";
cout << endl;
cout << " ";
if (is_reverse)
for (ll i = num - 1; i >= 0; i--) {
cout << v[i];
if (i != 0)
cout << " ";
}
else
for (ll i = 0; i < num; i++) {
cout << v[i];
if (i != num - 1)
cout << " ";
}
cout << endl;
}
// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
// if(num == 0) num = (ll)v.size();
// cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " <<
// v[i].second << endl;}
// }
template <typename T> void print_pairvec(const T &_pair, ll num = 0) {
cout << endl;
for (pair<ll, int> x : _pair) {
cout << x.first << " " << x.second << endl;
}
}
template <typename T> void print_vec2(const vector<vector<T>> &v) {
cout << endl;
cout << " ";
for (ll i = 0; i < v[0].size(); i++)
cout << i << " ";
cout << endl;
for (ll i = 0; i < v.size(); i++) {
cout << "i=" << i << ": ";
for (ll j = 0; j < v[i].size(); j++) {
if (v[i][j] == 0)
cout << "\x1B[0m" << v[i][j] << " ";
else
cout << "\x1B[31m" << v[i][j]
<< " "; // https://stackoverrun.com/ja/q/12618775
}
cout << "\x1B[0m" << endl;
}
}
struct Eratosthenes {
vector<ll> sieve; // sieve[i]: 数字iがエラトステネスで篩落とされた時の素数
Eratosthenes(ll n) : sieve(n + 1) {
for (int i = 0; i <= n; i++)
sieve[i] = i;
for (ll i = 2; i * i <= n; i++) {
if (sieve[i] < i)
continue;
for (ll j = i * i; j <= n; j += i)
sieve[j] = min(sieve[j], i);
}
}
vector<ll> prime_divisors(ll x, bool tmp = false) {
vector<ll> res(1, 1); // back()のところで
// ひっかかるので1を入れとかないとダメ
while (x > 1) {
if (res.back() != sieve[x])
res.push_back(sieve[x]);
x /= sieve[x];
}
return res;
}
map<ll, int> prime_divisors(ll x, int tmp = 0) {
map<ll, int> mp;
while (x > 1) {
mp[sieve[x]]++;
x /= sieve[x];
}
return mp;
}
};
int main() {
ll N;
cin >> N;
vector<ll> A(N);
for (ll i = 0; i < N; i++)
cin >> A[i];
sort(
A.begin(),
A.end()); // 82行目のbreakを入れないとTLEになるらしく,それならsortしないといけない
const ll INF = 1e6 + 1;
vector<ll> vec(INF, 0);
for (ll i = 0; i < N; i++) {
for (ll j = 1; j * A[i] <= INF; j++) {
vec[A[i] * j]++;
// if(vec[A[i]*j] >= 2) break;// これいれたらWA?
}
}
ll ans = 0;
for (ll i = 0; i < N; i++) {
if (vec[A[i]] == 1)
ans++;
}
cout << ans << endl;
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
using ll = long long;
template <typename T>
void print_vec(const vector<T> &v, bool is_reverse = false, ll num = 0) {
if (num == 0)
num = (ll)v.size();
cout << endl;
cout << "i= ";
for (ll i = 0; i < num; i++)
cout << i << " ";
cout << endl;
cout << " ";
if (is_reverse)
for (ll i = num - 1; i >= 0; i--) {
cout << v[i];
if (i != 0)
cout << " ";
}
else
for (ll i = 0; i < num; i++) {
cout << v[i];
if (i != num - 1)
cout << " ";
}
cout << endl;
}
// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
// if(num == 0) num = (ll)v.size();
// cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " <<
// v[i].second << endl;}
// }
template <typename T> void print_pairvec(const T &_pair, ll num = 0) {
cout << endl;
for (pair<ll, int> x : _pair) {
cout << x.first << " " << x.second << endl;
}
}
template <typename T> void print_vec2(const vector<vector<T>> &v) {
cout << endl;
cout << " ";
for (ll i = 0; i < v[0].size(); i++)
cout << i << " ";
cout << endl;
for (ll i = 0; i < v.size(); i++) {
cout << "i=" << i << ": ";
for (ll j = 0; j < v[i].size(); j++) {
if (v[i][j] == 0)
cout << "\x1B[0m" << v[i][j] << " ";
else
cout << "\x1B[31m" << v[i][j]
<< " "; // https://stackoverrun.com/ja/q/12618775
}
cout << "\x1B[0m" << endl;
}
}
struct Eratosthenes {
vector<ll> sieve; // sieve[i]: 数字iがエラトステネスで篩落とされた時の素数
Eratosthenes(ll n) : sieve(n + 1) {
for (int i = 0; i <= n; i++)
sieve[i] = i;
for (ll i = 2; i * i <= n; i++) {
if (sieve[i] < i)
continue;
for (ll j = i * i; j <= n; j += i)
sieve[j] = min(sieve[j], i);
}
}
vector<ll> prime_divisors(ll x, bool tmp = false) {
vector<ll> res(1, 1); // back()のところで
// ひっかかるので1を入れとかないとダメ
while (x > 1) {
if (res.back() != sieve[x])
res.push_back(sieve[x]);
x /= sieve[x];
}
return res;
}
map<ll, int> prime_divisors(ll x, int tmp = 0) {
map<ll, int> mp;
while (x > 1) {
mp[sieve[x]]++;
x /= sieve[x];
}
return mp;
}
};
int main() {
ll N;
cin >> N;
vector<ll> A(N);
for (ll i = 0; i < N; i++)
cin >> A[i];
sort(
A.begin(),
A.end()); // 82行目のbreakを入れないとTLEになるらしく,それならsortしないといけない
// const ll INF =1e6+1;// sortじゃなくてこっちがTLEの原因?
const ll INF = A.back() + 1;
vector<ll> vec(INF, 0);
for (ll i = 0; i < N; i++) {
for (ll j = 1; j * A[i] <= INF; j++) {
vec[A[i] * j]++;
// if(vec[A[i]*j] >= 2) break;// これいれたらWA?
}
}
ll ans = 0;
for (ll i = 0; i < N; i++) {
if (vec[A[i]] == 1)
ans++;
}
cout << ans << endl;
return 0;
}
| replace | 106 | 107 | 106 | 108 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int M = 1000005;
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
vector<int> cnt(M);
for (int x : a) {
// if (cnt[x] != 0) {
// cnt[x] = 2;
// continue;
// }
for (int i = x; i < M; i += x)
cnt[i]++;
}
int ans = 0;
for (int x : a) {
if (cnt[x] == 1)
ans++;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int M = 1000005;
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
vector<int> cnt(M);
for (int x : a) {
if (cnt[x] != 0) {
cnt[x] = 2;
continue;
}
for (int i = x; i < M; i += x)
cnt[i]++;
}
int ans = 0;
for (int x : a) {
if (cnt[x] == 1)
ans++;
}
cout << ans << endl;
return 0;
}
| replace | 15 | 19 | 15 | 19 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
int memo[1000010];
int all[1000010];
signed main() {
int n;
cin >> n;
int a[100010];
for (int i = 0; i < n; i++) {
cin >> a[i];
memo[a[i]]++;
}
for (int i = 1; i <= 1000000; i++) {
for (int j = i; j <= 1000000; j += i) {
all[j] += memo[i];
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
if (all[a[i]] == 1)
ans++;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
int memo[1000010];
int all[1000010];
signed main() {
int n;
cin >> n;
int a[200010];
for (int i = 0; i < n; i++) {
cin >> a[i];
memo[a[i]]++;
}
for (int i = 1; i <= 1000000; i++) {
for (int j = i; j <= 1000000; j += i) {
all[j] += memo[i];
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
if (all[a[i]] == 1)
ans++;
}
cout << ans << endl;
return 0;
}
| replace | 26 | 27 | 26 | 27 | 0 | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P, int> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 998244353;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
const int M = 1000001;
int n;
vi a;
bool b[M];
int main() {
cin >> n;
a = vi(n);
map<int, int> mp;
for (auto &i : a) {
cin >> i;
mp[i]++;
}
sort(a.begin(), a.end());
int t = 0;
for (auto i : a) {
if (mp[i] == 1 && !b[i])
t++;
if (!b[i]) {
int x = i;
while (x <= M)
b[x += i] = 1;
}
}
cout << t << endl;
} | #include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P, int> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 998244353;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
const int M = 1000001;
int n;
vi a;
bool b[M];
int main() {
cin >> n;
a = vi(n);
map<int, int> mp;
for (auto &i : a) {
cin >> i;
mp[i]++;
}
sort(a.begin(), a.end());
int t = 0;
for (auto i : a) {
if (mp[i] == 1 && !b[i])
t++;
if (!b[i]) {
int x = i;
while (x < M) {
b[x] = 1;
x += i;
}
}
}
cout << t << endl;
} | replace | 48 | 50 | 48 | 52 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
// マクロ&定数&関数 ================================================
typedef unsigned int uint;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;
typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vpint> vvpint;
typedef vector<vpll> vvpll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<vector<ll>>> vvvll;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = {0, 0, 1, -1, 1, 1, -1, -1, 0}; // 4;4近傍
const int DY[9] = {1, -1, 0, 0, 1, -1, 1, -1, 0}; // 8:8近傍 9:(0,0)を含む
const ll MOD = 1000000007; // 10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//---------------------------------------------------------------
// オーバーフローチェック
//---------------------------------------------------------------
bool is_overflow(ll a, ll b) { return ((a * b) / b != a); }
//---------------------------------------------------------------
// 約数列挙
//---------------------------------------------------------------
vll divisor(ll n) {
vll 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(begin(ret), end(ret));
return (ret);
}
//---------------------------------------------------------------
// N以下のすべての素数を列挙する(エラトステネスの篩)
//---------------------------------------------------------------
vbool searchSosuu(ll N) {
vbool sosuu;
for (ll i = 0; i < N; i++) {
sosuu.emplace_back(true);
}
sosuu[0] = false;
sosuu[1] = false;
for (ll i = 2; i < N; i++) {
if (sosuu[i]) {
for (ll j = 2; i * j < N; j++) {
sosuu[i * j] = false;
}
}
}
return sosuu;
}
//---------------------------------------------------------------
// 素因数分解 O(√N)
//---------------------------------------------------------------
vpll div_prime(ll n) {
vpll prime_factor;
for (ll i = 2; i * i <= n; i++) {
ll count = 0;
while (n % i == 0) {
count++;
n /= i;
}
if (count) {
pair<ll, ll> temp = {i, count};
prime_factor.emplace_back(temp);
}
}
if (n != 1) {
pair<ll, ll> temp = {n, 1};
prime_factor.emplace_back(temp);
}
return prime_factor;
}
//---------------------------------------------------------------
// 素数判定
//---------------------------------------------------------------
bool is_sosuu(ll N) {
if (N < 2)
return false;
else if (N == 2)
return true;
else if (N % 2 == 0)
return false;
for (ll i = 3; i <= sqrt(N); i += 2) {
if (N % i == 0)
return false;
}
return true;
}
//---------------------------------------------------------------
// 最大公約数(ユークリッドの互除法)
//---------------------------------------------------------------
ll gcd(ll a, ll b) {
if (a < b) {
ll tmp = a;
a = b;
b = tmp;
}
ll r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
//---------------------------------------------------------------
// 最小公倍数
//---------------------------------------------------------------
ll lcm(ll a, ll b) {
ll temp = gcd(a, b);
return temp * (a / temp) * (b / temp);
}
//---------------------------------------------------------------
// 階乗
//---------------------------------------------------------------
ll factorial(ll n) {
if (n <= 1)
return 1;
return (n * (factorial(n - 1))) % MOD;
}
//---------------------------------------------------------------
// 高速コンビネーション計算(前処理:O(N) 計算:O(1))
//---------------------------------------------------------------
// テーブルを作る前処理
ll comb_const = 200005;
vll fac(comb_const), finv(comb_const), inv(comb_const);
bool COMineted = false;
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i < comb_const; 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;
}
COMineted = true;
}
// 二項係数計算
ll COM(ll n, ll k) {
if (COMineted == false)
COMinit();
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//---------------------------------------------------------------
// 繰り返し2乗法 base^sisuu
//---------------------------------------------------------------
ll RepeatSquaring(ll base, ll sisuu) {
if (sisuu < 0) {
cout << "RepeatSquaring: 指数が負です!" << endl;
return 0;
}
if (sisuu == 0)
return 1;
if (sisuu % 2 == 0) {
ll t = RepeatSquaring(base, sisuu / 2) % MOD;
return (t * t) % MOD;
}
return base * RepeatSquaring(base, sisuu - 1) % MOD;
}
//---------------------------------------------------------------
// 高速単発コンビネーション計算(O(logN))
//---------------------------------------------------------------
ll fast_com(ll a, ll b) {
ll bunshi = 1;
ll bunbo = 1;
for (ll i = 1; i <= b; i++) {
bunbo *= i;
bunbo %= MOD;
bunshi *= (a - i + 1);
bunshi %= MOD;
}
ll ret = bunshi * RepeatSquaring(bunbo, MOD - 2);
ret %= MOD;
while (ret < 0) {
ret += MOD;
}
return ret;
}
//---------------------------------------------------------------
// 2直線の交差判定(直線(x1, y1)->(x2, y2) と 直線(X1, Y1)->(X2, Y2))
//---------------------------------------------------------------
bool is_cross(ll x1, ll y1, ll x2, ll y2, ll X1, ll Y1, ll X2, ll Y2) {
ll dx_ai = X1 - x1;
ll dy_ai = Y1 - y1;
ll dx_bi = X1 - x2;
ll dy_bi = Y1 - y2;
ll dx_ai2 = X2 - x1;
ll dy_ai2 = Y2 - y1;
ll dx_bi2 = X2 - x2;
ll dy_bi2 = Y2 - y2;
ll si = dx_ai * dy_bi - dy_ai * dx_bi;
ll si2 = dx_ai2 * dy_bi2 - dy_ai2 * dx_bi2;
ll si3 = dx_ai * dy_ai2 - dy_ai * dx_ai2;
ll si4 = dx_bi * dy_bi2 - dy_bi * dx_bi2;
return (si * si2 < 0 && si3 * si4 < 0);
}
//---------------------------------------------------------------
// 最長増加部分列の長さ(O(NlogN))
//---------------------------------------------------------------
ll LSI(vll vec) {
ll size = vec.size();
vll lsi(size + 1); // 長さjを作った時の右端の最小値
for (ll i = 0; i <= size; i++) {
lsi[i] = LLINF;
}
lsi[0] = 0;
lsi[1] = vec[0];
for (ll i = 1; i < size; i++) {
// 初めてvec[i]の方が小さくなるところを探す
auto Iter = lower_bound(lsi.begin(), lsi.end(), vec[i]);
ll idx = Iter - lsi.begin();
if (idx > 0 && lsi[idx - 1] < vec[i]) {
lsi[idx] = vec[i];
}
}
for (ll i = size; i >= 0; i--) {
if (lsi[i] < LLINF) {
return i;
}
}
}
//---------------------------------------------------------------
// 木の根からの深さ
//---------------------------------------------------------------
vll tree_depth(vvll edge, ll start_node, ll n_node) {
vll dist(n_node, LLINF);
dist[start_node] = 0;
stack<pll> S;
S.push({start_node, 0});
while (!S.empty()) {
ll node = S.top().first;
ll d = S.top().second;
dist[node] = d;
S.pop();
for (int i = 0; i < edge[node].size(); i++) {
if (dist[edge[node][i]] == LLINF) {
S.push({edge[node][i], d + 1});
}
}
}
return dist;
}
//---------------------------------------------------------------
// ワーシャルフロイド法(O(N^3)) 任意の2点間の最短距離
//---------------------------------------------------------------
vvll warshall_floyd(ll n, vvll d) {
for (int k = 0; k < n; k++) { // 経由する頂点
for (int i = 0; i < n; i++) { // 始点
for (int j = 0; j < n; j++) { // 終点
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
return d;
}
//---------------------------------------------------------------
// Union Find
//---------------------------------------------------------------
class UnionFind {
public:
/*
UnionFind uf(要素の個数);
for(int i = 0;i < 関係の個数; i++)
{
uf.merge(A[i], B[i]);
}
nを含む集合の大きさ = uf.size(n)
nを含む集合の代表者 = uf.root(n)
集合の個数 = uf.n_group
*/
vector<ll> par; // 各元の親を表す配列
vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)
ll n_group; // 集合の数
// Constructor
UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
for (ll i = 0; i < sz_; ++i)
par[i] = i; // 初期では親は自分自身
n_group = sz_;
}
void init(ll sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった
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 merge(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;
n_group--;
return true;
}
bool issame(ll x, ll y) { // 連結判定
return root(x) == root(y);
}
ll size(ll x) { // 素集合のサイズ
return siz[root(x)];
}
};
//========================================================================
int main() {
////==================================
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(30);
////==================================
/*
~思いついたことはとりあえず絶対メモする!!~
*/
ll N;
cin >> N;
vll A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
map<ll, ll> count;
for (int i = 0; i < N; i++) {
count[A[i]]++;
}
ll ans = 0;
for (int i = 0; i < N; i++) {
vll d = divisor(A[i]);
bool can = true;
for (int a : d) {
if (count[a] >= 1 && a != A[i]) {
can = false;
break;
}
}
if (count[A[i]] >= 2) {
can = false;
}
ans += can;
}
cout << ans;
} | #include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
// マクロ&定数&関数 ================================================
typedef unsigned int uint;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;
typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vpint> vvpint;
typedef vector<vpll> vvpll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<vector<ll>>> vvvll;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = {0, 0, 1, -1, 1, 1, -1, -1, 0}; // 4;4近傍
const int DY[9] = {1, -1, 0, 0, 1, -1, 1, -1, 0}; // 8:8近傍 9:(0,0)を含む
const ll MOD = 1000000007; // 10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//---------------------------------------------------------------
// オーバーフローチェック
//---------------------------------------------------------------
bool is_overflow(ll a, ll b) { return ((a * b) / b != a); }
//---------------------------------------------------------------
// 約数列挙
//---------------------------------------------------------------
vll divisor(ll n) {
vll 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(begin(ret), end(ret));
return (ret);
}
//---------------------------------------------------------------
// N以下のすべての素数を列挙する(エラトステネスの篩)
//---------------------------------------------------------------
vbool searchSosuu(ll N) {
vbool sosuu;
for (ll i = 0; i < N; i++) {
sosuu.emplace_back(true);
}
sosuu[0] = false;
sosuu[1] = false;
for (ll i = 2; i < N; i++) {
if (sosuu[i]) {
for (ll j = 2; i * j < N; j++) {
sosuu[i * j] = false;
}
}
}
return sosuu;
}
//---------------------------------------------------------------
// 素因数分解 O(√N)
//---------------------------------------------------------------
vpll div_prime(ll n) {
vpll prime_factor;
for (ll i = 2; i * i <= n; i++) {
ll count = 0;
while (n % i == 0) {
count++;
n /= i;
}
if (count) {
pair<ll, ll> temp = {i, count};
prime_factor.emplace_back(temp);
}
}
if (n != 1) {
pair<ll, ll> temp = {n, 1};
prime_factor.emplace_back(temp);
}
return prime_factor;
}
//---------------------------------------------------------------
// 素数判定
//---------------------------------------------------------------
bool is_sosuu(ll N) {
if (N < 2)
return false;
else if (N == 2)
return true;
else if (N % 2 == 0)
return false;
for (ll i = 3; i <= sqrt(N); i += 2) {
if (N % i == 0)
return false;
}
return true;
}
//---------------------------------------------------------------
// 最大公約数(ユークリッドの互除法)
//---------------------------------------------------------------
ll gcd(ll a, ll b) {
if (a < b) {
ll tmp = a;
a = b;
b = tmp;
}
ll r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
//---------------------------------------------------------------
// 最小公倍数
//---------------------------------------------------------------
ll lcm(ll a, ll b) {
ll temp = gcd(a, b);
return temp * (a / temp) * (b / temp);
}
//---------------------------------------------------------------
// 階乗
//---------------------------------------------------------------
ll factorial(ll n) {
if (n <= 1)
return 1;
return (n * (factorial(n - 1))) % MOD;
}
//---------------------------------------------------------------
// 高速コンビネーション計算(前処理:O(N) 計算:O(1))
//---------------------------------------------------------------
// テーブルを作る前処理
ll comb_const = 200005;
vll fac(comb_const), finv(comb_const), inv(comb_const);
bool COMineted = false;
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i < comb_const; 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;
}
COMineted = true;
}
// 二項係数計算
ll COM(ll n, ll k) {
if (COMineted == false)
COMinit();
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//---------------------------------------------------------------
// 繰り返し2乗法 base^sisuu
//---------------------------------------------------------------
ll RepeatSquaring(ll base, ll sisuu) {
if (sisuu < 0) {
cout << "RepeatSquaring: 指数が負です!" << endl;
return 0;
}
if (sisuu == 0)
return 1;
if (sisuu % 2 == 0) {
ll t = RepeatSquaring(base, sisuu / 2) % MOD;
return (t * t) % MOD;
}
return base * RepeatSquaring(base, sisuu - 1) % MOD;
}
//---------------------------------------------------------------
// 高速単発コンビネーション計算(O(logN))
//---------------------------------------------------------------
ll fast_com(ll a, ll b) {
ll bunshi = 1;
ll bunbo = 1;
for (ll i = 1; i <= b; i++) {
bunbo *= i;
bunbo %= MOD;
bunshi *= (a - i + 1);
bunshi %= MOD;
}
ll ret = bunshi * RepeatSquaring(bunbo, MOD - 2);
ret %= MOD;
while (ret < 0) {
ret += MOD;
}
return ret;
}
//---------------------------------------------------------------
// 2直線の交差判定(直線(x1, y1)->(x2, y2) と 直線(X1, Y1)->(X2, Y2))
//---------------------------------------------------------------
bool is_cross(ll x1, ll y1, ll x2, ll y2, ll X1, ll Y1, ll X2, ll Y2) {
ll dx_ai = X1 - x1;
ll dy_ai = Y1 - y1;
ll dx_bi = X1 - x2;
ll dy_bi = Y1 - y2;
ll dx_ai2 = X2 - x1;
ll dy_ai2 = Y2 - y1;
ll dx_bi2 = X2 - x2;
ll dy_bi2 = Y2 - y2;
ll si = dx_ai * dy_bi - dy_ai * dx_bi;
ll si2 = dx_ai2 * dy_bi2 - dy_ai2 * dx_bi2;
ll si3 = dx_ai * dy_ai2 - dy_ai * dx_ai2;
ll si4 = dx_bi * dy_bi2 - dy_bi * dx_bi2;
return (si * si2 < 0 && si3 * si4 < 0);
}
//---------------------------------------------------------------
// 最長増加部分列の長さ(O(NlogN))
//---------------------------------------------------------------
ll LSI(vll vec) {
ll size = vec.size();
vll lsi(size + 1); // 長さjを作った時の右端の最小値
for (ll i = 0; i <= size; i++) {
lsi[i] = LLINF;
}
lsi[0] = 0;
lsi[1] = vec[0];
for (ll i = 1; i < size; i++) {
// 初めてvec[i]の方が小さくなるところを探す
auto Iter = lower_bound(lsi.begin(), lsi.end(), vec[i]);
ll idx = Iter - lsi.begin();
if (idx > 0 && lsi[idx - 1] < vec[i]) {
lsi[idx] = vec[i];
}
}
for (ll i = size; i >= 0; i--) {
if (lsi[i] < LLINF) {
return i;
}
}
}
//---------------------------------------------------------------
// 木の根からの深さ
//---------------------------------------------------------------
vll tree_depth(vvll edge, ll start_node, ll n_node) {
vll dist(n_node, LLINF);
dist[start_node] = 0;
stack<pll> S;
S.push({start_node, 0});
while (!S.empty()) {
ll node = S.top().first;
ll d = S.top().second;
dist[node] = d;
S.pop();
for (int i = 0; i < edge[node].size(); i++) {
if (dist[edge[node][i]] == LLINF) {
S.push({edge[node][i], d + 1});
}
}
}
return dist;
}
//---------------------------------------------------------------
// ワーシャルフロイド法(O(N^3)) 任意の2点間の最短距離
//---------------------------------------------------------------
vvll warshall_floyd(ll n, vvll d) {
for (int k = 0; k < n; k++) { // 経由する頂点
for (int i = 0; i < n; i++) { // 始点
for (int j = 0; j < n; j++) { // 終点
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
return d;
}
//---------------------------------------------------------------
// Union Find
//---------------------------------------------------------------
class UnionFind {
public:
/*
UnionFind uf(要素の個数);
for(int i = 0;i < 関係の個数; i++)
{
uf.merge(A[i], B[i]);
}
nを含む集合の大きさ = uf.size(n)
nを含む集合の代表者 = uf.root(n)
集合の個数 = uf.n_group
*/
vector<ll> par; // 各元の親を表す配列
vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)
ll n_group; // 集合の数
// Constructor
UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
for (ll i = 0; i < sz_; ++i)
par[i] = i; // 初期では親は自分自身
n_group = sz_;
}
void init(ll sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった
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 merge(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;
n_group--;
return true;
}
bool issame(ll x, ll y) { // 連結判定
return root(x) == root(y);
}
ll size(ll x) { // 素集合のサイズ
return siz[root(x)];
}
};
//========================================================================
int main() {
////==================================
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(30);
////==================================
/*
~思いついたことはとりあえず絶対メモする!!~
*/
ll N;
cin >> N;
vll A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
vll count(1e6, 0);
for (int i = 0; i < N; i++) {
count[A[i]]++;
}
ll ans = 0;
for (int i = 0; i < N; i++) {
vll d = divisor(A[i]);
bool can = true;
for (int a : d) {
if (count[a] >= 1 && a != A[i]) {
can = false;
break;
}
}
if (count[A[i]] >= 2) {
can = false;
}
ans += can;
}
cout << ans;
} | replace | 431 | 432 | 431 | 432 | TLE | |
p02642 | C++ | Runtime Error | #include <algorithm>
#include <cmath> //sqrt
#include <functional>
#include <iomanip> //setprecision
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define MAX 100001
void _main() {
ll n;
cin >> n;
vector<ll> p(MAX, 0);
set<ll> s;
rep(i, n) {
ll a;
cin >> a;
p[a]++;
s.insert(a);
}
ll out = 0;
for (auto i : s) {
for (ll j = 2; j < MAX; j++) {
if (i * j >= MAX)
break;
p[i * j]++;
}
}
for (auto i : s) {
if (p[i] == 1)
out++;
}
cout << out << endl;
return;
}
int main() {
cout << fixed << setprecision(10);
_main();
return 0;
}
| #include <algorithm>
#include <cmath> //sqrt
#include <functional>
#include <iomanip> //setprecision
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define MAX 1000001
void _main() {
ll n;
cin >> n;
vector<ll> p(MAX, 0);
set<ll> s;
rep(i, n) {
ll a;
cin >> a;
p[a]++;
s.insert(a);
}
ll out = 0;
for (auto i : s) {
for (ll j = 2; j < MAX; j++) {
if (i * j >= MAX)
break;
p[i * j]++;
}
}
for (auto i : s) {
if (p[i] == 1)
out++;
}
cout << out << endl;
return;
}
int main() {
cout << fixed << setprecision(10);
_main();
return 0;
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int cnt[N];
int n, a[N / 10];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", a + i), cnt[a[i]]++;
for (int i = 1; i < N; i++)
if (cnt[i]) {
for (int j = i + i; j < N; j += i) {
cnt[j] += cnt[i];
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
ans += cnt[a[i]] == 1;
}
printf("%d\n", ans);
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int cnt[N];
int n, a[N / 5];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", a + i), cnt[a[i]]++;
for (int i = 1; i < N; i++)
if (cnt[i]) {
for (int j = i + i; j < N; j += i) {
cnt[j] += cnt[i];
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
ans += cnt[a[i]] == 1;
}
printf("%d\n", ans);
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n, a[233333], vis[233333], ans;
int main() {
ios::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i], vis[a[i]]++;
for (int i = 1; i <= n; i++) {
int flg = 1;
for (int j = 1; j * j <= a[i]; j++)
if (a[i] % j == 0) {
if (j != a[i] && vis[j] || j == a[i] && vis[j] > 1 ||
a[i] / j != a[i] && vis[a[i] / j] ||
a[i] / j == a[i] && vis[a[i] / j] > 1) {
flg = 0;
break;
}
}
if (flg)
ans++;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int n, a[2333333], vis[2333333], ans;
int main() {
ios::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i], vis[a[i]]++;
for (int i = 1; i <= n; i++) {
int flg = 1;
for (int j = 1; j * j <= a[i]; j++)
if (a[i] % j == 0) {
if (j != a[i] && vis[j] || j == a[i] && vis[j] > 1 ||
a[i] / j != a[i] && vis[a[i] / j] ||
a[i] / j == a[i] && vis[a[i] / j] > 1) {
flg = 0;
break;
}
}
if (flg)
ans++;
}
cout << ans << endl;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXI = 1001;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
vector<int> inc(MAXI, 0);
for (int i = 0; i < n; ++i) {
cin >> a[i];
++inc[a[i]];
}
if (inc[1] > 0) {
if (inc[1] > 1) {
cout << "0\n";
} else {
cout << "1\n";
}
return 0;
}
int cou = 0;
for (ll i = 2; i < MAXI; ++i) {
if (inc[i] == 0) {
continue;
}
if (inc[i] == 1) {
++cou;
}
for (ll j = i + i; j < MAXI; j += i) {
inc[j] = 0;
}
}
cout << cou << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXI = 1000001;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
vector<int> inc(MAXI, 0);
for (int i = 0; i < n; ++i) {
cin >> a[i];
++inc[a[i]];
}
if (inc[1] > 0) {
if (inc[1] > 1) {
cout << "0\n";
} else {
cout << "1\n";
}
return 0;
}
int cou = 0;
for (ll i = 2; i < MAXI; ++i) {
if (inc[i] == 0) {
continue;
}
if (inc[i] == 1) {
++cou;
}
for (ll j = i + i; j < MAXI; j += i) {
inc[j] = 0;
}
}
cout << cou << "\n";
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
int a[100009], cnt[1000009];
int main() {
int n, i, j;
cin >> n;
for (i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
for (i = 0; i < n; i++) {
if (cnt[a[i]] != 0) {
cnt[a[i]] = 2;
continue;
}
for (j = 1; a[i] * j <= a[n - 1]; j++)
cnt[a[i] * j]++;
}
int ans = 0;
for (i = 0; i < n; i++) {
if (cnt[a[i]] == 1)
ans++;
}
cout << ans;
}
| #include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
int a[200009], cnt[1000009];
int main() {
int n, i, j;
cin >> n;
for (i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
for (i = 0; i < n; i++) {
if (cnt[a[i]] != 0) {
cnt[a[i]] = 2;
continue;
}
for (j = 1; a[i] * j <= a[n - 1]; j++)
cnt[a[i] * j]++;
}
int ans = 0;
for (i = 0; i < n; i++) {
if (cnt[a[i]] == 1)
ans++;
}
cout << ans;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
void solveBruteForce() {}
void solveOptimized() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
int divisible[1000001];
for (int i = 1; i < 1000001; i++)
divisible[i] = 0;
divisible[0] = 1;
for (int i = 0; i < n; i++) {
int j = a[i];
while (j < 1000001) {
divisible[j]++;
j += a[i];
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
if (divisible[a[i]] <= 1)
ans++;
}
cout << ans;
}
void solve() {
// solveBruteForce();
solveOptimized();
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
void solveBruteForce() {}
void solveOptimized() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
int divisible[1000001];
for (int i = 1; i < 1000001; i++)
divisible[i] = 0;
divisible[0] = 1;
for (int i = 0; i < n; i++) {
int j = a[i];
if (divisible[j] < 2) {
while (j < 1000001) {
divisible[j]++;
j += a[i];
}
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
if (divisible[a[i]] <= 1)
ans++;
}
cout << ans;
}
void solve() {
// solveBruteForce();
solveOptimized();
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
| replace | 29 | 33 | 29 | 34 | TLE | |
p02642 | C++ | Time Limit Exceeded | #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T> using V = vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
const ll inf = (1e18);
const ll mod = 998244353;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }
struct __INIT {
__INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} __init;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
ll n;
cin >> n;
V<ll> a(n);
map<ll, ll> mp;
map<ll, bool> d;
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
d[a[i]] = true;
}
ll ans = 0;
for (auto p : mp) {
if (d[p.fi] && p.se == 1)
ans++;
for (ll i = 2; i * p.fi <= (1e6); i++) {
if (mp.count(i * p.fi)) {
d[i * p.fi] = false;
}
}
}
cout << ans << "\n";
}
| #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T> using V = vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
const ll inf = (1e18);
const ll mod = 998244353;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }
struct __INIT {
__INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} __init;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
ll n;
cin >> n;
V<ll> a(n);
map<ll, ll> mp;
map<ll, bool> d;
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
d[a[i]] = true;
}
ll ans = 0;
for (auto p : mp) {
if (!d[p.fi])
continue;
if (p.se == 1)
ans++;
for (ll i = 2; i * p.fi <= (1e6); i++) {
if (mp.count(i * p.fi)) {
d[i * p.fi] = false;
}
}
}
cout << ans << "\n";
}
| replace | 47 | 48 | 47 | 50 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順
int main() {
int N;
cin >> N;
vector<int> A(N);
rep(i, N) { cin >> A.at(i); }
sort(A.begin(), A.end());
ll res = 0;
vector<bool> B(N, false);
for (int i = 0; i < N; i++) {
if (B[i])
continue;
while (i < N - 1 && A[i] == A[i + 1]) {
B[i] = true;
B[i + 1] = true;
i++;
}
int x = A[i] * 2;
while (x <= A[N - 1]) {
auto y = lower_bound(A.begin(), A.end(), x);
if (*y == x) {
int d = y - A.begin();
B[d] = true;
for (y++, d++; y != A.end(); y++, d++) {
if (*y == x) {
B[d] = true;
}
}
}
x += A[i];
}
}
rep(i, N) {
if (!B[i])
res++;
}
cout << res << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順
int main() {
int N;
cin >> N;
vector<int> A(N);
rep(i, N) { cin >> A.at(i); }
sort(A.begin(), A.end());
ll res = 0;
vector<bool> B(N, false);
for (int i = 0; i < N; i++) {
if (B[i])
continue;
while (i < N - 1 && A[i] == A[i + 1]) {
B[i] = true;
B[i + 1] = true;
i++;
}
int x = A[i] * 2;
while (x <= A[N - 1]) {
auto y = lower_bound(A.begin(), A.end(), x);
if (*y == x) {
int d = y - A.begin();
B[d] = true;
while (d < N - 1 && A[d] == A[d + 1])
B[++d] = true;
}
x += A[i];
}
}
rep(i, N) {
if (!B[i])
res++;
}
cout << res << endl;
}
| replace | 28 | 33 | 28 | 30 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
const int M = 1000005;
int N;
cin >> N;
vector<int> A(N);
rep(i, N) cin >> A[i];
vector<int> C(M);
rep(i, M) C[i] = 0;
for (int x : A) {
for (int j = x; j < M; j += x) {
C[j] = C[j] + 1;
}
}
int ans = 0;
for (int x : A) {
if (C[x] == 1)
ans++;
}
cout << ans << endl;
return 0;
}
| #include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
const int M = 1000005;
int N;
cin >> N;
vector<int> A(N);
rep(i, N) cin >> A[i];
vector<int> C(M);
rep(i, M) C[i] = 0;
for (int x : A) {
if (C[x] == 1) {
C[x] = 2;
continue;
}
if (C[x] != 0)
continue;
for (int j = x; j < M; j += x) {
C[j] = C[j] + 1;
}
}
int ans = 0;
for (int x : A) {
if (C[x] == 1)
ans++;
}
cout << ans << endl;
return 0;
}
| insert | 14 | 14 | 14 | 20 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define CIN \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
#define TEST_CASE(t) for (int zz = 1; zz <= t; zz++)
#define PRINT_CASE printf("Case %d: ", zz)
#define Debug(x) cout << #x " = " << (x) << endl
const int maxn = (int)1e5 + 5;
typedef long long ll;
int cnt[maxn];
void solve() {
int n;
cin >> n;
int a[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int ans = 0;
for (int i = 1; i <= n; i++) {
if (cnt[a[i]]) {
cnt[a[i]] = 2;
continue;
}
int val = a[i];
for (int j = val; j < maxn; j += (val)) {
cnt[j]++;
}
}
for (int i = 1; i <= n; i++) {
if (cnt[a[i]] <= 1)
ans++;
}
cout << ans << endl;
}
int main() {
CIN
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// cout << "Fi Amanillah" << endl;
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define CIN \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
#define TEST_CASE(t) for (int zz = 1; zz <= t; zz++)
#define PRINT_CASE printf("Case %d: ", zz)
#define Debug(x) cout << #x " = " << (x) << endl
const int maxn = (int)1e6 + 5;
typedef long long ll;
int cnt[maxn];
void solve() {
int n;
cin >> n;
int a[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int ans = 0;
for (int i = 1; i <= n; i++) {
if (cnt[a[i]]) {
cnt[a[i]] = 2;
continue;
}
int val = a[i];
for (int j = val; j < maxn; j += (val)) {
cnt[j]++;
}
}
for (int i = 1; i <= n; i++) {
if (cnt[a[i]] <= 1)
ans++;
}
cout << ans << endl;
}
int main() {
CIN
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// cout << "Fi Amanillah" << endl;
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
sort(all(a));
vector<bool> ng(1000001, false);
rep(i, n) {
if (i == 0)
continue;
if (a[i] == a[i - 1])
ng[a[i]] = true;
}
vector<bool> dp(1000001, true);
for (int i : a) {
if (dp[i]) {
int x = i * 2;
while (x <= 1000000) {
dp[x] = false;
x += i;
}
}
}
int ans = 0;
for (int i : a) {
if (dp[i] && (!ng[i]))
ans++;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
sort(all(a));
vector<bool> ng(1000001, false);
rep(i, n) {
if (i == 0)
continue;
if (a[i] == a[i - 1])
ng[a[i]] = true;
}
vector<bool> dp(1000001, true);
for (int i : a) {
if (dp[i]) {
int x = i;
if (!ng[i])
x += i;
while (x <= 1000000) {
dp[x] = false;
x += i;
}
}
}
int ans = 0;
for (int i : a) {
if (dp[i] && (!ng[i]))
ans++;
}
cout << ans << endl;
} | replace | 26 | 27 | 26 | 29 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define fast \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define PB push_back
#define MP make_pair
#define F first
#define S second
int dp[1000006];
int b[1000006];
int main() {
int n;
cin >> n;
int a[100005];
int count = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[a[i]]++;
}
for (int i = 1; i < 1000006; i++) {
if (b[i] != 0) {
for (int j = 2 * i; j < 1000006; j += i) {
dp[j] = 1;
}
}
}
for (int i = 0; i < n; i++) {
if (b[a[i]] > 1) {
continue;
}
if (dp[a[i]] == 0) {
count++;
}
}
cout << count;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define fast \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define PB push_back
#define MP make_pair
#define F first
#define S second
int dp[1000006];
int b[1000006];
int main() {
int n;
cin >> n;
int a[200005];
int count = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[a[i]]++;
}
for (int i = 1; i < 1000006; i++) {
if (b[i] != 0) {
for (int j = 2 * i; j < 1000006; j += i) {
dp[j] = 1;
}
}
}
for (int i = 0; i < n; i++) {
if (b[a[i]] > 1) {
continue;
}
if (dp[a[i]] == 0) {
count++;
}
}
cout << count;
return 0;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
#define endl "\n";
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
ll const inf = 1e18;
ll const maxn = 1e6 + 5;
ll const mod = 1e9 + 7;
// code begins here
int main() {
fast;
ll n;
cin >> n;
vector<ll> arr(n);
for (auto &u : arr)
cin >> u;
vector<ll> cnt(maxn, 0), cnt1(maxn, 0);
set<ll> s;
for (ll i = 0; i < n; i++) {
cnt1[arr[i]]++;
if (s.count(arr[i]))
continue;
for (ll j = arr[i]; j < maxn; j += arr[i]) {
cnt[j]++;
}
}
ll ans = 0;
for (ll i = 0; i < n; i++) {
if (cnt[arr[i]] == 1 && cnt1[arr[i]] == 1)
ans++;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
#define endl "\n";
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
ll const inf = 1e18;
ll const maxn = 1e6 + 5;
ll const mod = 1e9 + 7;
// code begins here
int main() {
fast;
ll n;
cin >> n;
vector<ll> arr(n);
for (auto &u : arr)
cin >> u;
vector<ll> cnt(maxn, 0), cnt1(maxn, 0);
set<ll> s;
for (ll i = 0; i < n; i++) {
cnt1[arr[i]]++;
if (s.count(arr[i]))
continue;
for (ll j = arr[i]; j < maxn; j += arr[i]) {
cnt[j]++;
}
s.insert(arr[i]);
}
ll ans = 0;
for (ll i = 0; i < n; i++) {
if (cnt[arr[i]] == 1 && cnt1[arr[i]] == 1)
ans++;
}
cout << ans << endl;
return 0;
}
| insert | 39 | 39 | 39 | 40 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
#define debug(a) cout << #a ": " << a << endl
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
const int M = 1e6 + 7;
int a[N], b[M];
int main(void) {
IOS;
int n;
cin >> n;
int mx = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
mx = max(mx, a[i]);
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i) {
if (a[i] == a[i - 1]) {
b[a[i]] = 1;
}
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
if (!b[a[i]])
ans++;
for (int j = a[i] + a[i]; j <= mx; j += a[i]) {
b[j] = 1;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define debug(a) cout << #a ": " << a << endl
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
const int N = 2e5 + 7;
const int M = 1e6 + 7;
int a[N], b[M];
int main(void) {
IOS;
int n;
cin >> n;
int mx = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
mx = max(mx, a[i]);
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i) {
if (a[i] == a[i - 1]) {
b[a[i]] = 1;
}
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
if (!b[a[i]])
ans++;
for (int j = a[i] + a[i]; j <= mx; j += a[i]) {
b[j] = 1;
}
}
cout << ans << endl;
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int c[1000006];
vector<int> V;
set<int> S;
multiset<int> T;
int N, A[200005];
int dp[200005];
int main(void) {
cin >> N;
int Am = 0;
for (int i = 1; i <= N; i++) {
cin >> A[i];
V.push_back(A[i]);
S.insert(A[i]);
T.insert(A[i]);
Am = max(Am, A[i]);
}
// sort(V.begin(), V.end());
for (auto y : V) {
if (c[y] >= 1) {
c[y] = 2;
} else if (c[y] >= 0) {
c[y]++;
for (long long int j = y * 2; j <= Am; j += y) {
c[(int)j] = -1;
}
}
}
int ans = 0;
for (int i = 1; i <= N; i++) {
if (T.count(A[i]) >= 2) {
continue;
}
if (c[A[i]] == 1) {
ans++;
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int c[1000006];
vector<int> V;
set<int> S;
multiset<int> T;
int N, A[200005];
int dp[200005];
int main(void) {
cin >> N;
int Am = 0;
for (int i = 1; i <= N; i++) {
cin >> A[i];
V.push_back(A[i]);
S.insert(A[i]);
T.insert(A[i]);
Am = max(Am, A[i]);
}
// sort(V.begin(), V.end());
for (auto y : V) {
if (c[y] >= 1) {
c[y] = 2;
} else if (c[y] >= 0) {
c[y]++;
for (long long int j = y * 2; j <= Am; j += y) {
c[(int)j] = -1;
}
}
}
int ans = 0;
for (int i = 1; i <= N; i++) {
// if (T.count(A[i]) >= 2) { continue; }
if (c[A[i]] == 1) {
ans++;
}
}
cout << ans << endl;
return 0;
} | replace | 43 | 46 | 43 | 44 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int c[1000006];
vector<int> V;
set<int> S;
multiset<int> T;
int N, A[200005];
int dp[200005];
int num[1000006];
int main(void) {
cin >> N;
int Am = 0;
for (int i = 1; i <= N; i++) {
cin >> A[i];
V.push_back(A[i]);
S.insert(A[i]);
T.insert(A[i]);
Am = max(Am, A[i]);
num[A[i]]++;
}
// sort(V.begin(), V.end());
for (auto y : V) {
if (c[y] >= 1) {
c[y] = 2;
} else if (c[y] >= 0) {
c[y]++;
for (long long int j = y * 2; j <= Am; j += y) {
c[(int)j] = -1;
}
}
}
int ans = 0;
for (int i = 1; i <= N; i++) {
int u = A[i];
if (T.count(u) >= 2) {
continue;
}
// else if (c[u] == 1) { ans++; }
}
for (int i = 1; i <= N; i++) {
// if (T.count(A[i]) >= 2) { continue; }
if (c[A[i]] == 1) {
ans++;
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int c[1000006];
vector<int> V;
set<int> S;
multiset<int> T;
int N, A[200005];
int dp[200005];
int num[1000006];
int main(void) {
cin >> N;
int Am = 0;
for (int i = 1; i <= N; i++) {
cin >> A[i];
V.push_back(A[i]);
S.insert(A[i]);
T.insert(A[i]);
Am = max(Am, A[i]);
num[A[i]]++;
}
// sort(V.begin(), V.end());
for (auto y : V) {
if (c[y] >= 1) {
c[y] = 2;
} else if (c[y] >= 0) {
c[y]++;
for (long long int j = y * 2; j <= Am; j += y) {
c[(int)j] = -1;
}
}
}
int ans = 0;
for (int i = 1; i <= N; i++) {
int u = A[i];
if (T.count(u) >= 2) { /*continue;*/
}
// else if (c[u] == 1) { ans++; }
}
for (int i = 1; i <= N; i++) {
// if (T.count(A[i]) >= 2) { continue; }
if (c[A[i]] == 1) {
ans++;
}
}
cout << ans << endl;
return 0;
} | replace | 47 | 49 | 47 | 48 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
void fast() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main() {
fast();
int n, a[200005], b[200005], j, i, ans = 0;
cin >> n;
for (i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
for (i = 0; i <= a[n - 1]; i++)
b[i] = 1;
for (i = 0; i < n; i++)
if (b[a[i]])
for (j = a[i] * 2; j <= a[n - 1]; j += a[i])
b[j] = 0;
for (i = 0; i < n - 1; i++)
if (a[i] == a[i + 1])
b[a[i]] = 0;
for (i = 0; i < n; i++)
if (b[a[i]])
++ans;
cout << ans << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
void fast() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main() {
fast();
int n, a[200005], b[1000005], j, i, ans = 0;
cin >> n;
for (i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
for (i = 0; i <= a[n - 1]; i++)
b[i] = 1;
for (i = 0; i < n; i++)
if (b[a[i]])
for (j = a[i] * 2; j <= a[n - 1]; j += a[i])
b[j] = 0;
for (i = 0; i < n - 1; i++)
if (a[i] == a[i + 1])
b[a[i]] = 0;
for (i = 0; i < n; i++)
if (b[a[i]])
++ans;
cout << ans << "\n";
return 0;
} | replace | 9 | 10 | 9 | 10 | 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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
long n;
cin >> n;
vector<long> a(n);
map<long, long> b;
vector<long> c[1001001];
rep(i, n) {
cin >> a.at(i);
b[a.at(i)]++;
for (long j = 1; j * j <= a.at(i); j++) {
if (a.at(i) % j == 0) {
c[i].push_back(j);
c[i].push_back(a.at(i) / j);
}
}
}
int ans = 0;
rep(i, n) {
bool ex = true;
rep(j, c[i].size()) {
if ((c[i].at(j) != a.at(i) && b[c[i].at(j)] > 0) ||
(c[i].at(j) == a.at(i) && b[c[i].at(j)] > 1)) {
ex = false;
}
}
if (ex) {
ans++;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
long n;
cin >> n;
vector<long> a(n);
vector<long> b(1001001);
vector<long> c[1001001];
rep(i, n) {
cin >> a.at(i);
b[a.at(i)]++;
for (long j = 1; j * j <= a.at(i); j++) {
if (a.at(i) % j == 0) {
c[i].push_back(j);
c[i].push_back(a.at(i) / j);
}
}
}
int ans = 0;
rep(i, n) {
bool ex = true;
rep(j, c[i].size()) {
if ((c[i].at(j) != a.at(i) && b[c[i].at(j)] > 0) ||
(c[i].at(j) == a.at(i) && b[c[i].at(j)] > 1)) {
ex = false;
}
}
if (ex) {
ans++;
}
}
cout << ans << endl;
}
| replace | 9 | 10 | 9 | 10 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long int ll;
typedef pair<int, int> P;
int main() {
int n;
cin >> n;
int max_a = 202020;
vector<int> s(max_a * 2, 0);
vector<int> a(n);
rep(i, n) cin >> a[i];
sort(a.begin(), a.end());
rep(i, n) s[a[i]] = 1;
rep(i, n - 1) if (a[i] == a[i + 1]) s[a[i]] = 2;
for (int i = 1; i <= max_a; i++) {
if (s[i] == 0)
continue;
for (int j = i + i; j <= max_a; j += i) {
if (s[j] == 1)
s[j] = 2;
}
}
int ans = 0;
for (int i = 0; i <= max_a; i++) {
if (s[i] == 1)
ans++;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long int ll;
typedef pair<int, int> P;
int main() {
int n;
cin >> n;
int max_a = 2020202;
vector<int> s(max_a * 2, 0);
vector<int> a(n);
rep(i, n) cin >> a[i];
sort(a.begin(), a.end());
rep(i, n) s[a[i]] = 1;
rep(i, n - 1) if (a[i] == a[i + 1]) s[a[i]] = 2;
for (int i = 1; i <= max_a; i++) {
if (s[i] == 0)
continue;
for (int j = i + i; j <= max_a; j += i) {
if (s[j] == 1)
s[j] = 2;
}
}
int ans = 0;
for (int i = 0; i <= max_a; i++) {
if (s[i] == 1)
ans++;
}
cout << ans << endl;
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long int ll;
typedef pair<int, int> P;
int main() {
int n;
cin >> n;
int MAX_A = 202020;
vector<int> a(MAX_A + 1, 0);
rep(i, n) {
int t;
cin >> t;
a[t]++;
}
for (int i = 1; i <= MAX_A; i++) {
if (a[i] == 0)
continue;
for (int j = i + i; j <= MAX_A; j += i) {
a[j] = 2;
}
}
int ans = 0;
for (int i = 1; i <= MAX_A; i++) {
if (a[i] == 1)
ans++;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long int ll;
typedef pair<int, int> P;
int main() {
int n;
cin >> n;
int MAX_A = 2020202;
vector<int> a(MAX_A + 1, 0);
rep(i, n) {
int t;
cin >> t;
a[t]++;
}
for (int i = 1; i <= MAX_A; i++) {
if (a[i] == 0)
continue;
for (int j = i + i; j <= MAX_A; j += i) {
a[j] = 2;
}
}
int ans = 0;
for (int i = 1; i <= MAX_A; i++) {
if (a[i] == 1)
ans++;
}
cout << ans << endl;
return 0;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define join(a, d) \
accumulate(a.begin() + 1, a.end(), a[0], \
[](string s, string t) { return s + d + t; })
#define all(a) a.begin(), a.end()
// #define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;
int main(void) {
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vector<int> A(N);
rep(i, 0, N) cin >> A[i];
vector<int> nums(1000001, 0);
rep(i, 0, N) {
int j = 1;
int n = A[i];
while (n <= 1000000) {
nums[n] += j;
++j;
n = A[i] * j;
}
}
int ans = 0;
rep(i, 0, N) {
if (nums[A[i]] < 2) {
++ans;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define join(a, d) \
accumulate(a.begin() + 1, a.end(), a[0], \
[](string s, string t) { return s + d + t; })
#define all(a) a.begin(), a.end()
// #define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;
int main(void) {
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vector<int> A(N);
rep(i, 0, N) cin >> A[i];
vector<int> nums(1000001, 0);
rep(i, 0, N) {
int j = 1;
int n = A[i];
while (n <= 1000000) {
nums[n] += 1;
if (j == 1 && nums[n] > 1)
break;
++j;
n = A[i] * j;
}
}
int ans = 0;
rep(i, 0, N) {
if (nums[A[i]] < 2) {
++ans;
}
}
cout << ans << endl;
return 0;
}
| replace | 31 | 32 | 31 | 34 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
const double PI = acos(-1);
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = ll(1e9 + 7);
const ll INF = ll(1e18) + 7;
// repetition
#define REP(i, n) for (ll i = 0; i < n; i++)
#define RREP(i, n) for (ll i = n; i != 0; i--)
ll gcd(ll a, ll b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
unsigned getDigit(unsigned num) {
unsigned digit = 0;
while (num != 0) {
num /= 10;
digit++;
}
return digit;
}
unsigned binarySearch(ll target, ll max, ll min) {
while ((max - min) > 1) {
if ((max + min) / 2 > target) {
max = (max + min) / 2;
min = min;
} else {
max = max;
min = (max + min) / 2;
}
}
}
void f(int rest, string s) {
char abc[] = "abc";
if (rest == 0) {
cout << s << endl;
} else {
for (int i = 0; i < 3; i++) {
f(rest - 1, s + abc[i]);
}
}
}
/*
int main() {
// n,m->size, k-> value
// vector<vector<ll>> a(n ,vector<ll>(m, k));
// vector
// vector<ll> s(n,0);
// vector<vector<ll>> v;
// map<ll,ll> m;
// priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
pq;
// vector<pair<ll, ll>> epv(n, {0, 0});
// vector<vector<char>> v(h, vector<char>(w));
for(auto&& m: em) {
epv.push_back({ m.second, m.first });
}
ll n, k, a;
cin >> n >> k;
vector<ll> vp;
vector<ll> vn;
ll c = 0;
REP(i, n) {
cin >> a;
if(a >= 0 ) vp.push_back(a);
else vn.push_back(a);
}
sort(vp.begin(), vp.end());
sort(vn.begin(), vn.end());
ll ps = vp.size();
ll ns = vn.size();
cout << "k: " << k << endl;
cout << "ps: " << ps << endl;
cout << "ns: " << ns << endl;
if(k < ps * ns) {
ll m = k%ns;
ll d = k - (m+1);
cout << vn[m] * vp[d] << endl;
}else {
ll kd = k - ps*ns;
ll md = kd%ps;
ll dd = kd - md;
ll s = 0;
REP(i, ps) {
s = s+(ps-i-1);
cout << "s: " << s << endl;
cout << "kd: " << kd << endl;
cout << "s: " << s << endl;
cout << "kd: " << kd << endl;
cout << "i: " << i << endl;
if(s > kd) {
cout << "vp[i]: " << vp[i] << endl;
cout << "vp[ps-i]: " << vp[s-kd+i-1] << endl;
cout << vp[i] * vp[s-kd+i-1] << endl;
break;
}
}
}
}
ll h, w;
vector<vector<char>> v;
vector<ll> dx = {-1, 0, 1, 0};
vector<ll> dy = {0, -1, 0, 1};
ll bfs(ll ox, ll oy) {
vector<vector<ll>> vd(h, vector<ll>(w, -1));
queue<pair<ll, ll>> q;
q.push({ox, oy});
vd[oy][ox] = 0;
ll res = 0;
while(!q.empty()) {
pair<ll, ll> vn = q.front();
q.pop();
res = max(res, vd[vn.second][vn.first]);
for(ll i = 0; i < 4; i++){
ll nx = vn.first +dx[i];
ll ny = vn.second + dy[i];
if(nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
if(v[ny][nx] == '#') continue;
if(vd[ny][nx] == -1) {
vd[ny][nx] = res + 1;
q.push({nx, ny});
}
}
}
return res;
}
bool kai(string s) {
bool flg = true;
ll n = s.size();
for(ll i=0; i<n/2; i++) {
if(s[i] == s[n-1 -i]){
flg = true;
} else {
flg = false;
break;
}
}
return flg;
}
*/
struct UnionFind {
vector<ll> par;
map<ll, ll> s;
UnionFind(ll n) : par(n) {
REP(i, n) {
par[i] = i;
s[i]++;
}
}
ll root(ll x) {
if (par[x] == x)
return x;
return root(par[x]);
}
void unite(ll x, ll y) {
ll rx = root(x);
ll ry = root(y);
if (rx == ry)
return;
if (size(rx) > size(ry)) {
s[rx] = s[rx] + s[ry];
par[root(y)] = rx;
} else {
s[ry] = s[ry] + s[rx];
par[root(x)] = ry;
}
}
bool same(ll x, ll y) { return root(x) == root(y); }
ll size(ll x) { return s[root(x)]; }
};
// base^{exp}%mod
ll mod_pow(ll base, ll exp, ll mod) {
if (exp == 1)
return base % mod;
if (exp % 2 == 1)
return (base * mod_pow(base, exp - 1, mod)) % mod;
ll t = mod_pow(base, exp / 2, mod);
return (t * t) % mod;
}
// nPr
ll mod_permutation(ll n, ll r) {
ll t = 1;
while (r != 0) {
t = (t % MOD) * (n % MOD);
n--;
r--;
}
return t;
}
ll mod_factorial(ll r) {
ll v = 1;
while (r != 0) {
v = (v % MOD) * (r % MOD);
r--;
}
return v;
}
vector<ll> prime_factorization(ll n) {
vector<ll> P;
ll nn = sqrt(n) + 2;
vector<ll> prime(nn + 1, true);
for (ll i = 2; i <= nn; i++) {
if (prime[i]) {
for (ll j = 2 * i; j <= nn; j += i) {
prime[j] = false;
}
P.emplace_back(i);
}
}
vector<ll> d;
REP(i, P.size()) {
while (n % P[i] == 0) {
d.push_back(P[i]);
n /= P[i];
}
}
if (n > nn)
d.push_back(n);
return d;
}
vector<ll> sieve(ll n) {
vector<ll> P;
ll nn = sqrt(n) + 2;
vector<ll> prime(nn + 1, true);
for (ll i = 2; i <= nn; i++) {
if (prime[i]) {
for (ll j = 2 * i; j <= nn; j += i) {
prime[j] = false;
}
P.emplace_back(i);
}
}
return P;
}
bool is_prime(ll n) {
ll nn = sqrt(n) + 2;
vector<ll> prime(nn + 1, true);
if (n % 2 == 0) {
return false;
}
vector<ll> primes = sieve(nn);
REP(i, primes.size()) {
if (n % primes[i] == 0) {
return false;
}
}
return true;
}
struct Node {
vector<ll> edges;
vector<ll> costs;
bool done;
ll cost;
friend bool operator<(const Node &lhs, const Node &rhs) {
return rhs.cost < lhs.cost;
}
};
ll mod_conb(ll n, ll r, ll mod) {
return (mod_factorial(n) / mod_factorial(n - r) / mod_factorial(r)) % mod;
}
vector<vector<ll>> vv;
ll c = 0;
vector<ll> v;
ll n, m, q;
// indexからmまでのn桁の数列の列挙
void dfs2(ll index, ll count) {
if (count < n) {
for (ll i = index; i <= m; i++) {
v[count] = i;
dfs2(i, count + 1);
}
} else {
vv.push_back(v);
}
}
ll total(vector<ll> v) {
ll t = 0;
REP(i, v.size()) { t += v[i]; }
return t;
}
// vector<ll> dx = {-1, 0, 1, 0};
// vector<ll> dy = {0, -1, 0, 1};
// void dfs(ll oy, ll ox, ll color) {
// hw[oy][ox] = color;
// seen[oy][ox] = true;
// for(ll i = 0; i < 4; i++){
// ll ny = oy + dy[i];
// ll nx = ox + dx[i];
// if(nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
// if(seen[ny][nx] == false) {
// ll co = qa.top();
// qa.pop();
// dfs(ny, nx, co);
// }
// }
// }
// std::ifstream in("sub1_06.txt");
// std::cin.rdbuf(in.rdbuf());
/*
ll bfs(ll ox, ll oy) {
vector<vector<ll>> vd(h, vector<ll>(w, -1));
queue<pair<ll, ll>> q;
q.push({ox, oy});
vd[oy][ox] = 0;
ll res = 0;
while(!q.empty()) {
pair<ll, ll> vn = q.front();
q.pop();
res = max(res, vd[vn.second][vn.first]);
for(ll i = 0; i < 4; i++){
ll nx = vn.first +dx[i];
ll ny = vn.second + dy[i];
if(nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
if(v[ny][nx] == '#') continue;
if(vd[ny][nx] == -1) {
vd[ny][nx] = res + 1;
q.push({nx, ny});
}
}
}
return res;
}
*/
void Sieve(ll n) {
vector<bool> flags(n, true);
flags[0] = false;
flags[1] = false;
const ll sqrt_n = ceil(sqrt(n) + 0.1);
for (ll p = 2; p < sqrt_n; ++p) {
if (!flags[p])
continue;
for (ll mult = p * p; mult < n; mult += p)
flags[mult] = false;
}
}
int main() {
std::ifstream in("01-Handmade-00");
std::cin.rdbuf(in.rdbuf());
ll n;
cin >> n;
ll a;
vector<bool> s(10000000, false);
vector<bool> sd(10000000, false);
vector<ll> ar;
REP(i, n) {
cin >> a;
ar.push_back(a);
}
sort(ar.begin(), ar.end());
ll min = ar[0];
ll max = ar[ar.size() - 1];
if (ar.size() != 1 && min == max) {
cout << 0;
return 0;
}
ll c = 0;
ll dep = 0;
bool sw = true;
REP(i, ar.size()) {
if (!s[ar[i]]) {
s[ar[i]] = true;
sd[ar[i]] = true;
for (ll j = 2 * ar[i]; j <= max; j += ar[i]) {
s[j] = true;
}
} else {
if (ar[i - 1] == ar[i]) {
sd[ar[i]] = false;
}
}
}
REP(i, sd.size()) {
if (sd[i] == true) {
c++;
}
}
cout << c << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
const double PI = acos(-1);
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = ll(1e9 + 7);
const ll INF = ll(1e18) + 7;
// repetition
#define REP(i, n) for (ll i = 0; i < n; i++)
#define RREP(i, n) for (ll i = n; i != 0; i--)
ll gcd(ll a, ll b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
unsigned getDigit(unsigned num) {
unsigned digit = 0;
while (num != 0) {
num /= 10;
digit++;
}
return digit;
}
unsigned binarySearch(ll target, ll max, ll min) {
while ((max - min) > 1) {
if ((max + min) / 2 > target) {
max = (max + min) / 2;
min = min;
} else {
max = max;
min = (max + min) / 2;
}
}
}
void f(int rest, string s) {
char abc[] = "abc";
if (rest == 0) {
cout << s << endl;
} else {
for (int i = 0; i < 3; i++) {
f(rest - 1, s + abc[i]);
}
}
}
/*
int main() {
// n,m->size, k-> value
// vector<vector<ll>> a(n ,vector<ll>(m, k));
// vector
// vector<ll> s(n,0);
// vector<vector<ll>> v;
// map<ll,ll> m;
// priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
pq;
// vector<pair<ll, ll>> epv(n, {0, 0});
// vector<vector<char>> v(h, vector<char>(w));
for(auto&& m: em) {
epv.push_back({ m.second, m.first });
}
ll n, k, a;
cin >> n >> k;
vector<ll> vp;
vector<ll> vn;
ll c = 0;
REP(i, n) {
cin >> a;
if(a >= 0 ) vp.push_back(a);
else vn.push_back(a);
}
sort(vp.begin(), vp.end());
sort(vn.begin(), vn.end());
ll ps = vp.size();
ll ns = vn.size();
cout << "k: " << k << endl;
cout << "ps: " << ps << endl;
cout << "ns: " << ns << endl;
if(k < ps * ns) {
ll m = k%ns;
ll d = k - (m+1);
cout << vn[m] * vp[d] << endl;
}else {
ll kd = k - ps*ns;
ll md = kd%ps;
ll dd = kd - md;
ll s = 0;
REP(i, ps) {
s = s+(ps-i-1);
cout << "s: " << s << endl;
cout << "kd: " << kd << endl;
cout << "s: " << s << endl;
cout << "kd: " << kd << endl;
cout << "i: " << i << endl;
if(s > kd) {
cout << "vp[i]: " << vp[i] << endl;
cout << "vp[ps-i]: " << vp[s-kd+i-1] << endl;
cout << vp[i] * vp[s-kd+i-1] << endl;
break;
}
}
}
}
ll h, w;
vector<vector<char>> v;
vector<ll> dx = {-1, 0, 1, 0};
vector<ll> dy = {0, -1, 0, 1};
ll bfs(ll ox, ll oy) {
vector<vector<ll>> vd(h, vector<ll>(w, -1));
queue<pair<ll, ll>> q;
q.push({ox, oy});
vd[oy][ox] = 0;
ll res = 0;
while(!q.empty()) {
pair<ll, ll> vn = q.front();
q.pop();
res = max(res, vd[vn.second][vn.first]);
for(ll i = 0; i < 4; i++){
ll nx = vn.first +dx[i];
ll ny = vn.second + dy[i];
if(nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
if(v[ny][nx] == '#') continue;
if(vd[ny][nx] == -1) {
vd[ny][nx] = res + 1;
q.push({nx, ny});
}
}
}
return res;
}
bool kai(string s) {
bool flg = true;
ll n = s.size();
for(ll i=0; i<n/2; i++) {
if(s[i] == s[n-1 -i]){
flg = true;
} else {
flg = false;
break;
}
}
return flg;
}
*/
struct UnionFind {
vector<ll> par;
map<ll, ll> s;
UnionFind(ll n) : par(n) {
REP(i, n) {
par[i] = i;
s[i]++;
}
}
ll root(ll x) {
if (par[x] == x)
return x;
return root(par[x]);
}
void unite(ll x, ll y) {
ll rx = root(x);
ll ry = root(y);
if (rx == ry)
return;
if (size(rx) > size(ry)) {
s[rx] = s[rx] + s[ry];
par[root(y)] = rx;
} else {
s[ry] = s[ry] + s[rx];
par[root(x)] = ry;
}
}
bool same(ll x, ll y) { return root(x) == root(y); }
ll size(ll x) { return s[root(x)]; }
};
// base^{exp}%mod
ll mod_pow(ll base, ll exp, ll mod) {
if (exp == 1)
return base % mod;
if (exp % 2 == 1)
return (base * mod_pow(base, exp - 1, mod)) % mod;
ll t = mod_pow(base, exp / 2, mod);
return (t * t) % mod;
}
// nPr
ll mod_permutation(ll n, ll r) {
ll t = 1;
while (r != 0) {
t = (t % MOD) * (n % MOD);
n--;
r--;
}
return t;
}
ll mod_factorial(ll r) {
ll v = 1;
while (r != 0) {
v = (v % MOD) * (r % MOD);
r--;
}
return v;
}
vector<ll> prime_factorization(ll n) {
vector<ll> P;
ll nn = sqrt(n) + 2;
vector<ll> prime(nn + 1, true);
for (ll i = 2; i <= nn; i++) {
if (prime[i]) {
for (ll j = 2 * i; j <= nn; j += i) {
prime[j] = false;
}
P.emplace_back(i);
}
}
vector<ll> d;
REP(i, P.size()) {
while (n % P[i] == 0) {
d.push_back(P[i]);
n /= P[i];
}
}
if (n > nn)
d.push_back(n);
return d;
}
vector<ll> sieve(ll n) {
vector<ll> P;
ll nn = sqrt(n) + 2;
vector<ll> prime(nn + 1, true);
for (ll i = 2; i <= nn; i++) {
if (prime[i]) {
for (ll j = 2 * i; j <= nn; j += i) {
prime[j] = false;
}
P.emplace_back(i);
}
}
return P;
}
bool is_prime(ll n) {
ll nn = sqrt(n) + 2;
vector<ll> prime(nn + 1, true);
if (n % 2 == 0) {
return false;
}
vector<ll> primes = sieve(nn);
REP(i, primes.size()) {
if (n % primes[i] == 0) {
return false;
}
}
return true;
}
struct Node {
vector<ll> edges;
vector<ll> costs;
bool done;
ll cost;
friend bool operator<(const Node &lhs, const Node &rhs) {
return rhs.cost < lhs.cost;
}
};
ll mod_conb(ll n, ll r, ll mod) {
return (mod_factorial(n) / mod_factorial(n - r) / mod_factorial(r)) % mod;
}
vector<vector<ll>> vv;
ll c = 0;
vector<ll> v;
ll n, m, q;
// indexからmまでのn桁の数列の列挙
void dfs2(ll index, ll count) {
if (count < n) {
for (ll i = index; i <= m; i++) {
v[count] = i;
dfs2(i, count + 1);
}
} else {
vv.push_back(v);
}
}
ll total(vector<ll> v) {
ll t = 0;
REP(i, v.size()) { t += v[i]; }
return t;
}
// vector<ll> dx = {-1, 0, 1, 0};
// vector<ll> dy = {0, -1, 0, 1};
// void dfs(ll oy, ll ox, ll color) {
// hw[oy][ox] = color;
// seen[oy][ox] = true;
// for(ll i = 0; i < 4; i++){
// ll ny = oy + dy[i];
// ll nx = ox + dx[i];
// if(nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
// if(seen[ny][nx] == false) {
// ll co = qa.top();
// qa.pop();
// dfs(ny, nx, co);
// }
// }
// }
// std::ifstream in("sub1_06.txt");
// std::cin.rdbuf(in.rdbuf());
/*
ll bfs(ll ox, ll oy) {
vector<vector<ll>> vd(h, vector<ll>(w, -1));
queue<pair<ll, ll>> q;
q.push({ox, oy});
vd[oy][ox] = 0;
ll res = 0;
while(!q.empty()) {
pair<ll, ll> vn = q.front();
q.pop();
res = max(res, vd[vn.second][vn.first]);
for(ll i = 0; i < 4; i++){
ll nx = vn.first +dx[i];
ll ny = vn.second + dy[i];
if(nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
if(v[ny][nx] == '#') continue;
if(vd[ny][nx] == -1) {
vd[ny][nx] = res + 1;
q.push({nx, ny});
}
}
}
return res;
}
*/
void Sieve(ll n) {
vector<bool> flags(n, true);
flags[0] = false;
flags[1] = false;
const ll sqrt_n = ceil(sqrt(n) + 0.1);
for (ll p = 2; p < sqrt_n; ++p) {
if (!flags[p])
continue;
for (ll mult = p * p; mult < n; mult += p)
flags[mult] = false;
}
}
int main() {
// std::ifstream in("01-Handmade-00");
// std::cin.rdbuf(in.rdbuf());
ll n;
cin >> n;
ll a;
vector<bool> s(10000000, false);
vector<bool> sd(10000000, false);
vector<ll> ar;
REP(i, n) {
cin >> a;
ar.push_back(a);
}
sort(ar.begin(), ar.end());
ll min = ar[0];
ll max = ar[ar.size() - 1];
if (ar.size() != 1 && min == max) {
cout << 0;
return 0;
}
ll c = 0;
ll dep = 0;
bool sw = true;
REP(i, ar.size()) {
if (!s[ar[i]]) {
s[ar[i]] = true;
sd[ar[i]] = true;
for (ll j = 2 * ar[i]; j <= max; j += ar[i]) {
s[j] = true;
}
} else {
if (ar[i - 1] == ar[i]) {
sd[ar[i]] = false;
}
}
}
REP(i, sd.size()) {
if (sd[i] == true) {
c++;
}
}
cout << c << endl;
return 0;
} | replace | 414 | 416 | 414 | 416 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
int main() {
int N;
cin >> N;
vector<int> a(N);
vector<int> cnt(212345);
for (int i = 0; i < N; i++) {
cin >> a[i];
cnt[a[i]]++;
}
int ans = N;
for (int i = 0; i < N; i++) {
if (cnt[a[i]] > 1 || (a[i] != 1 && cnt[1] > 0)) {
ans--;
continue;
}
for (int j = 2; j * j <= a[i]; j++) {
if (a[i] % j == 0 && (cnt[a[i] / j] > 0 || cnt[j] > 0)) {
ans--;
break;
}
}
}
cout << ans << "\n";
} | #include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
int main() {
int N;
cin >> N;
vector<int> a(N);
vector<int> cnt(2123456);
for (int i = 0; i < N; i++) {
cin >> a[i];
cnt[a[i]]++;
}
int ans = N;
for (int i = 0; i < N; i++) {
if (cnt[a[i]] > 1 || (a[i] != 1 && cnt[1] > 0)) {
ans--;
continue;
}
for (int j = 2; j * j <= a[i]; j++) {
if (a[i] % j == 0 && (cnt[a[i] / j] > 0 || cnt[j] > 0)) {
ans--;
break;
}
}
}
cout << ans << "\n";
} | replace | 18 | 19 | 18 | 19 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define EPS (1e-9)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
bool LT(double a, double b) { return !equals(a, b) && a < b; }
bool LTE(double a, double b) { return equals(a, b) || a < b; }
const string YES = "";
const string NO = "";
typedef long long ll;
typedef pair<int, int> ii;
int n;
vector<ll> A;
const int MAX = 2000000;
vector<int> prime;
bool isntprime[MAX + 1];
void solve() {
map<int, int> mp;
rep(i, n) mp[A[i]]++;
set<int> BAN;
for (auto tmp : mp) {
if (tmp.snd != 1) {
BAN.insert(tmp.fst);
}
}
sort(ALL(A));
int cnt = 0;
int j;
rep(id, (int)A.size()) {
int i = A[id];
if (!isntprime[i]) {
if (!BAN.count(i)) {
++cnt;
}
for (j = 2 * i; j <= MAX; j += i)
isntprime[j] = true;
}
}
cout << cnt << endl;
}
int main() {
cin >> n;
A.resize(n);
rep(i, n) cin >> A[i];
solve();
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define EPS (1e-9)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
bool LT(double a, double b) { return !equals(a, b) && a < b; }
bool LTE(double a, double b) { return equals(a, b) || a < b; }
const string YES = "";
const string NO = "";
typedef long long ll;
typedef pair<int, int> ii;
int n;
vector<ll> A;
const int MAX = 2000000;
vector<int> prime;
bool isntprime[MAX + 1];
void solve() {
map<int, int> mp;
rep(i, n) mp[A[i]]++;
set<int> BAN;
for (auto tmp : mp) {
if (tmp.snd != 1) {
BAN.insert(tmp.fst);
}
}
sort(ALL(A));
A.erase(unique(ALL(A)), A.end());
int cnt = 0;
int j;
rep(id, (int)A.size()) {
int i = A[id];
if (!isntprime[i]) {
if (!BAN.count(i)) {
++cnt;
}
for (j = 2 * i; j <= MAX; j += i)
isntprime[j] = true;
}
}
cout << cnt << endl;
}
int main() {
cin >> n;
A.resize(n);
rep(i, n) cin >> A[i];
solve();
return 0;
}
| insert | 40 | 40 | 40 | 41 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main(void) {
int n;
int A[200002];
bool B[1000002] = {
0,
};
bool check[1000002] = {
0,
};
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> A[i];
if (check[A[i]] == false)
check[A[i]] = true;
else
B[A[i]] = true;
for (int j = 2; j <= 1000002 / A[i]; j++)
B[j * A[i]] = true;
}
int cnt = 0;
for (int i = 1; i <= n; i++)
if (B[A[i]] == false)
cnt++;
cout << cnt;
return 0;
} | #include <iostream>
using namespace std;
int main(void) {
int n;
int A[200002];
bool B[1000002] = {
0,
};
bool check[1000002] = {
0,
};
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> A[i];
if (check[A[i]] == false)
check[A[i]] = true;
else
B[A[i]] = true;
if (B[A[i]] != true)
for (int j = 2; j <= 1000002 / A[i]; j++)
B[j * A[i]] = true;
}
int cnt = 0;
for (int i = 1; i <= n; i++)
if (B[A[i]] == false)
cnt++;
cout << cnt;
return 0;
} | replace | 21 | 23 | 21 | 24 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < n; i++)
#define Rep(i, n) for (long long i = 1; i < n; i++)
#define ll long long
#include <cmath>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define PI acos(-1)
using P = pair<int, int>;
ll ketasu(ll a) {
ll num = 1;
while (a / 10) {
num++;
a /= 10;
}
return num;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll kosuu(ll a) {
ll sum = 0;
for (ll i = 1; i * i <= a; i++) {
if (a % i == 0) {
if (a != 1 && i * i != a) {
sum += 2;
} else {
sum++;
}
}
}
return sum;
}
ll M = 1000005;
int main() {
ll n;
cin >> n;
vector<ll> cnt(M);
vector<ll> s(n);
rep(i, n) { cin >> s[i]; }
for (ll x : s) {
if (cnt[x] != 0) {
cnt[x] = 2;
}
for (ll i = x; i < M; i += x)
cnt[i]++;
}
ll ans = 0;
for (ll x : s) {
if (cnt[x] == 1)
ans++;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < n; i++)
#define Rep(i, n) for (long long i = 1; i < n; i++)
#define ll long long
#include <cmath>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define PI acos(-1)
using P = pair<int, int>;
ll ketasu(ll a) {
ll num = 1;
while (a / 10) {
num++;
a /= 10;
}
return num;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll kosuu(ll a) {
ll sum = 0;
for (ll i = 1; i * i <= a; i++) {
if (a % i == 0) {
if (a != 1 && i * i != a) {
sum += 2;
} else {
sum++;
}
}
}
return sum;
}
ll M = 1000005;
int main() {
ll n;
cin >> n;
vector<ll> cnt(M);
vector<ll> s(n);
rep(i, n) { cin >> s[i]; }
for (ll x : s) {
if (cnt[x] != 0) {
cnt[x] = 2;
continue;
}
for (ll i = x; i < M; i += x)
cnt[i]++;
}
ll ans = 0;
for (ll x : s) {
if (cnt[x] == 1)
ans++;
}
cout << ans << endl;
}
| insert | 53 | 53 | 53 | 54 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < n; i++)
#define Rep(i, n) for (long long i = 1; i < n; i++)
#define ll long long
#include <cmath>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define PI acos(-1)
using P = pair<ll, ll>;
ll ketasu(ll a) {
ll num = 1;
while (a / 10) {
num++;
a /= 10;
}
return num;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll kosuu(ll a) {
ll sum = 0;
for (ll i = 1; i * i <= a; i++) {
if (a % i == 0) {
if (a != 1 && i * i != a) {
sum += 2;
} else {
sum++;
}
}
}
return sum;
}
ll di[] = {1, 0, -1, 0};
ll dj[] = {0, -1, 0, 1};
struct UnionFind {
vector<int> d;
UnionFind(int n = 0) : d(n, -1) {}
int find(int x) {
if ((d[x]) < 0)
return x;
return d[x] = find(d[x]);
}
bool unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return false;
if (d[x] > d[y])
swap(x, y);
d[x] += d[y];
d[y] = x;
return true;
}
bool same(int x, int y) { return find(x) == find(y); };
int size(int x) { return -d[find(x)]; };
};
int deg[100005];
vector<int> to[100005];
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
mint f(int n) {
if (n == 0)
return 1;
mint x = f(2 / n);
x *= x;
if (n % 2 == 1)
x *= 2;
return x;
}
mint choose(int n, int a) {
mint x = 1, y = 1;
rep(i, a) {
x *= n - i;
y *= a + i;
}
return x / y;
}
const ll m = 100005;
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;
} else {
for (ll i = x; i <= m; i += x) {
cnt[i]++;
}
}
}
ll ans = 0;
for (ll x : a) {
if (cnt[x] == 1)
ans++;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < n; i++)
#define Rep(i, n) for (long long i = 1; i < n; i++)
#define ll long long
#include <cmath>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define PI acos(-1)
using P = pair<ll, ll>;
ll ketasu(ll a) {
ll num = 1;
while (a / 10) {
num++;
a /= 10;
}
return num;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll kosuu(ll a) {
ll sum = 0;
for (ll i = 1; i * i <= a; i++) {
if (a % i == 0) {
if (a != 1 && i * i != a) {
sum += 2;
} else {
sum++;
}
}
}
return sum;
}
ll di[] = {1, 0, -1, 0};
ll dj[] = {0, -1, 0, 1};
struct UnionFind {
vector<int> d;
UnionFind(int n = 0) : d(n, -1) {}
int find(int x) {
if ((d[x]) < 0)
return x;
return d[x] = find(d[x]);
}
bool unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return false;
if (d[x] > d[y])
swap(x, y);
d[x] += d[y];
d[y] = x;
return true;
}
bool same(int x, int y) { return find(x) == find(y); };
int size(int x) { return -d[find(x)]; };
};
int deg[100005];
vector<int> to[100005];
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
mint f(int n) {
if (n == 0)
return 1;
mint x = f(2 / n);
x *= x;
if (n % 2 == 1)
x *= 2;
return x;
}
mint choose(int n, int a) {
mint x = 1, y = 1;
rep(i, a) {
x *= n - i;
y *= a + i;
}
return x / y;
}
const ll 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;
} else {
for (ll i = x; i <= m; i += x) {
cnt[i]++;
}
}
}
ll ans = 0;
for (ll x : a) {
if (cnt[x] == 1)
ans++;
}
cout << ans << endl;
}
| replace | 134 | 135 | 134 | 135 | 0 | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MAX = 200100;
int main() {
ll N;
cin >> N;
vector<int> A(N);
for (ll i = 0; i < N; i++)
cin >> A[i];
vector<int> M(MAX, 0);
for (auto a : A) {
if (M[a] != 0) {
M[a] = 2;
continue;
}
for (ll i = a; i <= MAX; i += a)
M[i]++;
}
ll ans = 0;
for (auto a : A) {
if (M[a] == 1)
ans++;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MAX = 2001000;
int main() {
ll N;
cin >> N;
vector<int> A(N);
for (ll i = 0; i < N; i++)
cin >> A[i];
vector<int> M(MAX, 0);
for (auto a : A) {
if (M[a] != 0) {
M[a] = 2;
continue;
}
for (ll i = a; i <= MAX; i += a)
M[i]++;
}
ll ans = 0;
for (auto a : A) {
if (M[a] == 1)
ans++;
}
cout << ans << endl;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <iostream>
#include <vector>
typedef long long ll;
int main() {
ll N;
std::cin >> N;
std::vector<ll> A(N);
for (int i = 0; i < N; i++) {
std::cin >> A[i];
}
std::vector<ll> B(1000010);
for (auto r : A) {
for (int x = r; x < 1000010; x += r) {
B[x]++;
}
}
ll resa = 0;
for (auto it = A.begin(); it != A.end(); it++) {
if (B[*it] == 1)
resa++;
}
std::cout << resa << std::endl;
return 0;
} | #include <iostream>
#include <vector>
typedef long long ll;
int main() {
ll N;
std::cin >> N;
std::vector<ll> A(N);
for (int i = 0; i < N; i++) {
std::cin >> A[i];
}
std::vector<ll> B(1000010);
for (auto r : A) {
if (B[r] != 0) {
B[r] = 2;
continue;
}
for (int x = r; x < 1000010; x += r) {
B[x]++;
}
}
ll resa = 0;
for (auto it = A.begin(); it != A.end(); it++) {
if (B[*it] == 1)
resa++;
}
std::cout << resa << std::endl;
return 0;
}
| insert | 14 | 14 | 14 | 18 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
// constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T> void remove(std::vector<T> &vector, unsigned int index) {
vector.erase(vector.begin() + index);
}
using Graph = vector<vector<tuple<ll, ll, ll>>>;
// MOD確認
ll N;
ll A[200010];
bool B[200010];
int main() {
cin >> N;
rep(i, N) cin >> A[i];
sort(A, A + N);
ll ans = 0;
rep(i, N) {
if (!B[A[i]] && A[i + 1] != A[i])
ans++;
for (ll j = 1; j * A[i] <= A[N - 1]; j++) {
B[A[i] * j] = 1;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
// constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T> void remove(std::vector<T> &vector, unsigned int index) {
vector.erase(vector.begin() + index);
}
using Graph = vector<vector<tuple<ll, ll, ll>>>;
// MOD確認
ll N;
ll A[200010];
bool B[2000010];
int main() {
cin >> N;
rep(i, N) cin >> A[i];
sort(A, A + N);
ll ans = 0;
rep(i, N) {
if (!B[A[i]] && A[i + 1] != A[i])
ans++;
for (ll j = 1; j * A[i] <= A[N - 1]; j++) {
B[A[i] * j] = 1;
}
}
cout << ans << endl;
}
| replace | 24 | 25 | 24 | 25 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rrepi(i, a, b) for (int i = ((int)(b)-1); i >= (a); --i)
#define rep(i, n) repi(i, 0, n)
#define rrep(i, n) rrepi(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x, 0, sizeof(x))
#define MINUS(x) memset(x, -1, sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define TOUPPER(x) transform(ALL(x), (x).begin(), ::toupper)
#define TOLOWER(x) transform(ALL(x), (x).begin(), ::tolower)
#define debug(var) \
do { \
std::cout << #var << " : "; \
view(var); \
} while (0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void view(const std::vector<T> &v) {
for (const auto &e : v) {
std::cout << e << " ";
}
std::cout << std::endl;
}
template <typename T> void view(const std::vector<std::vector<T>> &vv) {
for (const auto &v : vv) {
view(v);
}
}
template <typename T> void view(T e) { std::cout << e << std::endl; }
template <typename T> void viewarr(T arr[], int n) {
for (int i = 0; i < n; ++i)
std::cout << arr[i] << " ";
std::cout << std::endl;
}
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;
}
ll qp(ll a, ll b) {
ll ans = 1;
do {
if (b & 1)
ans = 1ll * ans * a;
a = 1ll * a * a;
} while (b >>= 1);
return ans;
}
ll qp(ll a, ll b, ll mo) {
ll ans = 1;
do {
if (b & 1)
ans = 1ll * ans * a % mo;
a = 1ll * a * a % mo;
} while (b >>= 1);
return ans;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;
int B[1000001];
int main() {
int N;
cin >> N;
vector<int> A(N);
rep(i, N) cin >> A[i];
rep(i, N) {
for (int p = 1; A[i] * p <= 1000000; p++) {
B[A[i] * p]++;
}
}
int ans = 0;
rep(i, N) if (B[A[i]] <= 1) ans++;
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rrepi(i, a, b) for (int i = ((int)(b)-1); i >= (a); --i)
#define rep(i, n) repi(i, 0, n)
#define rrep(i, n) rrepi(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x, 0, sizeof(x))
#define MINUS(x) memset(x, -1, sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define TOUPPER(x) transform(ALL(x), (x).begin(), ::toupper)
#define TOLOWER(x) transform(ALL(x), (x).begin(), ::tolower)
#define debug(var) \
do { \
std::cout << #var << " : "; \
view(var); \
} while (0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void view(const std::vector<T> &v) {
for (const auto &e : v) {
std::cout << e << " ";
}
std::cout << std::endl;
}
template <typename T> void view(const std::vector<std::vector<T>> &vv) {
for (const auto &v : vv) {
view(v);
}
}
template <typename T> void view(T e) { std::cout << e << std::endl; }
template <typename T> void viewarr(T arr[], int n) {
for (int i = 0; i < n; ++i)
std::cout << arr[i] << " ";
std::cout << std::endl;
}
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;
}
ll qp(ll a, ll b) {
ll ans = 1;
do {
if (b & 1)
ans = 1ll * ans * a;
a = 1ll * a * a;
} while (b >>= 1);
return ans;
}
ll qp(ll a, ll b, ll mo) {
ll ans = 1;
do {
if (b & 1)
ans = 1ll * ans * a % mo;
a = 1ll * a * a % mo;
} while (b >>= 1);
return ans;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;
int B[1000001];
int main() {
int N;
cin >> N;
vector<int> A(N);
rep(i, N) cin >> A[i];
rep(i, N) {
if (B[A[i]] <= 1) {
for (int p = 1; A[i] * p <= 1000000; p++) {
B[A[i] * p]++;
}
}
}
int ans = 0;
rep(i, N) if (B[A[i]] <= 1) ans++;
cout << ans << endl;
return 0;
}
| replace | 87 | 89 | 87 | 91 | TLE | |
p02642 | C++ | Time Limit Exceeded | /*
`-:://:::-
`//:-------:/:`
.+:--.......--:+`
`+:--..`````..--//`
.o:--..`` ``..--:o`
.o:--...```..---+/`
`/y+o/---....---:+o.
`...````-os+/:---:/+o/--.`
`-/+++++/:. `...` :h+d+oooo+/+-` ...
`/++//:::://++-`....` -.`//````````:` `..`
`o+/::------://o/` `-` -. -` `..`
`---.-o/:./o/::-..``..-ЗАПУСКАЕМ .. .. -` `... ``..``
`....o+:-++/:--.```..-://s. `-` .- -` `-o:
.-//::::/:-`
`:s+/:--....-::/+s-` .- `- -` -///:--------:/:`
./s+//:::::://oo-``..НЕЙРОННУЮ: СЕТЬ:::::::-`РАБОТЯГИ
`+:--........--:/`
.:ooo+++++osso-` `.:-...`/` ./::-------:/:` -`
:+--..``````.--:+:...-+:-`
`.-/+++++/+-.-` -. ``:so:/:--.......--:+`
`-```````o+/+--..`````..--:o/-..:s+:.
```````:``.. `-` -`
`+:--..`````..--/+-.../.`````..-o:--.......---/o. `
`: `:- -. .o:--..`` ``..--:o` `-`
`:o+:--------:+o-`
`-`-... .. .o/--...```..--:+/` `-`
`oy/so/////++o/.`
-/` `-` `- ``+s/o/:---...---:++. `-`
.-../d://///:-.`
`.---..``-..- .-/..`````-oo+/:::::/+o+- `-``-` `-.
````
`:++++/+++++- ..``.-/:` /y-:/++o++/:.`..` ./. `-
-++/::::::://+/..:-``:` .. `-.` ```.``` `..` `..`-` `-
`` -o//:--....-::/++` -.-` `-`.-` `..`..` `-.-
-----ss+:++/:--.```..-://s. /. `:: `-:. ./`
`````/:..+o/::-..``.--:/+s. ..-` `-``-` ..` `-` `-`-`
`-s+/::-----::/+oo---``-` .. .:- ``` .-` .-.- `-`
`:oo+//::://+os/..:`..-/:` :y.-:::::::.`.-` ./-` `-`
`./+oooooooo+/.`- .-:...`.. .//:-------://` `- `..` `:.
``.-::::-.``-/` `-` `- `oo:+:--.......--:/` `-
`.:--h.``..```
-.-`.- .- `+:--..`````..--//` `-
/s-//::::::::.
-` `/- .. .o:--..`` ``..--:o.```.-
`//:--------://`
-` .-`.-`
-.`-o/--...```..--:+/.``-:....``:-.+:--....`...--:+`
..`-. `-. ``:os:o/:---...---:++. `-
``///+:-..``````.--:+-````-.`
`.:///////.-` .:-..` -``-+o+/:::::/+o/. `-
`:+:-..`````..--:o/:--/ys+-
`-++///////+o/. ``....`-. :` `.:++++++/:.` .- -o/---......---/o.
`.`
`++//:-----::/+o:..` .-` : ``````` .- `+so+:--------:++-`
`````:-``:o/::-..`..--:/+o` -. `- .- `../../+o+////+o+:.`
-----syo/o+/:--.```..-://s. .-` `- .- `...
``-:////:-``
.` `/s//:--....-::/+s. -. `-` .- `..`
.+o+/:::--:://+s/-..` .::+y ``` .- `..`
./oo++////+oso-` `.... :y-+:::::::/` ...
`.:+oooooo/-` `....-. .//:-------:/:-.`
``...`` /+:+:--.......--:+`
`+:--..`````..--//`
.o:--..`` ``..--:o`
.+/--...```..--:+/`
`-o/:---...---:++.
`-+o+/:---:/+o/.
`.:+oooo+/-.`
``````
*/
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
// #define endl '\n'
#define all(x) x.begin(), x.end()
#define int long long
#define mk(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<ll, ll, ll> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
const ll INF = 1e9 + 228;
const ll INFLL = 1e18;
const ll MOD = 1e9 + 7;
// static const int maxn = 1e6 + 228;
const ld eps = 1e-4;
const ld eps2 = 1e-9;
const ll MOD2 = 998244353;
const ll dosz = 5e5;
const ll SZ = (1 << 18);
const ld PI = atan2l(0, -1);
void fast_io() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("a.in", "r", stdin);
// freopen("nocross.out", "w", stdout);
}
void solve() {
int n;
cin >> n;
vi nums(n);
for (int &i : nums)
cin >> i;
map<int, int> kek;
int ans = 0;
for (int i : nums)
kek[i]++;
for (int i = 0; i < n; i++) {
int cnt = 0;
kek[nums[i]]--;
for (int j = 1; j * j <= nums[i]; j++) {
if (nums[i] % j == 0) {
cnt += kek[j];
if (j * j != nums[i])
cnt += kek[nums[i] / j];
}
}
if (cnt == 0) {
ans++;
}
kek[nums[i]]++;
}
cout << ans << endl;
}
signed main() {
fast_io();
srand(time(NULL));
cout << fixed << setprecision(12);
int q = 1;
// cin >> q;
while (q--)
solve();
}
| /*
`-:://:::-
`//:-------:/:`
.+:--.......--:+`
`+:--..`````..--//`
.o:--..`` ``..--:o`
.o:--...```..---+/`
`/y+o/---....---:+o.
`...````-os+/:---:/+o/--.`
`-/+++++/:. `...` :h+d+oooo+/+-` ...
`/++//:::://++-`....` -.`//````````:` `..`
`o+/::------://o/` `-` -. -` `..`
`---.-o/:./o/::-..``..-ЗАПУСКАЕМ .. .. -` `... ``..``
`....o+:-++/:--.```..-://s. `-` .- -` `-o:
.-//::::/:-`
`:s+/:--....-::/+s-` .- `- -` -///:--------:/:`
./s+//:::::://oo-``..НЕЙРОННУЮ: СЕТЬ:::::::-`РАБОТЯГИ
`+:--........--:/`
.:ooo+++++osso-` `.:-...`/` ./::-------:/:` -`
:+--..``````.--:+:...-+:-`
`.-/+++++/+-.-` -. ``:so:/:--.......--:+`
`-```````o+/+--..`````..--:o/-..:s+:.
```````:``.. `-` -`
`+:--..`````..--/+-.../.`````..-o:--.......---/o. `
`: `:- -. .o:--..`` ``..--:o` `-`
`:o+:--------:+o-`
`-`-... .. .o/--...```..--:+/` `-`
`oy/so/////++o/.`
-/` `-` `- ``+s/o/:---...---:++. `-`
.-../d://///:-.`
`.---..``-..- .-/..`````-oo+/:::::/+o+- `-``-` `-.
````
`:++++/+++++- ..``.-/:` /y-:/++o++/:.`..` ./. `-
-++/::::::://+/..:-``:` .. `-.` ```.``` `..` `..`-` `-
`` -o//:--....-::/++` -.-` `-`.-` `..`..` `-.-
-----ss+:++/:--.```..-://s. /. `:: `-:. ./`
`````/:..+o/::-..``.--:/+s. ..-` `-``-` ..` `-` `-`-`
`-s+/::-----::/+oo---``-` .. .:- ``` .-` .-.- `-`
`:oo+//::://+os/..:`..-/:` :y.-:::::::.`.-` ./-` `-`
`./+oooooooo+/.`- .-:...`.. .//:-------://` `- `..` `:.
``.-::::-.``-/` `-` `- `oo:+:--.......--:/` `-
`.:--h.``..```
-.-`.- .- `+:--..`````..--//` `-
/s-//::::::::.
-` `/- .. .o:--..`` ``..--:o.```.-
`//:--------://`
-` .-`.-`
-.`-o/--...```..--:+/.``-:....``:-.+:--....`...--:+`
..`-. `-. ``:os:o/:---...---:++. `-
``///+:-..``````.--:+-````-.`
`.:///////.-` .:-..` -``-+o+/:::::/+o/. `-
`:+:-..`````..--:o/:--/ys+-
`-++///////+o/. ``....`-. :` `.:++++++/:.` .- -o/---......---/o.
`.`
`++//:-----::/+o:..` .-` : ``````` .- `+so+:--------:++-`
`````:-``:o/::-..`..--:/+o` -. `- .- `../../+o+////+o+:.`
-----syo/o+/:--.```..-://s. .-` `- .- `...
``-:////:-``
.` `/s//:--....-::/+s. -. `-` .- `..`
.+o+/:::--:://+s/-..` .::+y ``` .- `..`
./oo++////+oso-` `.... :y-+:::::::/` ...
`.:+oooooo/-` `....-. .//:-------:/:-.`
``...`` /+:+:--.......--:+`
`+:--..`````..--//`
.o:--..`` ``..--:o`
.+/--...```..--:+/`
`-o/:---...---:++.
`-+o+/:---:/+o/.
`.:+oooo+/-.`
``````
*/
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
// #define endl '\n'
#define all(x) x.begin(), x.end()
// #define int long long
#define mk(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<ll, ll, ll> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
const ll INF = 1e9 + 228;
const ll INFLL = 1e18;
const ll MOD = 1e9 + 7;
// static const int maxn = 1e6 + 228;
const ld eps = 1e-4;
const ld eps2 = 1e-9;
const ll MOD2 = 998244353;
const ll dosz = 5e5;
const ll SZ = (1 << 18);
const ld PI = atan2l(0, -1);
void fast_io() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("a.in", "r", stdin);
// freopen("nocross.out", "w", stdout);
}
void solve() {
int n;
cin >> n;
vi nums(n);
for (int &i : nums)
cin >> i;
map<int, int> kek;
int ans = 0;
for (int i : nums)
kek[i]++;
for (int i = 0; i < n; i++) {
int cnt = 0;
kek[nums[i]]--;
for (int j = 1; j * j <= nums[i]; j++) {
if (nums[i] % j == 0) {
cnt += kek[j];
if (j * j != nums[i])
cnt += kek[nums[i] / j];
}
}
if (cnt == 0) {
ans++;
}
kek[nums[i]]++;
}
cout << ans << endl;
}
signed main() {
fast_io();
srand(time(NULL));
cout << fixed << setprecision(12);
int q = 1;
// cin >> q;
while (q--)
solve();
}
| replace | 95 | 96 | 95 | 96 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORR(i, a, b) for (ll i = (a); i <= (b); i++)
#define repR(i, n) for (ll i = n; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout << (x) << "\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, vector<ll>, greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n")
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n")
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
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;
}
ll dx[4] = {0, 1, 0, -1};
ll dy[4] = {1, 0, -1, 0};
int main() {
ll n;
cin >> n;
vll a(n);
rep(i, n) cin >> a[i];
sort(all(a));
ll ans = 0;
vll b(1000001);
rep(i, n) {
if (b[a[i]] == 0) {
ans++;
if (i + 1 < n) {
if (a[i] == a[i + 1])
ans--;
}
}
ll now = 1;
while (now * a[i] < 1000001) {
b[now * a[i]] = 1;
now++;
}
}
COUT(ans);
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORR(i, a, b) for (ll i = (a); i <= (b); i++)
#define repR(i, n) for (ll i = n; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout << (x) << "\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, vector<ll>, greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n")
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n")
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
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;
}
ll dx[4] = {0, 1, 0, -1};
ll dy[4] = {1, 0, -1, 0};
int main() {
ll n;
cin >> n;
vll a(n);
rep(i, n) cin >> a[i];
sort(all(a));
ll ans = 0;
vll b(1000001);
rep(i, n) {
if (i) {
if (a[i] == a[i - 1])
continue;
}
if (b[a[i]] == 0) {
ans++;
if (i + 1 < n) {
if (a[i] == a[i + 1])
ans--;
}
}
ll now = 1;
while (now * a[i] < 1000001) {
b[now * a[i]] = 1;
now++;
}
}
COUT(ans);
}
| insert | 62 | 62 | 62 | 66 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int vis[maxn];
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
for (int j = 1; j * a[i] < maxn; j++) {
vis[a[i] * j]++;
}
}
int res = 0;
for (int i = 0; i < n; i++) {
if (vis[a[i]] == 1) {
res++;
}
}
cout << res << endl;
} | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int vis[maxn];
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
if (vis[a[i]]) {
vis[a[i]]++;
continue;
}
for (int j = 1; j * a[i] < maxn; j++) {
vis[a[i] * j]++;
}
}
int res = 0;
for (int i = 0; i < n; i++) {
if (vis[a[i]] == 1) {
res++;
}
}
cout << res << endl;
} | insert | 14 | 14 | 14 | 18 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <time.h>
#define F(i, a, b) for (long long i = a; i <= (b); ++i)
#define dF(i, a, b) for (long long i = a; i >= (b); --i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
const int mods = 1e9 + 7;
const int maxn = 2e5 + 10;
const int N = 1e5 + 10;
const int E = 1e6 + 10;
int x, n;
int vis[maxn];
int a[maxn];
int main() {
cin >> n;
F(i, 1, n) {
scanf("%d", &a[i]);
vis[a[i]]++;
}
int ans = n;
F(i, 1, n) {
if (vis[a[i]] > 1) {
ans--;
continue;
} else {
vis[a[i]]--;
F(j, 1, floor((double)sqrt(a[i]))) {
if (a[i] % j == 0) {
if (vis[j]) {
// cout<<i<<" "<<j<<endl;
ans--;
break;
} else if (vis[a[i] / j]) {
// cout<<i<<" "<<j<<endl;
ans--;
break;
}
}
}
vis[a[i]]++;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#include <time.h>
#define F(i, a, b) for (long long i = a; i <= (b); ++i)
#define dF(i, a, b) for (long long i = a; i >= (b); --i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
const int mods = 1e9 + 7;
const int maxn = 1e6 + 10;
const int N = 1e5 + 10;
const int E = 1e6 + 10;
int x, n;
int vis[maxn];
int a[maxn];
int main() {
cin >> n;
F(i, 1, n) {
scanf("%d", &a[i]);
vis[a[i]]++;
}
int ans = n;
F(i, 1, n) {
if (vis[a[i]] > 1) {
ans--;
continue;
} else {
vis[a[i]]--;
F(j, 1, floor((double)sqrt(a[i]))) {
if (a[i] % j == 0) {
if (vis[j]) {
// cout<<i<<" "<<j<<endl;
ans--;
break;
} else if (vis[a[i] / j]) {
// cout<<i<<" "<<j<<endl;
ans--;
break;
}
}
}
vis[a[i]]++;
}
}
cout << ans << endl;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
// int mx = (int)1e6 + 1;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int mx = *max_element(a.begin(), a.end());
vector<int> cnt(mx + 1);
for (int i = 0; i < n; i++) {
cnt[a[i]]++;
}
vector<bool> ok(mx, 1);
for (int i = 0; i < n; i++) {
if (cnt[a[i]] != 0) {
for (int j = a[i] + a[i]; j <= mx; j += a[i]) {
ok[j] = 0;
}
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
if (cnt[a[i]] == 1 && ok[a[i]]) {
ans++;
}
}
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
// int mx = (int)1e6 + 1;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int mx = *max_element(a.begin(), a.end());
vector<int> cnt(mx + 1);
for (int i = 0; i < n; i++) {
cnt[a[i]]++;
}
vector<bool> ok(mx + 1, 1);
for (int i = 0; i < n; i++) {
if (cnt[a[i]] != 0) {
for (int j = a[i] + a[i]; j <= mx; j += a[i]) {
ok[j] = 0;
}
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
if (cnt[a[i]] == 1 && ok[a[i]]) {
ans++;
}
}
cout << ans << '\n';
return 0;
}
| replace | 21 | 22 | 21 | 22 | 0 | |
p02642 | C++ | Time Limit Exceeded | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rep2(i, n) for (int i = 0; i <= n; i++)
#define repr(i, a, n) for (int i = a; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define uni(e) e.erase(unique(e.begin(), e.end()), e.end())
#define double long double
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;
}
int INF = 1e10;
int MOD = 1e9 + 7;
template <class T> void out(T a) { cout << a << '\n'; }
template <class T> void yesno(T b) {
if (b)
out("yes");
else
out("no");
}
template <class T> void YesNo(T b) {
if (b)
out("Yes");
else
out("No");
}
template <class T> void YESNO(T b) {
if (b)
out("YES");
else
out("NO");
}
template <class T> void noyes(T b) {
if (b)
out("no");
else
out("yes");
}
template <class T> void NoYes(T b) {
if (b)
out("No");
else
out("Yes");
}
template <class T> void NOYES(T b) {
if (b)
out("NO");
else
out("YES");
}
int keta(int a) {
double b = a;
b = log10(b);
int c = b;
return c + 1;
}
int kurai(int a, int b) {
int m = pow(10, b), n = pow(10, b - 1);
return (a % m) / n;
}
int ketawa(int a) {
int k = 0;
rep(i, keta(a)) { k += kurai(a, i + 1); }
return k;
}
int gcd(int a, int b) {
if (a % b == 0)
return b;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int mid(int a, int b, int c) {
vector<int> k(3);
k[0] = a;
k[1] = b;
k[2] = c;
sort(all(k));
return k[1];
}
bool sosuu(int a) {
bool b = 1;
if (a <= 1)
return 0;
else {
rep1(i, sqrt(a) - 1) {
if (a % (i + 1) == 0)
b = 0;
}
return b;
}
}
int modpow(int a, int b, int m = MOD) {
if (!b)
return 1;
if (b & 1)
return modpow(a, b - 1, m) * a % m;
int memo = modpow(a, b >> 1, m);
return memo * memo % m;
}
int fact_mod(int n) {
int f = 1;
for (int i = 2; i < n + 1; i++)
f = f * (i % MOD) % MOD;
return f;
}
int mod_pow(int x, int n) {
int res = 1;
while (n > 0) {
if (n & 1)
res = (res * x) % MOD;
x = (x * x) % MOD;
n >>= 1;
}
return res;
}
int c_mod(int n, int r) {
if (r > n - r)
r = n - r;
if (r == 0)
return 1;
int a = 1;
rep(i, r) a = a * ((n - i) % MOD) % MOD;
int b = mod_pow(fact_mod(r), MOD - 2);
return (a % MOD) * (b % MOD) % MOD;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int a;
cin >> a;
vector<int> b(a), c(1000010, 0);
rep(i, a) cin >> b[i];
rep(i, a) { c[b[i]] += 1; }
if (c[1] == 0) {
int d = 0;
rep(i, a) {
int e = 1;
rep(j, sqrt(b[i]) + 0.1) {
if (j == 0) {
if (c[b[i]] > 1) {
e = 0;
break;
}
} else {
if (b[i] != 2 && b[i] != 3) {
if (b[i] % (j + 1) == 0) {
if ((c[j + 1]) || (c[b[i] / (j + 1)])) {
e = 0;
break;
}
}
}
}
}
d += e;
}
out(d);
} else if (c[1] == 1)
out(1);
else
out(0);
}
| #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rep2(i, n) for (int i = 0; i <= n; i++)
#define repr(i, a, n) for (int i = a; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define uni(e) e.erase(unique(e.begin(), e.end()), e.end())
#define double long double
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;
}
int INF = 1e10;
int MOD = 1e9 + 7;
template <class T> void out(T a) { cout << a << '\n'; }
template <class T> void yesno(T b) {
if (b)
out("yes");
else
out("no");
}
template <class T> void YesNo(T b) {
if (b)
out("Yes");
else
out("No");
}
template <class T> void YESNO(T b) {
if (b)
out("YES");
else
out("NO");
}
template <class T> void noyes(T b) {
if (b)
out("no");
else
out("yes");
}
template <class T> void NoYes(T b) {
if (b)
out("No");
else
out("Yes");
}
template <class T> void NOYES(T b) {
if (b)
out("NO");
else
out("YES");
}
int keta(int a) {
double b = a;
b = log10(b);
int c = b;
return c + 1;
}
int kurai(int a, int b) {
int m = pow(10, b), n = pow(10, b - 1);
return (a % m) / n;
}
int ketawa(int a) {
int k = 0;
rep(i, keta(a)) { k += kurai(a, i + 1); }
return k;
}
int gcd(int a, int b) {
if (a % b == 0)
return b;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int mid(int a, int b, int c) {
vector<int> k(3);
k[0] = a;
k[1] = b;
k[2] = c;
sort(all(k));
return k[1];
}
bool sosuu(int a) {
bool b = 1;
if (a <= 1)
return 0;
else {
rep1(i, sqrt(a) - 1) {
if (a % (i + 1) == 0)
b = 0;
}
return b;
}
}
int modpow(int a, int b, int m = MOD) {
if (!b)
return 1;
if (b & 1)
return modpow(a, b - 1, m) * a % m;
int memo = modpow(a, b >> 1, m);
return memo * memo % m;
}
int fact_mod(int n) {
int f = 1;
for (int i = 2; i < n + 1; i++)
f = f * (i % MOD) % MOD;
return f;
}
int mod_pow(int x, int n) {
int res = 1;
while (n > 0) {
if (n & 1)
res = (res * x) % MOD;
x = (x * x) % MOD;
n >>= 1;
}
return res;
}
int c_mod(int n, int r) {
if (r > n - r)
r = n - r;
if (r == 0)
return 1;
int a = 1;
rep(i, r) a = a * ((n - i) % MOD) % MOD;
int b = mod_pow(fact_mod(r), MOD - 2);
return (a % MOD) * (b % MOD) % MOD;
}
signed main() {
int a;
cin >> a;
vector<int> b(a), c(1000010, 0);
rep(i, a) cin >> b[i];
rep(i, a) { c[b[i]] += 1; }
if (c[1] == 0) {
int d = 0;
rep(i, a) {
int e = 1;
rep(j, sqrt(b[i]) + 0.1) {
if (j == 0) {
if (c[b[i]] > 1) {
e = 0;
break;
}
} else {
if (b[i] != 2 && b[i] != 3) {
if (b[i] % (j + 1) == 0) {
if ((c[j + 1]) || (c[b[i] / (j + 1)])) {
e = 0;
break;
}
}
}
}
}
d += e;
}
out(d);
} else if (c[1] == 1)
out(1);
else
out(0);
}
| delete | 141 | 143 | 141 | 141 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 998244353;
vector<ll> ans;
ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
ll multiply(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll power(ll a, ll b) {
if (b == 0)
return 1;
ll temp = power(a, b / 2);
if (b % 2 == 1)
return multiply(temp, multiply(temp, a));
else
return multiply(temp, temp);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin >> n;
map<ll, ll> s;
vector<ll> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
s[v[i]]++;
}
ll c = 0, ans = 0;
for (int i = 0; i < n; i++) {
c = 0;
for (int j = 1; j <= sqrt(v[i]); j++) {
if ((v[i] % j) == 0) {
if (s.find(j) != s.end()) {
c += s[j];
}
if ((v[i] / j) != j && s.find(v[i] / j) != s.end()) {
c += s[v[i] / j];
}
}
}
if (c == 1) {
ans++;
}
}
cout << ans << "\n";
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 998244353;
vector<ll> ans;
ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
ll multiply(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll power(ll a, ll b) {
if (b == 0)
return 1;
ll temp = power(a, b / 2);
if (b % 2 == 1)
return multiply(temp, multiply(temp, a));
else
return multiply(temp, temp);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin >> n;
unordered_map<ll, ll> s;
vector<ll> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
s[v[i]]++;
}
ll c = 0, ans = 0;
for (int i = 0; i < n; i++) {
c = 0;
for (int j = 1; j <= sqrt(v[i]); j++) {
if ((v[i] % j) == 0) {
if (s.find(j) != s.end()) {
c += s[j];
}
if ((v[i] / j) != j && s.find(v[i] / j) != s.end()) {
c += s[v[i] / j];
}
}
}
if (c == 1) {
ans++;
}
}
cout << ans << "\n";
}
| replace | 26 | 27 | 26 | 27 | TLE | |
p02642 | C++ | Time Limit Exceeded | /*
* D.cpp
*
* Created on: 2020/06/14
* Author: admin
*/
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
int main() {
long long N;
cin >> N;
long long A[N];
for (int i = 0; i < N; i++) {
cin >> A[i];
}
bool dp[1000010];
for (int i = 0; i < 1000010; i++)
dp[i] = true;
sort(A, A + SIZE_OF_ARRAY(A));
long long count = 0;
for (int i = 0; i < N; i++) {
if (i < N - 1) {
if (A[i] == A[i + 1]) {
for (long long m = 1; A[i] * m < 1000010; m++) {
dp[A[i] * m] = false;
}
}
}
if (dp[A[i]]) {
count++;
for (long long m = 1; A[i] * m < 1000010; m++) {
dp[A[i] * m] = false;
}
}
}
cout << count;
}
| /*
* D.cpp
*
* Created on: 2020/06/14
* Author: admin
*/
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
int main() {
long long N;
cin >> N;
long long A[N];
for (int i = 0; i < N; i++) {
cin >> A[i];
}
bool dp[1000010];
for (int i = 0; i < 1000010; i++)
dp[i] = true;
sort(A, A + SIZE_OF_ARRAY(A));
long long count = 0;
for (int i = 0; i < N; i++) {
if (dp[A[i]]) {
if (i < N - 1) {
if (A[i] == A[i + 1]) {
for (long long m = 1; A[i] * m < 1000010; m++) {
dp[A[i] * m] = false;
}
}
}
}
if (dp[A[i]]) {
count++;
for (long long m = 1; A[i] * m < 1000010; m++) {
dp[A[i] * m] = false;
}
}
}
cout << count;
}
| replace | 30 | 34 | 30 | 36 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define endl "\n"
#define p pair<int, int>
#define arrinp(i, a, start, end) \
; \
for (ll i = start; i <= end; i++) \
cin >> a[i];
#define arrout(i, a, start, end) \
; \
for (ll i = start; i <= end; i++) \
cout << a[i] << " ";
#define swap(a, b) \
{ \
a = a + b; \
b = a - b; \
a = a - b;
#define forfront(i, start, end) for (ll i = start; i <= end; i++)
#define forback(i, start, end) for (ll i = start; i >= end; i--)
#define out(x) cout << x << " "
#define outline(x) cout << x << endl;
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int a[n];
set<int> s;
int count = 0;
int maxele = 0;
map<int, int> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
m[a[i]]++;
s.insert(a[i]);
maxele = max(maxele, a[i]);
}
set<int> f;
for (int x : s) {
for (int i = x; i <= maxele; i += x) {
if (i != x) {
if (s.find(i) != s.end()) {
f.insert(i);
}
}
}
}
for (int x : s) {
if (m[x] > 1) {
if (f.find(x) != f.end())
count += m[x] - 1;
else
count += m[x];
}
}
int ans = count + f.size();
// outline(count);
// outline(f.size());
ans = n - ans;
outline(ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define endl "\n"
#define p pair<int, int>
#define arrinp(i, a, start, end) \
; \
for (ll i = start; i <= end; i++) \
cin >> a[i];
#define arrout(i, a, start, end) \
; \
for (ll i = start; i <= end; i++) \
cout << a[i] << " ";
#define swap(a, b) \
{ \
a = a + b; \
b = a - b; \
a = a - b;
#define forfront(i, start, end) for (ll i = start; i <= end; i++)
#define forback(i, start, end) for (ll i = start; i >= end; i--)
#define out(x) cout << x << " "
#define outline(x) cout << x << endl;
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int a[n];
set<int> s;
int count = 0;
int maxele = 0;
map<int, int> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
m[a[i]]++;
s.insert(a[i]);
maxele = max(maxele, a[i]);
}
set<int> f;
for (int x : s) {
for (int i = x; i <= maxele; i += x) {
if (i != x) {
if (s.find(i) != s.end()) {
f.insert(i);
}
}
}
if (m[x] > 1) {
if (f.find(x) != f.end())
count += m[x] - 1;
else
count += m[x];
}
}
int ans = count + f.size();
// outline(count);
// outline(f.size());
ans = n - ans;
outline(ans);
return 0;
} | delete | 52 | 54 | 52 | 52 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
int main() {
int N;
scanf("%d", &N);
std::vector<int> A(N);
for (int i = 0; i < N; i++) {
scanf("%d", &A[i]);
}
// printf("read\n");
std::sort(A.begin(), A.end());
std::vector<int> count(1000004, 0);
for (int i = 0; i < N; i++) {
// printf("i=%d\n", i);
for (int j = A[i]; j < 1000004; j += A[i]) {
count[j]++;
}
}
int ans = 0;
for (int i = 0; i < N; i++) {
if (count[A[i]] == 1)
ans++;
}
std::cout << ans << std::endl;
return 0;
}
| #include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
int main() {
int N;
scanf("%d", &N);
std::vector<int> A(N);
for (int i = 0; i < N; i++) {
scanf("%d", &A[i]);
}
// printf("read\n");
std::sort(A.begin(), A.end());
std::vector<int> count(1000004, 0);
for (int i = 0; i < N; i++) {
// printf("i=%d\n", i);
if (count[A[i]] > 0) {
count[A[i]]++;
continue;
}
for (int j = A[i]; j < 1000004; j += A[i]) {
count[j]++;
}
}
int ans = 0;
for (int i = 0; i < N; i++) {
if (count[A[i]] == 1)
ans++;
}
std::cout << ans << std::endl;
return 0;
}
| insert | 27 | 27 | 27 | 31 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int a[111111], b[1111111];
int main() {
int n, c = 0;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++) {
if (b[a[i]] > 1)
c--, b[a[i]]--;
if (b[a[i]])
continue;
for (int j = a[i]; j < 1111111; j += a[i])
b[j] = 1;
b[a[i]]++;
c++;
}
cout << c << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int a[222222], b[1111111];
int main() {
int n, c = 0;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++) {
if (b[a[i]] > 1)
c--, b[a[i]]--;
if (b[a[i]])
continue;
for (int j = a[i]; j < 1111111; j += a[i])
b[j] = 1;
b[a[i]]++;
c++;
}
cout << c << endl;
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02642 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <stack>
#include <vector>
#define MAX_N 90
using namespace std;
bool criba[MAX_N + 1];
int ocurrences[MAX_N + 1];
int main() {
int N, i, A, j, counter;
scanf("%d", &N);
memset(ocurrences, 0, sizeof ocurrences);
for (i = 0; i < N; ++i) {
scanf("%d", &A);
++ocurrences[A];
}
memset(criba, 0, sizeof criba);
for (i = 1; i <= MAX_N; ++i)
if (ocurrences[i]) {
j = (ocurrences[i] > 1) ? i : 2 * i;
while (j <= MAX_N) {
if (ocurrences[j])
criba[j] = true;
j += i;
}
}
counter = 0;
for (i = 0; i <= MAX_N; ++i)
if (!criba[i])
counter += ocurrences[i];
printf("%d", counter);
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <stack>
#include <vector>
#define MAX_N 1000000
using namespace std;
bool criba[MAX_N + 1];
int ocurrences[MAX_N + 1];
int main() {
int N, i, A, j, counter;
scanf("%d", &N);
memset(ocurrences, 0, sizeof ocurrences);
for (i = 0; i < N; ++i) {
scanf("%d", &A);
++ocurrences[A];
}
memset(criba, 0, sizeof criba);
for (i = 1; i <= MAX_N; ++i)
if (ocurrences[i]) {
j = (ocurrences[i] > 1) ? i : 2 * i;
while (j <= MAX_N) {
if (ocurrences[j])
criba[j] = true;
j += i;
}
}
counter = 0;
for (i = 0; i <= MAX_N; ++i)
if (!criba[i])
counter += ocurrences[i];
printf("%d", counter);
return 0;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p02642 | C++ | Runtime Error | #include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
int n, tmp;
cin >> n;
int count_a[11] = {0};
int a_max = -1;
vector<int> b;
int count = 0;
for (int i = 0; i < n; i++) {
cin >> tmp;
count_a[tmp]++;
if (a_max < tmp) {
a_max = tmp;
}
}
if (count_a[1] > 1) {
cout << 0 << endl;
return 0;
}
/*
for(int i= 1;i <= a_max;i++){
if(count_a[i] == 1){
b.push_back(i);
}
}
*/
int blength = b.size();
bool dp[a_max + 1];
for (int i = 0; i < a_max + 1; i++) {
dp[i] = true;
}
for (int i = 1; i <= a_max; i++) {
if (count_a[i] >= 1) {
tmp = i;
for (int j = tmp + tmp; j <= a_max; j += tmp) {
dp[j] = false;
}
}
}
for (int i = 1; i <= a_max; i++) {
if (count_a[i] == 1) {
tmp = i;
if (dp[tmp]) {
count++;
}
}
}
cout << count << endl;
return 0;
}
/*
5
24 11 8 3 16
4
5 5 5 5
10
33 18 45 28 8 19 89 86 2 4
*/ | #include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
int n, tmp;
cin >> n;
int count_a[1000001] = {0};
int a_max = -1;
vector<int> b;
int count = 0;
for (int i = 0; i < n; i++) {
cin >> tmp;
count_a[tmp]++;
if (a_max < tmp) {
a_max = tmp;
}
}
if (count_a[1] > 1) {
cout << 0 << endl;
return 0;
}
/*
for(int i= 1;i <= a_max;i++){
if(count_a[i] == 1){
b.push_back(i);
}
}
*/
int blength = b.size();
bool dp[a_max + 1];
for (int i = 0; i < a_max + 1; i++) {
dp[i] = true;
}
for (int i = 1; i <= a_max; i++) {
if (count_a[i] >= 1) {
tmp = i;
for (int j = tmp + tmp; j <= a_max; j += tmp) {
dp[j] = false;
}
}
}
for (int i = 1; i <= a_max; i++) {
if (count_a[i] == 1) {
tmp = i;
if (dp[tmp]) {
count++;
}
}
}
cout << count << endl;
return 0;
}
/*
5
24 11 8 3 16
4
5 5 5 5
10
33 18 45 28 8 19 89 86 2 4
*/ | replace | 8 | 9 | 8 | 9 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for (UL i = 0; i < (n); i++)
UL C[1000001] = {};
UL N;
UL A[200000];
int main() {
scanf("%u", &N);
rep(i, N) scanf("%u", A + i);
sort(A, A + N);
UL ans = 0;
rep(i, N) {
C[A[i]]++;
if (!C[A[i]])
continue;
for (UL j = A[i] + A[i]; j <= 1000000; j += A[i])
C[j]++;
}
rep(i, N) if (C[A[i]] <= 1) ans++;
printf("%u", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for (UL i = 0; i < (n); i++)
UL C[1000001] = {};
UL N;
UL A[200000];
int main() {
scanf("%u", &N);
rep(i, N) scanf("%u", A + i);
sort(A, A + N);
UL ans = 0;
rep(i, N) {
C[A[i]]++;
if (C[A[i]] > 1)
continue;
for (UL j = A[i] + A[i]; j <= 1000000; j += A[i])
C[j]++;
}
rep(i, N) if (C[A[i]] <= 1) ans++;
printf("%u", ans);
return 0;
}
| replace | 18 | 19 | 18 | 19 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
#define lol long long
#define gcd(x, y) __gcd(x, y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed << setprecision(14)
using namespace std;
using pii = pair<int, int>;
template <class A, class B> inline bool chmax(A &a, const B &b) {
return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
return b < a && (a = b, true);
}
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
const lol inf = (1LL << 60);
const lol MOD = (1e9) + 7;
const lol mod = 998244353;
const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
lol n, m, k, r, q;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
vector<int> a(n + 1, 0);
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a.begin(), a.end() - 1);
lol ma = a[n - 1];
vector<int> dp(ma + 1, 0);
lol ans = 0;
for (int i = 0; i < n; i++) {
if (dp[a[i]] == 0) {
if (a[i] != a[i + 1])
ans++;
for (int j = a[i]; j <= 1000000; j += a[i])
dp[j]++;
}
}
cout << ans << '\n';
return (0);
}
| #include <bits/stdc++.h>
#define lol long long
#define gcd(x, y) __gcd(x, y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed << setprecision(14)
using namespace std;
using pii = pair<int, int>;
template <class A, class B> inline bool chmax(A &a, const B &b) {
return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
return b < a && (a = b, true);
}
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
const lol inf = (1LL << 60);
const lol MOD = (1e9) + 7;
const lol mod = 998244353;
const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
lol n, m, k, r, q;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
vector<int> a(n + 1, 0);
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a.begin(), a.end() - 1);
lol ma = a[n - 1];
vector<int> dp(1000000 + 1, 0);
lol ans = 0;
for (int i = 0; i < n; i++) {
if (dp[a[i]] == 0) {
if (a[i] != a[i + 1])
ans++;
for (int j = a[i]; j <= 1000000; j += a[i])
dp[j]++;
}
}
cout << ans << '\n';
return (0);
}
| replace | 33 | 34 | 33 | 34 | -11 | |
p02642 | C++ | Time Limit Exceeded | #include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
bool exist[1000004];
bool duplicate[1000004];
bool dfs(std::vector<int> pr, std::vector<int> yakusuu, int val, int index,
int orig) {
if (index == yakusuu.size()) {
if (val == orig)
return false;
else if (exist[val])
return true;
else
return false;
} else {
bool ret = false;
int target = yakusuu[index];
int num = pr[target];
int multiple = 1;
for (int i = 0; i <= num; i++) {
ret |= dfs(pr, yakusuu, val * multiple, index + 1, orig);
multiple *= target;
if (ret)
return true;
}
return ret;
}
}
int main() {
int N;
scanf("%d", &N);
std::vector<int> A(N);
for (int i = 0; i < 1000004; i++) {
exist[i] = false;
duplicate[i] = false;
}
for (int i = 0; i < N; i++) {
scanf("%d", &A[i]);
}
std::sort(A.begin(), A.end());
for (int i = 0; i < N; i++) {
if (exist[A[i]]) {
duplicate[A[i]] = true;
;
} else {
exist[A[i]] = true;
}
}
int ans = 0;
std::vector<int> prime;
std::vector<bool> isprime(10004, true);
for (int i = 2; i * i <= 1000004; i++) {
if (isprime[i]) {
prime.push_back(i);
for (int j = 2 * i; j * j < 1000004; j += i) {
isprime[j] = false;
}
}
}
std::sort(prime.begin(), prime.end());
std::vector<int> pr(1000004, 0);
for (int i = 0; i < N; i++) {
// printf("i=%d\n", i);
if (duplicate[A[i]])
continue;
std::vector<int> yakusuu;
int temp = A[i];
for (int p : prime) {
// printf("temp=%d, p=%d\n", temp, p);
if (p * p > temp)
break;
while (temp % p == 0) {
if (pr[p] == 0)
yakusuu.push_back(p);
pr[p]++;
temp = temp / p;
// printf("in while temp=%d, p=%d\n", temp, p);
}
}
if (temp != 1) {
yakusuu.push_back(temp);
pr[temp]++;
}
// printf("prime calc end\n");
bool existyakusuu = dfs(pr, yakusuu, 1, 0, A[i]);
if (!existyakusuu)
ans++;
// printf("exist yakusuu = %d\n", existyakusuu);
for (int p : yakusuu) {
pr[p] = 0;
}
}
std::cout << ans << std::endl;
return 0;
}
| #include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
bool exist[1000004];
bool duplicate[1000004];
bool dfs(std::vector<int> &pr, std::vector<int> &yakusuu, int val, int index,
int orig) {
if (index == yakusuu.size()) {
if (val == orig)
return false;
else if (exist[val])
return true;
else
return false;
} else {
bool ret = false;
int target = yakusuu[index];
int num = pr[target];
int multiple = 1;
for (int i = 0; i <= num; i++) {
ret |= dfs(pr, yakusuu, val * multiple, index + 1, orig);
multiple *= target;
if (ret)
return true;
}
return ret;
}
}
int main() {
int N;
scanf("%d", &N);
std::vector<int> A(N);
for (int i = 0; i < 1000004; i++) {
exist[i] = false;
duplicate[i] = false;
}
for (int i = 0; i < N; i++) {
scanf("%d", &A[i]);
}
std::sort(A.begin(), A.end());
for (int i = 0; i < N; i++) {
if (exist[A[i]]) {
duplicate[A[i]] = true;
;
} else {
exist[A[i]] = true;
}
}
int ans = 0;
std::vector<int> prime;
std::vector<bool> isprime(10004, true);
for (int i = 2; i * i <= 1000004; i++) {
if (isprime[i]) {
prime.push_back(i);
for (int j = 2 * i; j * j < 1000004; j += i) {
isprime[j] = false;
}
}
}
std::sort(prime.begin(), prime.end());
std::vector<int> pr(1000004, 0);
for (int i = 0; i < N; i++) {
// printf("i=%d\n", i);
if (duplicate[A[i]])
continue;
std::vector<int> yakusuu;
int temp = A[i];
for (int p : prime) {
// printf("temp=%d, p=%d\n", temp, p);
if (p * p > temp)
break;
while (temp % p == 0) {
if (pr[p] == 0)
yakusuu.push_back(p);
pr[p]++;
temp = temp / p;
// printf("in while temp=%d, p=%d\n", temp, p);
}
}
if (temp != 1) {
yakusuu.push_back(temp);
pr[temp]++;
}
// printf("prime calc end\n");
bool existyakusuu = dfs(pr, yakusuu, 1, 0, A[i]);
if (!existyakusuu)
ans++;
// printf("exist yakusuu = %d\n", existyakusuu);
for (int p : yakusuu) {
pr[p] = 0;
}
}
std::cout << ans << std::endl;
return 0;
}
| replace | 18 | 19 | 18 | 19 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define rep(i, cc, n) for (int i = cc; i < n; ++i)
#define lrep(i, cc, n) for (long long i = cc; i < n; ++i)
#define sqrep(i, cc, n) for (long long i = cc; i * i <= n; ++i)
#define rrep(i, cc, n) for (long i = cc; i > n; --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
using ll = long long;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9 = 1000000000;
const ll mod = 1000000007;
ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
int main() {
vector<bool> ans(200200, true);
int n;
cin >> n;
vector<int> a(n);
rep(i, 0, n) cin >> a[i];
sort(a.begin(), a.end(), greater<int>());
rep(i, 0, n) {
int p = a[i];
if (i == 0)
for (int j = 2 * p; j <= a[0]; j += p)
ans[j] = false;
else {
if (a[i] == a[i - 1])
for (int j = p; j <= a[0]; j += p)
ans[j] = false;
else
for (int j = 2 * p; j <= a[0]; j += p)
ans[j] = false;
}
}
int cnt = 0;
rep(i, 0, n) {
if (ans[a[i]])
cnt++;
}
cout << cnt << endl;
} | #include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define rep(i, cc, n) for (int i = cc; i < n; ++i)
#define lrep(i, cc, n) for (long long i = cc; i < n; ++i)
#define sqrep(i, cc, n) for (long long i = cc; i * i <= n; ++i)
#define rrep(i, cc, n) for (long i = cc; i > n; --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
using ll = long long;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9 = 1000000000;
const ll mod = 1000000007;
ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
int main() {
vector<bool> ans(2002000, true);
int n;
cin >> n;
vector<int> a(n);
rep(i, 0, n) cin >> a[i];
sort(a.begin(), a.end(), greater<int>());
rep(i, 0, n) {
int p = a[i];
if (i == 0)
for (int j = 2 * p; j <= a[0]; j += p)
ans[j] = false;
else {
if (a[i] == a[i - 1])
for (int j = p; j <= a[0]; j += p)
ans[j] = false;
else
for (int j = 2 * p; j <= a[0]; j += p)
ans[j] = false;
}
}
int cnt = 0;
rep(i, 0, n) {
if (ans[a[i]])
cnt++;
}
cout << cnt << endl;
} | replace | 35 | 36 | 35 | 36 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define A_MAX 2000100
bool dp[A_MAX];
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++)
cin >> A[i];
sort(A.begin(), A.end());
fill(dp, dp + A_MAX, true);
for (int i = N - 1; i >= 0; i--) {
if (i < N - 1 && A[i + 1] == A[i])
dp[A[i]] = false;
int tmp = 2 * A[i];
while (tmp <= A_MAX) {
dp[tmp] = false;
tmp += A[i];
}
}
int ans = 0;
for (int i = 0; i < N; i++) {
if (dp[A[i]])
ans++;
}
cout << ans << endl;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define A_MAX 2000100
bool dp[A_MAX];
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++)
cin >> A[i];
sort(A.begin(), A.end());
fill(dp, dp + A_MAX, true);
for (int i = 0; i < N; i++) {
if (!dp[A[i]])
continue;
if (i > 0 && A[i - 1] == A[i])
dp[A[i]] = false;
int tmp = 2 * A[i];
while (tmp <= A_MAX) {
dp[tmp] = false;
tmp += A[i];
}
}
int ans = 0;
for (int i = 0; i < N; i++) {
if (dp[A[i]])
ans++;
}
cout << ans << endl;
} | replace | 16 | 18 | 16 | 20 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
template <typename T> void print_vector(vector<T> &vec) {
cout << "print_vector -> ";
for (int i = 0; i < vec.size(); i++) {
if (i == vec.size() - 1) {
cout << vec[i] << endl;
} else {
cout << vec[i] << " ";
}
}
return;
}
vector<int> v;
void solve(int n) {
if (n <= 1)
return;
int l = sqrt(n);
for (int i = 2; i <= l; i++) {
if (n % i == 0) {
solve(i);
solve((int)(n / i));
return;
}
}
v.push_back(n);
return;
}
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++)
cin >> A[i];
vector<int> map(1000010, 0);
for (int i = 0; i < N; i++) {
if (map[A[i]] == 1) {
map[A[i]]++;
continue;
}
for (int j = A[i]; j < 1000010; j += A[i]) {
map[j]++;
}
}
int ans = 0;
for (int a : A) {
if (map[a] == 1)
ans++;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
template <typename T> void print_vector(vector<T> &vec) {
cout << "print_vector -> ";
for (int i = 0; i < vec.size(); i++) {
if (i == vec.size() - 1) {
cout << vec[i] << endl;
} else {
cout << vec[i] << " ";
}
}
return;
}
vector<int> v;
void solve(int n) {
if (n <= 1)
return;
int l = sqrt(n);
for (int i = 2; i <= l; i++) {
if (n % i == 0) {
solve(i);
solve((int)(n / i));
return;
}
}
v.push_back(n);
return;
}
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++)
cin >> A[i];
vector<int> map(1000010, 0);
for (int i = 0; i < N; i++) {
if (map[A[i]] >= 1) {
map[A[i]]++;
continue;
}
for (int j = A[i]; j < 1000010; j += A[i]) {
map[j]++;
}
}
int ans = 0;
for (int a : A) {
if (map[a] == 1)
ans++;
}
cout << ans << endl;
return 0;
} | replace | 43 | 44 | 43 | 44 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace std;
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db double
#define eps 1e-8
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
const ll mod = 1e9 + 9;
const ll maxn = 2e5 + 10;
const ll mxe = 1e6 + 10;
bool divided[mxe];
vector<int> arr;
map<int, int> occ;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
arr.resize(n);
for (auto &i : arr)
cin >> i, occ[i]++;
sort(all(arr));
ll res = 0;
for (auto i : arr) {
if (!divided[i] && occ[i] == 1) {
res++;
}
for (int j = 1; j * i < mxe; j++) {
divided[j * i] = 1;
}
}
cout << res << endl;
} | #include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace std;
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db double
#define eps 1e-8
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
const ll mod = 1e9 + 9;
const ll maxn = 2e5 + 10;
const ll mxe = 1e6 + 10;
bool divided[mxe];
vector<int> arr;
map<int, int> occ;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
arr.resize(n);
for (auto &i : arr)
cin >> i, occ[i]++;
sort(all(arr));
ll res = 0;
for (auto i : arr) {
if (!divided[i] && occ[i] == 1) {
res++;
}
if (!divided[i]) {
for (int j = 1; j * i < mxe; j++) {
divided[j * i] = 1;
}
}
}
cout << res << endl;
} | replace | 37 | 39 | 37 | 41 | TLE | |
p02642 | C++ | Time Limit Exceeded | #pragma GCC target("avx2")
#pragma GCC optimize "trapv"
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define si(a) scanf("%d", &a)
#define si2(a, b) scanf("%d%d", &a, &b)
#define sl(a) scanf("%lld", &a)
#define sl2(a, b) scanf("%lld%lld", &a, &b)
#define pb push_back
#define mk make_pair
#define loop(n) for (int i = 0; i < n; i++)
#define FOR(a, b) for (int i = a; i <= b; i++)
#define sz size()
#define ff first
#define ss second
#define mem(a, val) memset(a, val, sizeof(a))
#define md 1000000007
#define pi acos(-1.0)
ll a[200010], m[1000005];
int main() {
ll t, n, i, j, k, l, r, mn = 0, mx = 1;
cin >> n;
ll cnt = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
m[a[i]]++;
}
ll f = 0;
for (int i = 0; i < n; i++) {
f = 0;
if (m[a[i]] > 1)
continue;
for (ll j = 1; j * j <= a[i]; j++) {
if (a[i] % j == 0) {
if (m[j] > 0 && j != a[i])
f = 1;
ll p = a[i] / j;
if (m[p] > 0 && p != a[i])
f = 1;
}
}
// cout<<a[i]<<" "<<f<<endl;
if (f == 0)
cnt++;
}
cout << cnt;
}
| #pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define si(a) scanf("%d", &a)
#define si2(a, b) scanf("%d%d", &a, &b)
#define sl(a) scanf("%lld", &a)
#define sl2(a, b) scanf("%lld%lld", &a, &b)
#define pb push_back
#define mk make_pair
#define loop(n) for (int i = 0; i < n; i++)
#define FOR(a, b) for (int i = a; i <= b; i++)
#define sz size()
#define ff first
#define ss second
#define mem(a, val) memset(a, val, sizeof(a))
#define md 1000000007
#define pi acos(-1.0)
ll a[200010], m[1000005];
int main() {
ll t, n, i, j, k, l, r, mn = 0, mx = 1;
cin >> n;
ll cnt = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
m[a[i]]++;
}
ll f = 0;
for (int i = 0; i < n; i++) {
f = 0;
if (m[a[i]] > 1)
continue;
for (ll j = 1; j * j <= a[i]; j++) {
if (a[i] % j == 0) {
if (m[j] > 0 && j != a[i])
f = 1;
ll p = a[i] / j;
if (m[p] > 0 && p != a[i])
f = 1;
}
}
// cout<<a[i]<<" "<<f<<endl;
if (f == 0)
cnt++;
}
cout << cnt;
}
| delete | 1 | 2 | 1 | 1 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define lld long long
#define pb push_back
#define mk make_pair
#define MAX (lld)1e5 + 7
#define lim (lld)1e9 + 7
#define MAX2 (int)1e6 + 9
#define ff first
#define ss second
#define fastio \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
const lld mod = lim;
lld power(lld x, lld y, lld p) {
lld res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int extend_gcd(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int x1, y1;
int d = extend_gcd(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
int rowNum[] = {-1, 0, 0, 1};
int colNum[] = {0, -1, 1, 0};
std::vector<int> vis(MAX2);
int main() {
fastio int n, ans = 0;
cin >> n;
std::vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
for (int j = v[i]; j <= MAX2; j += v[i]) {
vis[j]++;
}
}
for (int i = 0; i < n; i++) {
if (vis[v[i]] == 1)
ans++;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define lld long long
#define pb push_back
#define mk make_pair
#define MAX (lld)1e5 + 7
#define lim (lld)1e9 + 7
#define MAX2 (int)1e6 + 9
#define ff first
#define ss second
#define fastio \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
const lld mod = lim;
lld power(lld x, lld y, lld p) {
lld res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int extend_gcd(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int x1, y1;
int d = extend_gcd(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
int rowNum[] = {-1, 0, 0, 1};
int colNum[] = {0, -1, 1, 0};
std::vector<int> vis(MAX2);
int main() {
fastio int n, ans = 0;
cin >> n;
std::vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
for (int j = v[i]; j <= v[n - 1]; j += v[i]) {
vis[j]++;
}
}
for (int i = 0; i < n; i++) {
if (vis[v[i]] == 1)
ans++;
}
cout << ans << endl;
} | replace | 62 | 63 | 62 | 63 | TLE | |
p02642 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(s, i, n) for (i = s; i < n; i++)
using namespace std;
int ans, N, A[200001];
int a[200001];
bool f[200001];
int main() {
int b, i, j, m;
cin >> N;
rep(1, i, N + 1) {
cin >> A[i];
a[A[i]]++;
m = max(m, A[i]);
}
rep(1, i, N + 1) {
if (a[A[i]] > 1)
f[A[i]] = true;
for (j = A[i] * 2; j < m + 1; j += A[i])
f[j] = true;
}
rep(1, i, N + 1) {
if (!f[A[i]])
ans++;
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(s, i, n) for (i = s; i < n; i++)
using namespace std;
int ans, N, A[200001];
int a[1000001];
bool f[1000001];
int main() {
int b, i, j, m;
cin >> N;
rep(1, i, N + 1) {
cin >> A[i];
a[A[i]]++;
m = max(m, A[i]);
}
rep(1, i, N + 1) {
if (a[A[i]] > 1)
f[A[i]] = true;
for (j = A[i] * 2; j < m + 1; j += A[i])
f[j] = true;
}
rep(1, i, N + 1) {
if (!f[A[i]])
ans++;
}
cout << ans << endl;
return 0;
} | replace | 11 | 13 | 11 | 13 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep_ll(i, x, n) for (ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main() {
const int MAX_SIZE = 1000005;
bool num[MAX_SIZE];
rep(i, 0, MAX_SIZE) num[i] = false;
int n;
cin >> n;
vector<int> a(n);
rep(i, 0, n) cin >> a[i];
sort(a.begin(), a.end());
int cnt = 0;
// エラトステネスの篩
rep(i, 0, n) {
if (num[a[i]] == true)
continue;
// 重複判定、昇順なのでこれでOK
if (!(i < n - 1 && a[i] == a[i + 1]))
cnt++;
for (int j = a[i]; i < MAX_SIZE; j += a[i])
num[j] = true;
}
cout << cnt;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep_ll(i, x, n) for (ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main() {
const int MAX_SIZE = 1000005;
bool num[MAX_SIZE];
rep(i, 0, MAX_SIZE) num[i] = false;
int n;
cin >> n;
vector<int> a(n);
rep(i, 0, n) cin >> a[i];
sort(a.begin(), a.end());
int cnt = 0;
// エラトステネスの篩
rep(i, 0, n) {
if (num[a[i]] == true)
continue;
// 重複判定、昇順なのでこれでOK
if (!(i < n - 1 && a[i] == a[i + 1]))
cnt++;
for (int j = a[i]; j < MAX_SIZE; j += a[i])
num[j] = true;
}
cout << cnt;
return 0;
} | replace | 30 | 31 | 30 | 31 | TLE | |
p02642 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <unordered_set>
#define ll long long
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
vector<ll> d(n);
ll sz = 1000000;
vector<bool> arr(sz, true);
unordered_set<ll> st;
for (int i = 0; i < n; i++) {
cin >> d[i];
if (st.find(d[i]) == st.end()) {
st.insert(d[i]);
for (ll j = d[i] * 2; j < sz; j += d[i]) {
arr[j] = false;
}
} else {
arr[d[i]] = false;
}
}
ll ans = 0;
for (ll i = 0; i < (ll)(d.size()); i++) {
if (arr[d[i]]) {
ans++;
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <bits/stdc++.h>
#include <unordered_set>
#define ll long long
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
vector<ll> d(n);
ll sz = 1000001;
vector<bool> arr(sz, true);
unordered_set<ll> st;
for (int i = 0; i < n; i++) {
cin >> d[i];
if (st.find(d[i]) == st.end()) {
st.insert(d[i]);
for (ll j = d[i] * 2; j < sz; j += d[i]) {
arr[j] = false;
}
} else {
arr[d[i]] = false;
}
}
ll ans = 0;
for (ll i = 0; i < (ll)(d.size()); i++) {
if (arr[d[i]]) {
ans++;
}
}
cout << ans << endl;
return 0;
} | replace | 18 | 19 | 18 | 19 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type>
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())
#define FOR(i, A, B) for (auto i = (A); i != (B); i++)
#define FORD(i, A, B) for (auto i = (A); i != (B); i--)
#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))
using namespace std;
typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;
template <class U, class V> istream &operator>>(istream &in, pair<U, V> &pr) {
return in >> pr.first >> pr.second;
}
template <class U, class V> ostream &operator<<(ostream &out, pair<U, V> &p) {
return out << p.first << " " << p.second;
}
template <class T> ostream &operator<<(ostream &out, vector<T> vec) {
for (T &e : vec)
out << e << " ";
return out << endl;
}
// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
};
void solveSingleCase(int caseNo) {
int N;
cin >> N;
VEC(int) A(N);
READVEC(A);
const int MAXN = 1000000;
VEC(bool) bad(MAXN + 1, false);
map<int, int> counter;
for (int a : A) {
FOR(m, 2, MAXN / a + 1)
bad[a * m] = true;
counter[a]++;
if (counter[a] >= 2)
bad[a] = true;
}
int ret = 0;
for (int a : A)
if (!bad[a])
ret++;
cout << ret << endl;
};
int main(int argc, char **argv) {
io_init();
// Actual program code starts here.
int T = 1;
// cin >> T;
FOR(tcase, 1, T + 1) { solveSingleCase(tcase); }
return 0;
};
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type>
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())
#define FOR(i, A, B) for (auto i = (A); i != (B); i++)
#define FORD(i, A, B) for (auto i = (A); i != (B); i--)
#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))
using namespace std;
typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;
template <class U, class V> istream &operator>>(istream &in, pair<U, V> &pr) {
return in >> pr.first >> pr.second;
}
template <class U, class V> ostream &operator<<(ostream &out, pair<U, V> &p) {
return out << p.first << " " << p.second;
}
template <class T> ostream &operator<<(ostream &out, vector<T> vec) {
for (T &e : vec)
out << e << " ";
return out << endl;
}
// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
};
void solveSingleCase(int caseNo) {
int N;
cin >> N;
VEC(int) A(N);
READVEC(A);
const int MAXN = 1000000;
VEC(bool) bad(MAXN + 1, false);
map<int, int> counter;
for (int a : A)
if (!bad[a]) {
FOR(m, 2, MAXN / a + 1)
bad[a * m] = true;
counter[a]++;
if (counter[a] >= 2)
bad[a] = true;
}
int ret = 0;
for (int a : A)
if (!bad[a])
ret++;
cout << ret << endl;
};
int main(int argc, char **argv) {
io_init();
// Actual program code starts here.
int T = 1;
// cin >> T;
FOR(tcase, 1, T + 1) { solveSingleCase(tcase); }
return 0;
};
| replace | 74 | 81 | 74 | 82 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mpr make_pair
#define pr pair<lli, lli>
#define pb push_back
#define vl vector<lli>
#define mp map<lli, lli>
#define all(x) x.begin(), x.end()
#define FOR(i, n) for (lli i = 0; i < (lli)n; i++)
#define FOR1(i, j, n) for (lli i = j; i < (lli)n; i++)
#define mod 1000000007
lli gcd(lli a, lli b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
lli power(lli x, lli n, lli m) {
lli res = 1;
while (n > 0) {
if (n & 1)
res = (res * x) % m;
x = (x * x) % m;
n = n >> 1;
}
return res;
}
lli modInverse(lli n, lli p) { return power(n, p - 2, p); }
lli nCr(lli n, lli r, lli p) {
if (r == 0)
return 1;
lli fac[n + 1];
fac[0] = 1;
for (lli i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i % p;
return ((fac[n] * modInverse(fac[r], p) % p) % p * modInverse(fac[n - r], p) %
p) %
p;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
lli n, res = 0;
cin >> n;
vl v(n), cnt(200009, 0);
mp m;
for (lli i = 0; i < n; i++) {
cin >> v[i];
cnt[v[i]]++;
}
sort(all(v));
for (lli i = 0; i < n; i++) {
for (lli j = 2 * v[i]; j <= v.back(); j += v[i])
m[j]++;
}
for (lli i = 0; i < n; i++) {
if (cnt[v[i]] > 1)
continue;
if (m[v[i]] == 0)
res++;
}
cout << res << endl;
/*for(lli i=0;i<n;i++)
{
int cnt=0;
for(lli j=1;j*j<=v[i];j++)
{
if(v[i]%j==0)
{
if(j!=v[i]&&m[j]==1||j==v[i]&&m[j]>1)
{
cnt++;
break;
}
if(v[i]/j!=v[i]&&m[v[i]/j]==1||v[i]/j==v[i]&&m[v[i]/j]>1)
{
cnt++;
break;
}
//if(j!=v[i]&&m[j]==1&&j*j==v[i]) cnt--;
}
}
if(cnt==0) res++;
}
cout<<res<<endl;*/
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mpr make_pair
#define pr pair<lli, lli>
#define pb push_back
#define vl vector<lli>
#define mp map<lli, lli>
#define all(x) x.begin(), x.end()
#define FOR(i, n) for (lli i = 0; i < (lli)n; i++)
#define FOR1(i, j, n) for (lli i = j; i < (lli)n; i++)
#define mod 1000000007
lli gcd(lli a, lli b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
lli power(lli x, lli n, lli m) {
lli res = 1;
while (n > 0) {
if (n & 1)
res = (res * x) % m;
x = (x * x) % m;
n = n >> 1;
}
return res;
}
lli modInverse(lli n, lli p) { return power(n, p - 2, p); }
lli nCr(lli n, lli r, lli p) {
if (r == 0)
return 1;
lli fac[n + 1];
fac[0] = 1;
for (lli i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i % p;
return ((fac[n] * modInverse(fac[r], p) % p) % p * modInverse(fac[n - r], p) %
p) %
p;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
lli n, res = 0;
cin >> n;
vl v(n);
mp m, cnt;
for (lli i = 0; i < n; i++) {
cin >> v[i];
cnt[v[i]]++;
}
sort(all(v));
for (lli i = 0; i < n; i++) {
for (lli j = 2 * v[i]; j <= v.back(); j += v[i])
m[j]++;
}
for (lli i = 0; i < n; i++) {
if (cnt[v[i]] > 1)
continue;
if (m[v[i]] == 0)
res++;
}
cout << res << endl;
/*for(lli i=0;i<n;i++)
{
int cnt=0;
for(lli j=1;j*j<=v[i];j++)
{
if(v[i]%j==0)
{
if(j!=v[i]&&m[j]==1||j==v[i]&&m[j]>1)
{
cnt++;
break;
}
if(v[i]/j!=v[i]&&m[v[i]/j]==1||v[i]/j==v[i]&&m[v[i]/j]>1)
{
cnt++;
break;
}
//if(j!=v[i]&&m[j]==1&&j*j==v[i]) cnt--;
}
}
if(cnt==0) res++;
}
cout<<res<<endl;*/
return 0;
}
| replace | 51 | 53 | 51 | 53 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
for (int T = 0; T < t; T++) {
ll n, ans = 0;
cin >> n;
ll a[n];
int b[1000001] = {0};
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (int i = 1; i < n; i++) {
if (a[i] == a[i - 1])
b[a[i]] = 1;
}
for (int i = 0; i < n; i++) {
if (b[a[i]] != 1)
ans++;
for (int j = 2 * a[i]; j <= 1000000; j += a[i]) {
if (b[j] == 0)
b[j] = 1;
}
}
std::cout << ans << std::endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
for (int T = 0; T < t; T++) {
ll n, ans = 0;
cin >> n;
ll a[n];
int b[1000001] = {0};
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (int i = 1; i < n; i++) {
if (a[i] == a[i - 1])
b[a[i]] = 1;
}
for (int i = 0; i < n; i++) {
if (b[a[i]] != 1)
ans++;
if (a[i] != a[i - 1]) {
for (int j = 2 * a[i]; j <= 1000000; j += a[i]) {
if (b[j] == 0)
b[j] = 1;
}
}
}
std::cout << ans << std::endl;
}
return 0;
} | replace | 25 | 28 | 25 | 30 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 100005;
int a[MAX_N], cnt[1000005];
int main() {
int n;
cin >> n;
rep(i, n) {
cin >> a[i];
cnt[a[i]]++;
}
if (cnt[1] == 1) {
cout << "1" << endl;
return 0;
}
if (cnt[1] > 1) {
cout << "0" << endl;
return 0;
}
bool flag = true;
int ans = 0;
rep(i, n) {
flag = true;
if (cnt[a[i]] > 1)
flag = false;
for (int j = 2; j * j <= a[i]; ++j) {
if (a[i] % j == 0) {
if (cnt[j] > 0) {
flag = false;
break;
}
if (cnt[a[i] / j] > 0) {
flag = false;
break;
}
}
}
if (flag)
ans++;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 200005;
int a[MAX_N], cnt[1000005];
int main() {
int n;
cin >> n;
rep(i, n) {
cin >> a[i];
cnt[a[i]]++;
}
if (cnt[1] == 1) {
cout << "1" << endl;
return 0;
}
if (cnt[1] > 1) {
cout << "0" << endl;
return 0;
}
bool flag = true;
int ans = 0;
rep(i, n) {
flag = true;
if (cnt[a[i]] > 1)
flag = false;
for (int j = 2; j * j <= a[i]; ++j) {
if (a[i] % j == 0) {
if (cnt[j] > 0) {
flag = false;
break;
}
if (cnt[a[i] / j] > 0) {
flag = false;
break;
}
}
}
if (flag)
ans++;
}
cout << ans << endl;
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll, ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for (int i = 0; i < (b); i++)
#define f00(b) for (int j = 0; j < (b); j++)
#define f1(b) for (int i = 1; i <= (b); i++)
#define f11(b) for (int j = 1; j <= (b); j++)
#define f2(a, b) for (int i = (a); i <= (b); i++)
#define f22(a, b) for (int j = (a); j <= (b); j++)
#define sf(a) scanf("%lld", &a)
#define sff(a, b) scanf("%lld %lld", &a, &b)
#define pf(a) printf("%lld\n", a)
#define pff(a, b) printf("%lld %lld\n", a, b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a, b) memset(a, b, sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)
const ll mod = (ll)998244353;
const ll maxn = (ll)1e4 + 5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max() - 1;
// const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;
ll dx[] = {0, 1, 0, -1};
ll dy[] = {1, 0, -1, 0};
ll dxx[] = {0, 1, 0, -1, 1, 1, -1, -1};
ll dyy[] = {1, 0, -1, 0, 1, -1, 1, -1};
void solve() {
ll m[maxn];
map<ll, ll> num;
ll n;
mem(m, 0);
cin >> n;
ll a[n + 5];
f1(n) cin >> a[i], num[a[i]]++;
for (auto u : num) {
ll len = u.ss;
ll vr = u.ff;
for (ll i = vr; i <= (ll)maxn - 2; i += vr)
m[i] += len; // cout << i << ' ' << len << ' ' << vr << '\n';
// cout << len << '\n';
}
ll ans = 0;
for (ll i = 1; i <= n; i++) {
if (m[a[i]] == 1)
ans++;
// cout << m[a[i]] << '\n';
}
cout << ans;
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
ll T;
T = 1;
// cin >> T;
// scanf("%lld",&T);
ll CT = 0;
// work();
while (T--) {
// cout << "Case " << ++CT <<": " ;
// printf("Case %lld: ",++CT);
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll, ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for (int i = 0; i < (b); i++)
#define f00(b) for (int j = 0; j < (b); j++)
#define f1(b) for (int i = 1; i <= (b); i++)
#define f11(b) for (int j = 1; j <= (b); j++)
#define f2(a, b) for (int i = (a); i <= (b); i++)
#define f22(a, b) for (int j = (a); j <= (b); j++)
#define sf(a) scanf("%lld", &a)
#define sff(a, b) scanf("%lld %lld", &a, &b)
#define pf(a) printf("%lld\n", a)
#define pff(a, b) printf("%lld %lld\n", a, b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a, b) memset(a, b, sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)
const ll mod = (ll)998244353;
const ll maxn = (ll)1e6 + 5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max() - 1;
// const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;
ll dx[] = {0, 1, 0, -1};
ll dy[] = {1, 0, -1, 0};
ll dxx[] = {0, 1, 0, -1, 1, 1, -1, -1};
ll dyy[] = {1, 0, -1, 0, 1, -1, 1, -1};
void solve() {
ll m[maxn];
map<ll, ll> num;
ll n;
mem(m, 0);
cin >> n;
ll a[n + 5];
f1(n) cin >> a[i], num[a[i]]++;
for (auto u : num) {
ll len = u.ss;
ll vr = u.ff;
for (ll i = vr; i <= (ll)maxn - 2; i += vr)
m[i] += len; // cout << i << ' ' << len << ' ' << vr << '\n';
// cout << len << '\n';
}
ll ans = 0;
for (ll i = 1; i <= n; i++) {
if (m[a[i]] == 1)
ans++;
// cout << m[a[i]] << '\n';
}
cout << ans;
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
ll T;
T = 1;
// cin >> T;
// scanf("%lld",&T);
ll CT = 0;
// work();
while (T--) {
// cout << "Case " << ++CT <<": " ;
// printf("Case %lld: ",++CT);
solve();
}
return 0;
}
| replace | 41 | 42 | 41 | 42 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < n; i++)
#define Rep(i, m, n) for (long long i = m; i < n; i++)
#define REP(i, m, n, p) for (long long i = m; i < n; i += p)
#define all(v) v.begin(), v.end()
#define pq priority_queue
#define bcnt(n) __builtin_popcountll(n)
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using ll = long long; // long longをllだけにした
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using mii = map<int, int>;
using pqll = priority_queue<long long>;
using pqllg = priority_queue<long long, vector<long long>, greater<long long>>;
using mll = map<long long, long long>;
using pll = pair<long long, long long>;
using sll = set<long long>;
using vpll = vector<pair<long long, long long>>;
using mlv = map<long long, vector<long long>>;
long long divup(long long a, long long b);
long long kaijou(long long i);
long long P(long long n, long long k);
long long C(long long n, long long k);
long long GCD(long long a, long long b);
long long LCM(long long a, long long b);
bool prime(long long N);
double distance(vector<long long> p, vector<long long> q, long long n);
void press(vector<long long> &v);
void ranking(vector<long long> &v);
void erase(vector<long long> &v, long long i);
void unique(vector<long long> &v);
void printv(vector<long long> v);
vector<long long> keta(ll x);
long long modpow(long long a, long long n, long long mod);
long long modinv(long long a, long long mod);
// 20200416
vector<long long> inputv(long long n);
// 20200417
vector<long long> yakusuu(int n);
map<long long, long long> soinsuu(long long n);
vector<vector<long long>> maze(long long i, long long j, vector<string> &s);
// 20200423
vector<long long> eratos(long long n);
set<long long> eraset(long long n);
//////////////////////////////////////////////////////
// 端数繰りあがり割り算(検証済)
// a÷bの端数繰り上げ
// b!=0のデバグはしてないので分母に0を入れないように
// 負数対応
long long divup(long long a, long long b) {
long long x = abs(a);
long long y = abs(b);
long long z = (x + y - 1) / y;
if ((a < 0 && b > 0) || (a > 0 && b < 0))
return -z;
else if (a == 0)
return 0;
else
return z;
}
// 階乗
// 検証済み
long long kaijou(long long i) {
if (i == 0)
return 1;
long long j = 1;
for (long long k = 1; k <= i; k++) {
j *= k;
}
return j;
}
// 順列nPk(完成)
// n個の異なる要素から、取り出す順序を区別してk個取り出す場合の数
// n<kなら0を返す
// 敢えて負数時のデバグはしてない
long long P(long long n, long long k) {
if (n < k)
return 0;
long long y = 1;
for (long long i = 0; i < k; i++) {
y *= (n - i);
}
return y;
}
// 組み合わせnCk(検証済み)
// P,kaijouと併用
long long C(long long n, long long k) {
if (n < k)
return 0;
return P(n, k) / kaijou(k);
}
// nHk
// 区別しないn個の要素を、区別するk個のグループに分ける
// 0個のグループがあっ
// て良い
// C必須
// 最大公約数GCD,最小公倍数LCM
// LCMを使うときはGCDをセットで
// 検証済み
long long GCD(long long a, long long b) {
if (a < b)
swap(a, b);
long long d = a % b;
if (d == 0) {
return b;
}
return GCD(b, d);
}
long long LCM(long long a, long long b) { return (a / GCD(a, b)) * b; }
// 素数判定
// 素数ならばtrue、素数以外の整数にはfalse
// 負数は全てfalse
// 検証済み
bool prime(long long N) {
if (N == 1) {
return false;
}
if (N < 0)
return false;
long long p = sqrt(N);
for (long long i = 2; i <= p; i++) {
if (N % i == 0) {
return false;
}
}
return true;
}
// ユークリッド距離
// 検証済み
// 位置ベクトル1,位置ベクトル2,ベクトルの次元(2または3が一般的)
double distance(vector<long long> p, vector<long long> q, long long n) {
double x = 0;
for (long long i = 0; i < n; i++) {
x += pow((p.at(i) - q.at(i)), 2);
}
return sqrt(x);
}
// 配列圧縮(検証済)
//{1,36,1,3,8,-2,-92}を
//{2, 5,2,3,4, 1, 0}にする
void press(vector<long long> &v) {
long long n = v.size();
vector<long long> w(n);
map<long long, long long> m;
for (auto &p : v) {
m[p] = 0;
}
long long i = 0;
for (auto &p : m) {
p.second = i;
i++;
}
for (long long i = 0; i < n; i++) {
w.at(i) = m[v.at(i)];
}
v = w;
return;
}
// 配列のi番目の要素がj番目に小さいとき、j番目の数がiであるベクトルを返す関数
// 配列の要素が全て異なるときにしか正常に動作しない
// 配列の要素に同じものが含まれても見かけ上動作はするが意味のない値を戻し、
// エラーも起きないので注意
// 検証済
//{2,4,1,6,0,3,8,9,5}を
//{4,2,0,5,1,8,3,6,7}にして返す
//"rank"という名前にするとSTLの関数(配列の次元を返す関数)になるので注意
void ranking(vector<long long> &v) {
long long n = v.size();
map<long long, long long> m;
long long i;
for (i = 0; i < n; i++) {
m[v.at(i)] = i;
}
vector<long long> w(n);
i = 0;
for (auto &p : m) {
v.at(i) = p.second;
i++;
}
return;
}
// 部分削除(未検証)
// ベクトルのi番目(i=0,1,2,...,n-1)の要素を削除し、
// 以降の要素を全て前に1ずらして参照返し
// ベクトル長は1小さくなって返る
// i>n-1の時は変化しない
void erase(vector<long long> &v, long long i) {
long long n = v.size();
if (i > n - 1)
return;
for (long long j = i; j < n - 1; j++) {
v.at(j) = v.at(j + 1);
}
v.pop_back();
return;
}
// 重複削除(未完成)
// 引数ベクトルに同一要素が複数あるとき、先頭を残し他は削除
// 参照返し
// ベクトル長も変化する
// O(logn)くらい
void unique(vector<long long> &v) {
long long n = v.size();
set<long long> s;
long long i = 0;
while (i < n) {
if (s.count(v.at(i))) {
erase(v, i);
n--;
} else {
s.insert(v.at(i));
i++;
}
}
return;
}
// ベクトルの出力(検証済)
// debug用にvectorの中身を出力する
void printv(vector<long long> v) {
cout << "{ ";
for (auto &p : v) {
cout << p << ",";
}
cout << "}" << endl;
}
// 10進法でn桁の整数xに対して、大きい方の位から、その位の1桁の数字を
// 収納した長さnのベクトルを返す
// 0に対しては{0}を返す
// 検証済み
vector<ll> keta(ll x) {
if (x == 0)
return {0};
ll n = log10(x) + 1; // xの桁数
vll w(n, 0);
for (ll i = 0; i < n; i++) {
ll p;
p = x % 10;
x = x / 10;
w[n - 1 - i] = p;
}
return w;
}
// 20200415
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// a^{-1} mod を計算する
// modとaが互いに素のときのみ有効(数学的に逆元が一意に定まるのがそのときのみ)
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
// 整数n個の入力を受け取ってベクトルに突っ込んで返す
// チェック済み
vector<long long> inputv(long long n) {
vector<long long> v(n);
for (long long i = 0; i < n; i++) {
cin >> v[i];
}
return v;
}
vector<long long> yakusuu(long long n) // nの約数を列挙
{
vector<long long> ret;
for (long long i = 1; i <= sqrt(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;
}
map<long long, long long> soinsuu(long long n) {
map<long long, long long> m;
long long p = sqrt(n);
while (n % 2 == 0) {
n /= 2;
if (m.count(2)) {
m[2]++;
} else {
m[2] = 1;
}
}
for (long long i = 3; i * i <= n; i += 2) {
while (n % i == 0) {
n /= i;
if (m.count(i)) {
m[i]++;
} else {
m[i] = 1;
}
}
}
if (n != 1)
m[n] = 1;
return m;
}
// スタートが(i,j)の迷路の全ての地点までの距離を幅優先探索で解く
// スタートから何マス離れているか(辿り着けない場合は-1)を入れたベクトルを返す
// 壁からスタートしても正常に動作するので注意(この関数の外で処理が必要)
// 検証済み 一応O(地図の広さ)くらい
vector<vector<long long>> maze(ll i, ll j, vector<string> &s) {
ll h = s.size();
ll w = s[0].size();
queue<vector<long long>> q;
vector<vector<long long>> dis(h, vll(w, -1));
q.push({i, j});
dis[i][j] = 0;
while (!q.empty()) {
auto v = q.front();
q.pop();
if (v[0] > 0 && s[v[0] - 1][v[1]] == '.' && dis[v[0] - 1][v[1]] == -1) {
dis[v[0] - 1][v[1]] = dis[v[0]][v[1]] + 1;
q.push({v[0] - 1, v[1]});
}
if (v[1] > 0 && s[v[0]][v[1] - 1] == '.' && dis[v[0]][v[1] - 1] == -1) {
dis[v[0]][v[1] - 1] = dis[v[0]][v[1]] + 1;
q.push({v[0], v[1] - 1});
}
if (v[0] < h - 1 && s[v[0] + 1][v[1]] == '.' && dis[v[0] + 1][v[1]] == -1) {
dis[v[0] + 1][v[1]] = dis[v[0]][v[1]] + 1;
q.push({v[0] + 1, v[1]});
}
if (v[1] < w - 1 && s[v[0]][v[1] + 1] == '.' && dis[v[0]][v[1] + 1] == -1) {
dis[v[0]][v[1] + 1] = dis[v[0]][v[1]] + 1;
q.push({v[0], v[1] + 1});
}
}
return dis; // スタートから何マス離れているか(辿り着けない場合は-1)
}
// エラトステネスのふるいによりn以下の素数を全てベクトルに入れて返す
// vector<long long> eratos(long long n){
// }
// 二項係数の剰余を求める
// 引数は剰余の形ではなくもとの数そのものである
// 未検証(検証サンプルがない)
long long modC(long long n, long long k, long long mod) {
if (n < k)
return 0;
long long p = 1, q = 1;
for (long long i = 0; i < k; i++) {
p = p * (n - i) % mod;
q = q * (i + 1) % mod;
}
return p * modinv(q, mod) % mod;
}
// 20200418
// 整数のとき限定の普通のPOW関数
// 標準機能のpow(a,n)は整数だとバグるのでこちらを使う
long long POW(long long a, long long n) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a;
a = a * a;
n >>= 1;
}
return res;
}
// 20200423
// エラトステネスのふるいによりn以下の素数を全てベクトルに入れて返す
vector<long long> eratos(long long n) {
if (n < 2)
return {};
vll v(n - 1);
rep(i, n - 1) {
v[i] = i + 2; // 2からnまで
}
ll i = 0;
while (i < n - 1) {
ll p = v[i];
for (ll j = i + 1; j < n - 1; j++) {
if (v[j] % p == 0) {
v.erase(v.begin() + j);
n--;
}
}
i++;
}
v.resize(n - 1);
return v;
}
// n以下の素数を全て詰めたset
set<long long> eraset(long long n) {
set<long long> s;
vll v = eratos(n);
for (auto &t : v) {
s.insert(t);
}
return s;
}
// 20200428
//(x1,y1),(x2,y2)を通る直線をax+by+c=0としたとき
//{a,b,c}を返す
vll line(ll x1, ll y1, ll x2, ll y2) {
vector<ll> v(3);
v[0] = y1 - y2;
v[1] = x2 - x1;
v[2] = -x1 * (y1 - y2) + y1 * (x1 - x2);
return v;
}
//(x,y)とv[0]x+v[1]y+v[2]=0との距離
double dis(vll v, ll x, ll y) {
double s = sqrt(v[0] * v[0] + v[1] * v[1]);
return (double)abs(v[0] * x + v[1] * y + v[2]) / s;
}
// 20200502
void maxin(ll &a, ll b) {
a = max(a, b);
return;
}
void minin(ll &a, ll b) {
a = min(a, b);
return;
}
// 20200506
map<long long, long long> countv(vll v) {
map<long long, long long> m;
for (auto &g : v) {
if (m.count(g))
m[g]++;
else
m[g] = 1;
}
return m;
}
// nCk modを求める
const ll MAX = 510000;
const ll MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
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;
}
}
// 二項係数計算
long long commod(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;
}
// 順列計算
long long pmod(ll n, ll k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[n - k] % MOD;
}
/* next combination */
// 次の組み合わせをbitで返す
// 全探索のloopに使える
long long next_combination(long long sub) {
long long x = sub & -sub, y = sub + x;
return (((sub & ~y) / x) >> 1) | y;
}
//////////////////////////////////////////
struct UF { // サイズが測れるUF
vector<long long> par, size; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
// sizeはiを根とする木のサイズ
UF(long long N) : par(N), size(N) { // 最初は全てが根であるとして初期化
for (long long i = 0; i < N; i++) {
par[i] = i;
size[i] = 1;
}
}
long long root(
long long x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(long long x, long long y) { // xとyの木を併合
long long rx = root(x); // xの根をrx
long long ry = root(y); // yの根をry
if (rx == ry)
return; // xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] =
ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
size[ry] += size[rx];
size[rx] = 0; // サイズの処理 根じゃなくなったらサイズは0になる
}
bool same(long long x,
long long y) { // 2つのデータx, yが属する木が同じならtrueを返す
long long rx = root(x);
long long ry = root(y);
return rx == ry;
}
};
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
// int mod=17;
// const int mod = 998244353;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
void debug(ll &a) { cout << a << endl; }
void debug(vll &a) {
cout << "debug vector" << endl;
cout << "{ ";
for (auto t : a) {
cout << t << ",";
}
cout << " }" << endl;
cout << "debug finished" << endl;
}
void debug(set<long long> &a) {
cout << "debug set" << endl;
for (auto t : a) {
cout << t << endl;
}
cout << "debug finished" << endl;
}
void debug(map<long long, long long> a) {
cout << "debug map" << endl;
for (auto t : a) {
cout << t.first << " " << t.second << endl;
}
cout << "debug finished" << endl;
}
void debug(queue<long long> a) {
cout << "debug queue" << endl;
while (!a.empty()) {
ll t = a.front();
a.pop();
cout << t << endl;
}
cout << "debug finished" << endl;
}
// 20200604
struct STmax { // 最大値を測るセグ木
ll size; // treeの葉の数=m*2-1
ll m; // tree最下段の数
vector<long long> seg;
STmax(long long n) : size(n), m(n), seg(0) {
m = 1;
while (m < n) {
m *= 2;
}
size = m * 2 - 1;
rep(i, size) { seg.push_back(-99999999977); }
}
// ここまで共通
// minの場合はpush_backの値をdekaiにする?
void update(ll i, ll k) { // i番目をkに更新
ll v = i + m - 1;
seg[v] = k;
while (v > 0) {
v = (v - 1) / 2;
seg[v] = max(seg[v * 2 + 1], seg[v * 2 + 2]);
}
}
ll query(ll a, ll b, ll k, ll l, ll r) { // 区間[a,b)での最大値を求める
if (r <= a || b <= l)
return -99999999977;
if (a <= l && r <= b)
return seg[k];
// cout << "#" << a << " " << b << " " << k << " " << l << " " << r << endl;
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return max(vl, vr);
}
ll largest(ll a, ll b) {
if (a >= b)
return -99999999977;
return query(a, b, 0, 0, m);
}
};
struct STmin { // 最小値を測るセグ木
ll size; // treeの葉の数=m*2-1
ll m; // tree最下段の数
vector<long long> seg;
STmin(long long n) : size(n), m(n), seg(0) {
m = 1;
while (m < n) {
m *= 2;
}
size = m * 2 - 1;
rep(i, size) { seg.push_back(99999999977); }
}
// ここまで共通
// minの場合はpush_backの値をdekaiにする?
void update(ll i, ll k) { // i番目をkに更新
ll v = i + m - 1;
seg[v] = k;
while (v > 0) {
v = (v - 1) / 2;
seg[v] = min(seg[v * 2 + 1], seg[v * 2 + 2]);
}
}
ll query(ll a, ll b, ll k, ll l, ll r) { // 区間[a,b)での最大値を求める
if (r <= a || b <= l)
return 99999999977;
if (a <= l && r <= b)
return seg[k];
// cout << "#" << a << " " << b << " " << k << " " << l << " " << r << endl;
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
ll smallest(ll a, ll b) {
if (a >= b)
return 99999999977;
return query(a, b, 0, 0, m);
}
};
struct STsum { // 区間の合計値を測るセグ木
ll size; // treeの葉の数=m*2-1
ll m; // tree最下段の数
vector<long long> seg;
STsum(long long n) : size(n), m(n), seg(0) {
m = 1;
while (m < n) {
m *= 2;
}
size = m * 2 - 1;
rep(i, size) { seg.push_back(0); }
// 改造時はここをまず変える
}
// ここまで共通
// minの場合はpush_backの値をdekaiにする
void update(ll i, ll k) { // i番目をkに更新
ll v = i + m - 1;
seg[v] = k;
while (v > 0) {
v = (v - 1) / 2;
seg[v] = seg[v * 2 + 1] + seg[v * 2 + 2];
// 改造時はここを変える
}
}
ll query(ll a, ll b, ll k, ll l, ll r) { // 区間[a,b)での最大値を求める
if (r <= a || b <= l)
return 0;
if (a <= l && r <= b)
return seg[k];
// cout << "#" << a << " " << b << " " << k << " " << l << " " << r << endl;
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return vl + vr; // 改造時はここを変える
}
ll sum(ll a, ll b) {
if (a >= b)
return 0;
return query(a, b, 0, 0, m);
}
};
//////////////////////////////////////////////
// ll const mod=1e9+7;
ll const dekai = 9223372036854775807; // POW(2,63)-1.素数.
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, -1, 0, 1};
ll ddx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
ll ddy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// cout<<fixed<<setprecision(10);
#define ednl endl
#define endk endl
//////////////////////////////////////////////////
int main() {
ll n;
cin >> n;
auto a = inputv(n);
sort(all(a));
sll s;
mll m = countv(a);
ll ans = 0;
rep(i, n) {
if (m[a[i]] == 1) {
vll y = yakusuu(a[i]);
ll f = 0;
for (ll t : y) {
if (s.count(t))
f = 1;
}
if (!f)
ans++;
}
s.insert(a[i]);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < n; i++)
#define Rep(i, m, n) for (long long i = m; i < n; i++)
#define REP(i, m, n, p) for (long long i = m; i < n; i += p)
#define all(v) v.begin(), v.end()
#define pq priority_queue
#define bcnt(n) __builtin_popcountll(n)
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using ll = long long; // long longをllだけにした
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using mii = map<int, int>;
using pqll = priority_queue<long long>;
using pqllg = priority_queue<long long, vector<long long>, greater<long long>>;
using mll = map<long long, long long>;
using pll = pair<long long, long long>;
using sll = set<long long>;
using vpll = vector<pair<long long, long long>>;
using mlv = map<long long, vector<long long>>;
long long divup(long long a, long long b);
long long kaijou(long long i);
long long P(long long n, long long k);
long long C(long long n, long long k);
long long GCD(long long a, long long b);
long long LCM(long long a, long long b);
bool prime(long long N);
double distance(vector<long long> p, vector<long long> q, long long n);
void press(vector<long long> &v);
void ranking(vector<long long> &v);
void erase(vector<long long> &v, long long i);
void unique(vector<long long> &v);
void printv(vector<long long> v);
vector<long long> keta(ll x);
long long modpow(long long a, long long n, long long mod);
long long modinv(long long a, long long mod);
// 20200416
vector<long long> inputv(long long n);
// 20200417
vector<long long> yakusuu(int n);
map<long long, long long> soinsuu(long long n);
vector<vector<long long>> maze(long long i, long long j, vector<string> &s);
// 20200423
vector<long long> eratos(long long n);
set<long long> eraset(long long n);
//////////////////////////////////////////////////////
// 端数繰りあがり割り算(検証済)
// a÷bの端数繰り上げ
// b!=0のデバグはしてないので分母に0を入れないように
// 負数対応
long long divup(long long a, long long b) {
long long x = abs(a);
long long y = abs(b);
long long z = (x + y - 1) / y;
if ((a < 0 && b > 0) || (a > 0 && b < 0))
return -z;
else if (a == 0)
return 0;
else
return z;
}
// 階乗
// 検証済み
long long kaijou(long long i) {
if (i == 0)
return 1;
long long j = 1;
for (long long k = 1; k <= i; k++) {
j *= k;
}
return j;
}
// 順列nPk(完成)
// n個の異なる要素から、取り出す順序を区別してk個取り出す場合の数
// n<kなら0を返す
// 敢えて負数時のデバグはしてない
long long P(long long n, long long k) {
if (n < k)
return 0;
long long y = 1;
for (long long i = 0; i < k; i++) {
y *= (n - i);
}
return y;
}
// 組み合わせnCk(検証済み)
// P,kaijouと併用
long long C(long long n, long long k) {
if (n < k)
return 0;
return P(n, k) / kaijou(k);
}
// nHk
// 区別しないn個の要素を、区別するk個のグループに分ける
// 0個のグループがあっ
// て良い
// C必須
// 最大公約数GCD,最小公倍数LCM
// LCMを使うときはGCDをセットで
// 検証済み
long long GCD(long long a, long long b) {
if (a < b)
swap(a, b);
long long d = a % b;
if (d == 0) {
return b;
}
return GCD(b, d);
}
long long LCM(long long a, long long b) { return (a / GCD(a, b)) * b; }
// 素数判定
// 素数ならばtrue、素数以外の整数にはfalse
// 負数は全てfalse
// 検証済み
bool prime(long long N) {
if (N == 1) {
return false;
}
if (N < 0)
return false;
long long p = sqrt(N);
for (long long i = 2; i <= p; i++) {
if (N % i == 0) {
return false;
}
}
return true;
}
// ユークリッド距離
// 検証済み
// 位置ベクトル1,位置ベクトル2,ベクトルの次元(2または3が一般的)
double distance(vector<long long> p, vector<long long> q, long long n) {
double x = 0;
for (long long i = 0; i < n; i++) {
x += pow((p.at(i) - q.at(i)), 2);
}
return sqrt(x);
}
// 配列圧縮(検証済)
//{1,36,1,3,8,-2,-92}を
//{2, 5,2,3,4, 1, 0}にする
void press(vector<long long> &v) {
long long n = v.size();
vector<long long> w(n);
map<long long, long long> m;
for (auto &p : v) {
m[p] = 0;
}
long long i = 0;
for (auto &p : m) {
p.second = i;
i++;
}
for (long long i = 0; i < n; i++) {
w.at(i) = m[v.at(i)];
}
v = w;
return;
}
// 配列のi番目の要素がj番目に小さいとき、j番目の数がiであるベクトルを返す関数
// 配列の要素が全て異なるときにしか正常に動作しない
// 配列の要素に同じものが含まれても見かけ上動作はするが意味のない値を戻し、
// エラーも起きないので注意
// 検証済
//{2,4,1,6,0,3,8,9,5}を
//{4,2,0,5,1,8,3,6,7}にして返す
//"rank"という名前にするとSTLの関数(配列の次元を返す関数)になるので注意
void ranking(vector<long long> &v) {
long long n = v.size();
map<long long, long long> m;
long long i;
for (i = 0; i < n; i++) {
m[v.at(i)] = i;
}
vector<long long> w(n);
i = 0;
for (auto &p : m) {
v.at(i) = p.second;
i++;
}
return;
}
// 部分削除(未検証)
// ベクトルのi番目(i=0,1,2,...,n-1)の要素を削除し、
// 以降の要素を全て前に1ずらして参照返し
// ベクトル長は1小さくなって返る
// i>n-1の時は変化しない
void erase(vector<long long> &v, long long i) {
long long n = v.size();
if (i > n - 1)
return;
for (long long j = i; j < n - 1; j++) {
v.at(j) = v.at(j + 1);
}
v.pop_back();
return;
}
// 重複削除(未完成)
// 引数ベクトルに同一要素が複数あるとき、先頭を残し他は削除
// 参照返し
// ベクトル長も変化する
// O(logn)くらい
void unique(vector<long long> &v) {
long long n = v.size();
set<long long> s;
long long i = 0;
while (i < n) {
if (s.count(v.at(i))) {
erase(v, i);
n--;
} else {
s.insert(v.at(i));
i++;
}
}
return;
}
// ベクトルの出力(検証済)
// debug用にvectorの中身を出力する
void printv(vector<long long> v) {
cout << "{ ";
for (auto &p : v) {
cout << p << ",";
}
cout << "}" << endl;
}
// 10進法でn桁の整数xに対して、大きい方の位から、その位の1桁の数字を
// 収納した長さnのベクトルを返す
// 0に対しては{0}を返す
// 検証済み
vector<ll> keta(ll x) {
if (x == 0)
return {0};
ll n = log10(x) + 1; // xの桁数
vll w(n, 0);
for (ll i = 0; i < n; i++) {
ll p;
p = x % 10;
x = x / 10;
w[n - 1 - i] = p;
}
return w;
}
// 20200415
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// a^{-1} mod を計算する
// modとaが互いに素のときのみ有効(数学的に逆元が一意に定まるのがそのときのみ)
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
// 整数n個の入力を受け取ってベクトルに突っ込んで返す
// チェック済み
vector<long long> inputv(long long n) {
vector<long long> v(n);
for (long long i = 0; i < n; i++) {
cin >> v[i];
}
return v;
}
vector<long long> yakusuu(long long n) // nの約数を列挙
{
vector<long long> ret;
for (long long i = 1; i <= sqrt(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;
}
map<long long, long long> soinsuu(long long n) {
map<long long, long long> m;
long long p = sqrt(n);
while (n % 2 == 0) {
n /= 2;
if (m.count(2)) {
m[2]++;
} else {
m[2] = 1;
}
}
for (long long i = 3; i * i <= n; i += 2) {
while (n % i == 0) {
n /= i;
if (m.count(i)) {
m[i]++;
} else {
m[i] = 1;
}
}
}
if (n != 1)
m[n] = 1;
return m;
}
// スタートが(i,j)の迷路の全ての地点までの距離を幅優先探索で解く
// スタートから何マス離れているか(辿り着けない場合は-1)を入れたベクトルを返す
// 壁からスタートしても正常に動作するので注意(この関数の外で処理が必要)
// 検証済み 一応O(地図の広さ)くらい
vector<vector<long long>> maze(ll i, ll j, vector<string> &s) {
ll h = s.size();
ll w = s[0].size();
queue<vector<long long>> q;
vector<vector<long long>> dis(h, vll(w, -1));
q.push({i, j});
dis[i][j] = 0;
while (!q.empty()) {
auto v = q.front();
q.pop();
if (v[0] > 0 && s[v[0] - 1][v[1]] == '.' && dis[v[0] - 1][v[1]] == -1) {
dis[v[0] - 1][v[1]] = dis[v[0]][v[1]] + 1;
q.push({v[0] - 1, v[1]});
}
if (v[1] > 0 && s[v[0]][v[1] - 1] == '.' && dis[v[0]][v[1] - 1] == -1) {
dis[v[0]][v[1] - 1] = dis[v[0]][v[1]] + 1;
q.push({v[0], v[1] - 1});
}
if (v[0] < h - 1 && s[v[0] + 1][v[1]] == '.' && dis[v[0] + 1][v[1]] == -1) {
dis[v[0] + 1][v[1]] = dis[v[0]][v[1]] + 1;
q.push({v[0] + 1, v[1]});
}
if (v[1] < w - 1 && s[v[0]][v[1] + 1] == '.' && dis[v[0]][v[1] + 1] == -1) {
dis[v[0]][v[1] + 1] = dis[v[0]][v[1]] + 1;
q.push({v[0], v[1] + 1});
}
}
return dis; // スタートから何マス離れているか(辿り着けない場合は-1)
}
// エラトステネスのふるいによりn以下の素数を全てベクトルに入れて返す
// vector<long long> eratos(long long n){
// }
// 二項係数の剰余を求める
// 引数は剰余の形ではなくもとの数そのものである
// 未検証(検証サンプルがない)
long long modC(long long n, long long k, long long mod) {
if (n < k)
return 0;
long long p = 1, q = 1;
for (long long i = 0; i < k; i++) {
p = p * (n - i) % mod;
q = q * (i + 1) % mod;
}
return p * modinv(q, mod) % mod;
}
// 20200418
// 整数のとき限定の普通のPOW関数
// 標準機能のpow(a,n)は整数だとバグるのでこちらを使う
long long POW(long long a, long long n) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a;
a = a * a;
n >>= 1;
}
return res;
}
// 20200423
// エラトステネスのふるいによりn以下の素数を全てベクトルに入れて返す
vector<long long> eratos(long long n) {
if (n < 2)
return {};
vll v(n - 1);
rep(i, n - 1) {
v[i] = i + 2; // 2からnまで
}
ll i = 0;
while (i < n - 1) {
ll p = v[i];
for (ll j = i + 1; j < n - 1; j++) {
if (v[j] % p == 0) {
v.erase(v.begin() + j);
n--;
}
}
i++;
}
v.resize(n - 1);
return v;
}
// n以下の素数を全て詰めたset
set<long long> eraset(long long n) {
set<long long> s;
vll v = eratos(n);
for (auto &t : v) {
s.insert(t);
}
return s;
}
// 20200428
//(x1,y1),(x2,y2)を通る直線をax+by+c=0としたとき
//{a,b,c}を返す
vll line(ll x1, ll y1, ll x2, ll y2) {
vector<ll> v(3);
v[0] = y1 - y2;
v[1] = x2 - x1;
v[2] = -x1 * (y1 - y2) + y1 * (x1 - x2);
return v;
}
//(x,y)とv[0]x+v[1]y+v[2]=0との距離
double dis(vll v, ll x, ll y) {
double s = sqrt(v[0] * v[0] + v[1] * v[1]);
return (double)abs(v[0] * x + v[1] * y + v[2]) / s;
}
// 20200502
void maxin(ll &a, ll b) {
a = max(a, b);
return;
}
void minin(ll &a, ll b) {
a = min(a, b);
return;
}
// 20200506
map<long long, long long> countv(vll v) {
map<long long, long long> m;
for (auto &g : v) {
if (m.count(g))
m[g]++;
else
m[g] = 1;
}
return m;
}
// nCk modを求める
const ll MAX = 510000;
const ll MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
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;
}
}
// 二項係数計算
long long commod(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;
}
// 順列計算
long long pmod(ll n, ll k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[n - k] % MOD;
}
/* next combination */
// 次の組み合わせをbitで返す
// 全探索のloopに使える
long long next_combination(long long sub) {
long long x = sub & -sub, y = sub + x;
return (((sub & ~y) / x) >> 1) | y;
}
//////////////////////////////////////////
struct UF { // サイズが測れるUF
vector<long long> par, size; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
// sizeはiを根とする木のサイズ
UF(long long N) : par(N), size(N) { // 最初は全てが根であるとして初期化
for (long long i = 0; i < N; i++) {
par[i] = i;
size[i] = 1;
}
}
long long root(
long long x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(long long x, long long y) { // xとyの木を併合
long long rx = root(x); // xの根をrx
long long ry = root(y); // yの根をry
if (rx == ry)
return; // xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] =
ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
size[ry] += size[rx];
size[rx] = 0; // サイズの処理 根じゃなくなったらサイズは0になる
}
bool same(long long x,
long long y) { // 2つのデータx, yが属する木が同じならtrueを返す
long long rx = root(x);
long long ry = root(y);
return rx == ry;
}
};
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
// int mod=17;
// const int mod = 998244353;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
void debug(ll &a) { cout << a << endl; }
void debug(vll &a) {
cout << "debug vector" << endl;
cout << "{ ";
for (auto t : a) {
cout << t << ",";
}
cout << " }" << endl;
cout << "debug finished" << endl;
}
void debug(set<long long> &a) {
cout << "debug set" << endl;
for (auto t : a) {
cout << t << endl;
}
cout << "debug finished" << endl;
}
void debug(map<long long, long long> a) {
cout << "debug map" << endl;
for (auto t : a) {
cout << t.first << " " << t.second << endl;
}
cout << "debug finished" << endl;
}
void debug(queue<long long> a) {
cout << "debug queue" << endl;
while (!a.empty()) {
ll t = a.front();
a.pop();
cout << t << endl;
}
cout << "debug finished" << endl;
}
// 20200604
struct STmax { // 最大値を測るセグ木
ll size; // treeの葉の数=m*2-1
ll m; // tree最下段の数
vector<long long> seg;
STmax(long long n) : size(n), m(n), seg(0) {
m = 1;
while (m < n) {
m *= 2;
}
size = m * 2 - 1;
rep(i, size) { seg.push_back(-99999999977); }
}
// ここまで共通
// minの場合はpush_backの値をdekaiにする?
void update(ll i, ll k) { // i番目をkに更新
ll v = i + m - 1;
seg[v] = k;
while (v > 0) {
v = (v - 1) / 2;
seg[v] = max(seg[v * 2 + 1], seg[v * 2 + 2]);
}
}
ll query(ll a, ll b, ll k, ll l, ll r) { // 区間[a,b)での最大値を求める
if (r <= a || b <= l)
return -99999999977;
if (a <= l && r <= b)
return seg[k];
// cout << "#" << a << " " << b << " " << k << " " << l << " " << r << endl;
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return max(vl, vr);
}
ll largest(ll a, ll b) {
if (a >= b)
return -99999999977;
return query(a, b, 0, 0, m);
}
};
struct STmin { // 最小値を測るセグ木
ll size; // treeの葉の数=m*2-1
ll m; // tree最下段の数
vector<long long> seg;
STmin(long long n) : size(n), m(n), seg(0) {
m = 1;
while (m < n) {
m *= 2;
}
size = m * 2 - 1;
rep(i, size) { seg.push_back(99999999977); }
}
// ここまで共通
// minの場合はpush_backの値をdekaiにする?
void update(ll i, ll k) { // i番目をkに更新
ll v = i + m - 1;
seg[v] = k;
while (v > 0) {
v = (v - 1) / 2;
seg[v] = min(seg[v * 2 + 1], seg[v * 2 + 2]);
}
}
ll query(ll a, ll b, ll k, ll l, ll r) { // 区間[a,b)での最大値を求める
if (r <= a || b <= l)
return 99999999977;
if (a <= l && r <= b)
return seg[k];
// cout << "#" << a << " " << b << " " << k << " " << l << " " << r << endl;
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
ll smallest(ll a, ll b) {
if (a >= b)
return 99999999977;
return query(a, b, 0, 0, m);
}
};
struct STsum { // 区間の合計値を測るセグ木
ll size; // treeの葉の数=m*2-1
ll m; // tree最下段の数
vector<long long> seg;
STsum(long long n) : size(n), m(n), seg(0) {
m = 1;
while (m < n) {
m *= 2;
}
size = m * 2 - 1;
rep(i, size) { seg.push_back(0); }
// 改造時はここをまず変える
}
// ここまで共通
// minの場合はpush_backの値をdekaiにする
void update(ll i, ll k) { // i番目をkに更新
ll v = i + m - 1;
seg[v] = k;
while (v > 0) {
v = (v - 1) / 2;
seg[v] = seg[v * 2 + 1] + seg[v * 2 + 2];
// 改造時はここを変える
}
}
ll query(ll a, ll b, ll k, ll l, ll r) { // 区間[a,b)での最大値を求める
if (r <= a || b <= l)
return 0;
if (a <= l && r <= b)
return seg[k];
// cout << "#" << a << " " << b << " " << k << " " << l << " " << r << endl;
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return vl + vr; // 改造時はここを変える
}
ll sum(ll a, ll b) {
if (a >= b)
return 0;
return query(a, b, 0, 0, m);
}
};
//////////////////////////////////////////////
// ll const mod=1e9+7;
ll const dekai = 9223372036854775807; // POW(2,63)-1.素数.
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, -1, 0, 1};
ll ddx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
ll ddy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// cout<<fixed<<setprecision(10);
#define ednl endl
#define endk endl
//////////////////////////////////////////////////
int main() {
ll n;
cin >> n;
auto a = inputv(n);
sort(all(a));
sll s;
mll m = countv(a);
ll ans = 0;
rep(i, n) {
if (m[a[i]] == 1) {
vll y = yakusuu(a[i]);
ll f = 0;
for (ll t : y) {
if (s.count(t))
f = 1;
}
if (!f)
ans++;
}
s.insert(a[i]);
}
cout << ans;
} | replace | 791 | 793 | 791 | 793 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
// using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i, j, n) for (ll i = (ll)(j); i < (ll)(n); i++)
#define REP(i, j, n) for (ll i = (ll)(j); i <= (ll)(n); i++)
#define per(i, j, n) for (ll i = (ll)(j); (ll)(n) <= i; i--)
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (ll)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (ll)(key)))
#define pb emplace_back
#define mp std::make_pair
// #define endl "\n"
//
using std::cin;
using std::cout;
using std::endl;
using std::lower_bound;
using std::string;
using std::upper_bound;
using std::vector;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll, ll>;
// constexpr
ll MOD = 1e9 + 7;
// constexpr ll MOD=998244353;
// constexpr ll MOD=10000000;
constexpr ll MAX = 1e6;
constexpr ll INF = (1ll << 62);
template <class T>
class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> {
};
struct Segment_tree {
ll N;
vector<pii> node;
Segment_tree(ll sz) {
N = 1;
while (N < sz)
N *= 2;
node.resize(2 * N - 1, mp(INF, INF));
per(i, N - 2, 0) { node[i] = std::min(node[i * 2 + 1], node[i * 2 + 1]); }
}
void update(ll X, pii val) {
X += N - 1;
node[X] = val;
while (X > 0) {
X = (X - 1) / 2;
node[X] = std::min(node[X * 2 + 1], node[X * 2 + 2]);
}
}
pii RMQ(ll a, ll b, ll now, ll l, ll r) { //[a,b),[l,r)
if (r < 0)
r = N;
if (r <= a || b <= l)
return mp(INF, INF);
if (a <= l && r <= b)
return node[now];
auto vl = RMQ(a, b, now * 2 + 1, l, (l + r) / 2),
vr = RMQ(a, b, now * 2 + 2, (l + r) / 2, r);
return std::min(vl, vr);
}
};
struct Binary_indexed_tree {
int N;
vi bit;
Binary_indexed_tree(int n) : N(n) { bit.resize(N + 1, 0); }
void add(int x, int a) {
for (x; x <= N; x += (x & -x))
bit[x] += a;
}
ll sum(int x) {
ll ret = 0;
for (x; x > 0; x -= (x & -x))
ret += bit[x];
return ret;
}
ll lower_bound(ll X) {
if (sum(N) < X)
return -1;
ll ret = 0, memo = 1, sum = 0;
while (memo * 2 <= N)
memo *= 2;
while (memo > 0) {
if (memo + ret <= N && sum + bit[memo + ret] < X) {
sum += bit[memo + ret];
ret += memo;
}
memo /= 2;
}
return ret + 1;
}
};
struct Union_Find {
ll N;
vi par;
vi siz;
Union_Find(int n) : N(n) {
par.resize(N);
siz.resize(N, 1);
rep(i, 0, N) par[i] = i;
}
ll root(ll X) {
if (par[X] == X)
return X;
return par[X] = root(par[X]);
}
bool same(ll X, ll Y) { return root(X) == root(Y); }
void unite(ll X, ll Y) {
X = root(X);
Y = root(Y);
if (X == Y)
return;
par[X] = Y;
siz[Y] += siz[X];
siz[X] = 0;
}
ll size(ll X) { return siz[root(X)]; }
};
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
vi fac, finv, inv;
void COMinit() {
fac.resize(MAX);
finv.resize(MAX);
inv.resize(MAX);
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int 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 COM(ll n, ll r) {
if (n < r || n < 0 || r < 0)
return 0;
return fac[n] * finv[r] % MOD * finv[n - r] % MOD;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll N;
cin >> N;
vi A(N);
rep(i, 0, N) cin >> A[i];
std::map<ll, ll> cnt;
rep(i, 0, N) { cnt[A[i]]++; }
ll ans = 0;
rep(i, 0, N) {
cnt[A[i]]--;
bool flag = 1;
REP(j, 1, sqrt(A[i])) {
if (A[i] % j == 0) {
if (cnt[j] > 0 || cnt[A[i] / j] > 0) {
flag = 0;
break;
}
}
}
if (flag)
ans++;
cnt[A[i]]++;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
// using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i, j, n) for (ll i = (ll)(j); i < (ll)(n); i++)
#define REP(i, j, n) for (ll i = (ll)(j); i <= (ll)(n); i++)
#define per(i, j, n) for (ll i = (ll)(j); (ll)(n) <= i; i--)
#define ll int
#define ALL(a) (a).begin(), (a).end()
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (ll)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (ll)(key)))
#define pb emplace_back
#define mp std::make_pair
// #define endl "\n"
//
using std::cin;
using std::cout;
using std::endl;
using std::lower_bound;
using std::string;
using std::upper_bound;
using std::vector;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll, ll>;
// constexpr
ll MOD = 1e9 + 7;
// constexpr ll MOD=998244353;
// constexpr ll MOD=10000000;
constexpr ll MAX = 1e6;
constexpr ll INF = (1ll << 62);
template <class T>
class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> {
};
struct Segment_tree {
ll N;
vector<pii> node;
Segment_tree(ll sz) {
N = 1;
while (N < sz)
N *= 2;
node.resize(2 * N - 1, mp(INF, INF));
per(i, N - 2, 0) { node[i] = std::min(node[i * 2 + 1], node[i * 2 + 1]); }
}
void update(ll X, pii val) {
X += N - 1;
node[X] = val;
while (X > 0) {
X = (X - 1) / 2;
node[X] = std::min(node[X * 2 + 1], node[X * 2 + 2]);
}
}
pii RMQ(ll a, ll b, ll now, ll l, ll r) { //[a,b),[l,r)
if (r < 0)
r = N;
if (r <= a || b <= l)
return mp(INF, INF);
if (a <= l && r <= b)
return node[now];
auto vl = RMQ(a, b, now * 2 + 1, l, (l + r) / 2),
vr = RMQ(a, b, now * 2 + 2, (l + r) / 2, r);
return std::min(vl, vr);
}
};
struct Binary_indexed_tree {
int N;
vi bit;
Binary_indexed_tree(int n) : N(n) { bit.resize(N + 1, 0); }
void add(int x, int a) {
for (x; x <= N; x += (x & -x))
bit[x] += a;
}
ll sum(int x) {
ll ret = 0;
for (x; x > 0; x -= (x & -x))
ret += bit[x];
return ret;
}
ll lower_bound(ll X) {
if (sum(N) < X)
return -1;
ll ret = 0, memo = 1, sum = 0;
while (memo * 2 <= N)
memo *= 2;
while (memo > 0) {
if (memo + ret <= N && sum + bit[memo + ret] < X) {
sum += bit[memo + ret];
ret += memo;
}
memo /= 2;
}
return ret + 1;
}
};
struct Union_Find {
ll N;
vi par;
vi siz;
Union_Find(int n) : N(n) {
par.resize(N);
siz.resize(N, 1);
rep(i, 0, N) par[i] = i;
}
ll root(ll X) {
if (par[X] == X)
return X;
return par[X] = root(par[X]);
}
bool same(ll X, ll Y) { return root(X) == root(Y); }
void unite(ll X, ll Y) {
X = root(X);
Y = root(Y);
if (X == Y)
return;
par[X] = Y;
siz[Y] += siz[X];
siz[X] = 0;
}
ll size(ll X) { return siz[root(X)]; }
};
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
vi fac, finv, inv;
void COMinit() {
fac.resize(MAX);
finv.resize(MAX);
inv.resize(MAX);
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int 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 COM(ll n, ll r) {
if (n < r || n < 0 || r < 0)
return 0;
return fac[n] * finv[r] % MOD * finv[n - r] % MOD;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll N;
cin >> N;
vi A(N);
rep(i, 0, N) cin >> A[i];
std::map<ll, ll> cnt;
rep(i, 0, N) { cnt[A[i]]++; }
ll ans = 0;
rep(i, 0, N) {
cnt[A[i]]--;
bool flag = 1;
REP(j, 1, sqrt(A[i])) {
if (A[i] % j == 0) {
if (cnt[j] > 0 || cnt[A[i] / j] > 0) {
flag = 0;
break;
}
}
}
if (flag)
ans++;
cnt[A[i]]++;
}
cout << ans << endl;
}
| replace | 9 | 10 | 9 | 10 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <iostream>
#include <map>
#include <vector>
typedef long long ll;
int N;
ll A[200005], mark[200005];
std::map<ll, std::vector<int>> occ;
int main() {
std::cin >> N;
ll mA = 0;
for (int i = 0; i < N; ++i) {
std::cin >> A[i];
mA = std::max(mA, A[i]);
mark[i] = 1;
occ[A[i]].push_back(i);
}
int ans = N;
for (int i = 0; i < N; ++i) {
for (ll x = A[i]; x <= mA; x += A[i]) {
if (occ.find(x) == occ.end())
continue;
for (int j : occ[x]) {
if (i == j)
continue;
if (mark[j])
ans--;
mark[j] = 0;
}
}
}
std::cout << ans << "\n";
return 0;
}
| #include <iostream>
#include <map>
#include <vector>
typedef long long ll;
int N;
ll A[200005], mark[200005];
std::map<ll, std::vector<int>> occ;
int main() {
std::cin >> N;
ll mA = 0;
for (int i = 0; i < N; ++i) {
std::cin >> A[i];
mA = std::max(mA, A[i]);
mark[i] = 1;
occ[A[i]].push_back(i);
}
int ans = N;
for (int i = 0; i < N; ++i) {
if (mark[i] == 0)
continue;
if (occ[A[i]].size() > 1) {
mark[i] = 0;
ans--;
}
for (ll x = A[i]; x <= mA; x += A[i]) {
if (occ.find(x) == occ.end())
continue;
for (int j : occ[x]) {
if (i == j)
continue;
if (mark[j])
ans--;
mark[j] = 0;
}
}
}
std::cout << ans << "\n";
return 0;
}
| insert | 22 | 22 | 22 | 28 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MAX int(2 * 10e5)
#define ll long long int
using namespace std;
int main() {
vector<ll> sieve(MAX + 1, true);
int n;
cin >> n;
vector<ll> arr(n + 1, 0);
vector<ll> freq(MAX + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> arr[i];
freq[arr[i]] += 1;
}
sort(arr.begin(), arr.end());
ll end = arr[n - 1];
for (int i = 1; i <= n; i++) {
int curr = arr[i];
if (sieve[curr] == false) {
freq[curr] = 0;
continue;
}
for (ll j = 2; j * i <= end; j++) {
sieve[curr * j] = false;
}
if (freq[curr] > 1)
sieve[curr] = false;
freq[curr] = 0;
}
ll count = 0;
for (int i = 1; i <= n; i++) {
if (sieve[arr[i]] == true)
count++;
}
cout << count << endl;
}
| #include <bits/stdc++.h>
#define MAX int(2 * 10e5)
#define ll long long int
using namespace std;
int main() {
vector<ll> sieve(MAX + 1, true);
int n;
cin >> n;
vector<ll> arr(n + 1, 0);
vector<ll> freq(MAX + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> arr[i];
freq[arr[i]] += 1;
}
sort(arr.begin(), arr.end());
ll end = arr[n - 1];
for (int i = 1; i <= n; i++) {
int curr = arr[i];
if (sieve[curr] == false) {
freq[curr] = 0;
continue;
}
for (ll j = 2; j * curr <= MAX; j++) {
sieve[curr * j] = false;
}
if (freq[curr] > 1)
sieve[curr] = false;
freq[curr] = 0;
}
ll count = 0;
for (int i = 1; i <= n; i++) {
if (sieve[arr[i]] == true)
count++;
}
cout << count << endl;
}
| replace | 25 | 26 | 25 | 26 | 0 | |
p02642 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <unordered_map>
#include <vector>
using namespace std;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template <class T> void printvec(const vector<T> &v) {
for (auto x : v) {
cout << x << " ";
}
cout << endl;
}
template <class T> void printtree(const vector<vector<T>> &tree) {
for (long long i = 0; i < tree.size(); ++i) {
cout << i + 1 << ": ";
printvec(tree[i]);
}
}
template <class T, class U> void printmap(const map<T, U> &mp) {
for (auto x : mp) {
cout << x.first << "=>" << x.second << endl;
}
}
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;
}
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll INF = 1e9;
const ll MOD = 1000000007; // 1e9 + 7
int main(int argc, char **argv) {
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(false);
// cout << setprecision(10) << fixed;
ll n;
cin >> n;
vector<ll> a(n);
rep(i, n) { cin >> a[i]; }
vector<ll> cnts;
rep(i, n) { ++cnts[a[i]]; }
auto check = [&](ll v) {
if (cnts[v] > 0) { // found
return true;
}
return false;
};
ll ans = 0;
rep(i, n) {
--cnts[a[i]];
bool found = false;
for (ll j = 1; j * j <= a[i]; ++j) {
if (a[i] % j == 0) {
if (check(j)) {
found = true;
break;
}
if (check(a[i] / j)) {
found = true;
break;
}
}
}
if (!found) {
++ans;
}
++cnts[a[i]];
}
cout << ans << endl;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <unordered_map>
#include <vector>
using namespace std;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template <class T> void printvec(const vector<T> &v) {
for (auto x : v) {
cout << x << " ";
}
cout << endl;
}
template <class T> void printtree(const vector<vector<T>> &tree) {
for (long long i = 0; i < tree.size(); ++i) {
cout << i + 1 << ": ";
printvec(tree[i]);
}
}
template <class T, class U> void printmap(const map<T, U> &mp) {
for (auto x : mp) {
cout << x.first << "=>" << x.second << endl;
}
}
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;
}
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll INF = 1e9;
const ll MOD = 1000000007; // 1e9 + 7
int main(int argc, char **argv) {
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(false);
// cout << setprecision(10) << fixed;
ll n;
cin >> n;
vector<ll> a(n);
rep(i, n) { cin >> a[i]; }
vector<ll> cnts(1e6 + 5);
rep(i, n) { ++cnts[a[i]]; }
auto check = [&](ll v) {
if (cnts[v] > 0) { // found
return true;
}
return false;
};
ll ans = 0;
rep(i, n) {
--cnts[a[i]];
bool found = false;
for (ll j = 1; j * j <= a[i]; ++j) {
if (a[i] % j == 0) {
if (check(j)) {
found = true;
break;
}
if (check(a[i] / j)) {
found = true;
break;
}
}
}
if (!found) {
++ans;
}
++cnts[a[i]];
}
cout << ans << endl;
}
| replace | 84 | 85 | 84 | 85 | -11 | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;
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;
vector<int> vec(n);
rep(i, n) cin >> vec[i];
map<int, int> mp;
sort(all(vec));
int cnt = 0;
set<int> same;
vector<int> ignore(100001, 0);
rep(i, n) { ignore[vec[i]]++; }
rep(i, n) {
if (ignore[vec[i]] > 1) {
mp[vec[i]]++;
}
}
rep(i, n) {
if (ignore[vec[i]] > 1)
continue;
vector<int> divs = divisor(vec[i]);
bool found = false;
rep(j, divs.size()) {
if (mp[divs[j]] != 0) {
found = true;
break;
}
}
if (!found)
cnt++;
mp[vec[i]]++;
}
cout << cnt << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;
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;
vector<int> vec(n);
rep(i, n) cin >> vec[i];
map<int, int> mp;
sort(all(vec));
int cnt = 0;
set<int> same;
vector<int> ignore(1000001, 0);
rep(i, n) { ignore[vec[i]]++; }
rep(i, n) {
if (ignore[vec[i]] > 1) {
mp[vec[i]]++;
}
}
rep(i, n) {
if (ignore[vec[i]] > 1)
continue;
vector<int> divs = divisor(vec[i]);
bool found = false;
rep(j, divs.size()) {
if (mp[divs[j]] != 0) {
found = true;
break;
}
}
if (!found)
cnt++;
mp[vec[i]]++;
}
cout << cnt << endl;
return 0;
} | replace | 29 | 30 | 29 | 30 | 0 | |
p02642 | C++ | Time Limit Exceeded | /**
* author: otera
**/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf = 1e9 + 7;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
#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++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(), c.end()
#define pb push_back
#define debug(x) cerr << #x << " = " << (x) << endl;
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;
}
bool used[1001000];
void solve() {
int n;
cin >> n;
rep(i, 1001000) { used[i] = 0; }
set<int> se;
vector<int> a(n);
rep(i, n) {
cin >> a[i];
if (se.find(a[i]) != se.end()) {
used[a[i]] = 1;
int x = a[i];
for (int j = x; j < 1001000; j += x) {
used[j] = 1;
}
}
se.insert(a[i]);
}
sort(all(a));
int ans = 0;
rep(i, n) {
int x = a[i];
if (!used[x]) {
++ans;
for (int j = x; j < 1001000; j += x) {
used[j] = 1;
}
}
}
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// cout << fixed << setprecision(10);
// int t; cin >> t; rep(i, t)solve();
solve();
return 0;
} | /**
* author: otera
**/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf = 1e9 + 7;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
#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++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(), c.end()
#define pb push_back
#define debug(x) cerr << #x << " = " << (x) << endl;
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;
}
bool used[1001000];
void solve() {
int n;
cin >> n;
rep(i, 1001000) { used[i] = 0; }
set<int> se;
vector<int> a(n);
rep(i, n) {
cin >> a[i];
if (se.find(a[i]) != se.end()) {
if (used[a[i]])
continue;
used[a[i]] = 1;
int x = a[i];
for (int j = x; j < 1001000; j += x) {
used[j] = 1;
}
}
se.insert(a[i]);
}
sort(all(a));
int ans = 0;
rep(i, n) {
int x = a[i];
if (!used[x]) {
++ans;
for (int j = x; j < 1001000; j += x) {
used[j] = 1;
}
}
}
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// cout << fixed << setprecision(10);
// int t; cin >> t; rep(i, t)solve();
solve();
return 0;
} | insert | 77 | 77 | 77 | 79 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for (ll i = 0; i < t; i++)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int, int>
#define umpl unordered_map<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vvl vector<vl>
#define fill(a, p) memset(a, p, sizeof(a))
#define pb push_back
#define mod 1000000007
#define N 1000005
#define all(a) a.begin(), a.end()
#define point pair<ll, ll>
#define endl "\n"
const int inf = 1000000007;
const ll linf = 1ll * inf * inf;
const ll MAXIMUM = 2005;
inline ll mul(ll a, ll b) { return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b) {
ll c = a - b;
if (c < 0)
c += mod;
return c;
}
inline ll add(ll a, ll b) {
ll c = a + b;
if (c >= mod)
c -= mod;
return c;
}
inline ll max(ll a, ll b) { return a > b ? a : b; }
inline ll min(ll a, ll b) { return a < b ? a : b; }
inline ll ceil(ll a, ll b) {
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
inline ll mo(ll a, ll b) {
if (b < 0) {
b = abs(b) % mod;
b = a - b;
return (b < 0) ? b + mod : b;
} else {
return (a + b) % mod;
}
}
inline ll pow(ll a, ll b) {
if (b == 0) {
return 1;
} else {
if (b % 2 == 0) {
ll temp = pow(a, b / 2);
return temp * temp;
} else {
return a * pow(a, b - 1);
}
}
}
struct hash_pair {
template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const {
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};
int main() {
ll n;
cin >> n;
vl a(n);
f(n) cin >> a[i];
sort(all(a));
unordered_map<ll, ll> mp;
f(n) { mp[a[i]]++; }
if (mp[1] > 0) {
if (mp[1] == 1) {
cout << 1 << endl;
} else {
cout << 0 << endl;
}
return 0;
}
ll ans = 0;
f(n) {
bool flag = false;
if (mp[a[i]] > 1)
continue;
for (ll j = 2; j <= sqrt(a[i]); j++) {
if (a[i] % j == 0) {
if ((a[i] / j) == j) {
if (mp[j] > 0) {
flag = true;
break;
}
} else {
if (mp[j] > 0 || mp[a[i] / j] > 0) {
flag = true;
break;
}
}
}
}
if (!flag) {
ans++;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for (ll i = 0; i < t; i++)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int, int>
#define umpl unordered_map<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vvl vector<vl>
#define fill(a, p) memset(a, p, sizeof(a))
#define pb push_back
#define mod 1000000007
#define N 1000005
#define all(a) a.begin(), a.end()
#define point pair<ll, ll>
#define endl "\n"
const int inf = 1000000007;
const ll linf = 1ll * inf * inf;
const ll MAXIMUM = 2005;
inline ll mul(ll a, ll b) { return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b) {
ll c = a - b;
if (c < 0)
c += mod;
return c;
}
inline ll add(ll a, ll b) {
ll c = a + b;
if (c >= mod)
c -= mod;
return c;
}
inline ll max(ll a, ll b) { return a > b ? a : b; }
inline ll min(ll a, ll b) { return a < b ? a : b; }
inline ll ceil(ll a, ll b) {
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
inline ll mo(ll a, ll b) {
if (b < 0) {
b = abs(b) % mod;
b = a - b;
return (b < 0) ? b + mod : b;
} else {
return (a + b) % mod;
}
}
inline ll pow(ll a, ll b) {
if (b == 0) {
return 1;
} else {
if (b % 2 == 0) {
ll temp = pow(a, b / 2);
return temp * temp;
} else {
return a * pow(a, b - 1);
}
}
}
struct hash_pair {
template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const {
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};
int main() {
ll n;
cin >> n;
vl a(n);
f(n) cin >> a[i];
sort(all(a));
ll mp[N];
fill(mp, 0);
f(n) { mp[a[i]]++; }
if (mp[1] > 0) {
if (mp[1] == 1) {
cout << 1 << endl;
} else {
cout << 0 << endl;
}
return 0;
}
ll ans = 0;
f(n) {
bool flag = false;
if (mp[a[i]] > 1)
continue;
for (ll j = 2; j <= sqrt(a[i]); j++) {
if (a[i] % j == 0) {
if ((a[i] / j) == j) {
if (mp[j] > 0) {
flag = true;
break;
}
} else {
if (mp[j] > 0 || mp[a[i] / j] > 0) {
flag = true;
break;
}
}
}
}
if (!flag) {
ans++;
}
}
cout << ans << endl;
} | replace | 85 | 86 | 85 | 87 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define optimizar_io \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define fore(i, a, b) for (int i = a; i < b; i++)
#define fori(i, a, b) for (int i = a; i <= b; i++)
#define pb push_back
#define popb pop_back
#define mk make_pair
#define fi first
#define se second
#define endl '\n'
#define MAX 1000005
typedef long long int lli;
typedef long double ld;
const double PI = acos(-1.0);
ld eps = 1e-9;
vector<int> bucket(MAX, 0);
bool is(set<int> s, int n) {
if (bucket[n] >= 2)
return false;
for (int i = 1; i * i <= n; i++) {
if (!(n % i)) {
if (s.count(i) && i != n)
return false;
if (i * i != n) {
if (s.count(n / i) && (n / i) != n)
return false;
}
}
}
return true;
}
int main() {
optimizar_io int n;
cin >> n;
vector<int> v(n);
set<int> s;
fore(i, 0, n) {
cin >> v[i];
bucket[v[i]]++;
s.insert(v[i]);
}
int cont = 0;
fore(i, 0, n) {
if (is(s, v[i]))
cont++;
}
cout << cont << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define optimizar_io \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define fore(i, a, b) for (int i = a; i < b; i++)
#define fori(i, a, b) for (int i = a; i <= b; i++)
#define pb push_back
#define popb pop_back
#define mk make_pair
#define fi first
#define se second
#define endl '\n'
#define MAX 1000005
typedef long long int lli;
typedef long double ld;
const double PI = acos(-1.0);
ld eps = 1e-9;
vector<int> bucket(MAX, 0);
bool is(set<int> &s, int n) {
if (bucket[n] >= 2)
return false;
for (int i = 1; i * i <= n; i++) {
if (!(n % i)) {
if (s.count(i) && i != n)
return false;
if (i * i != n) {
if (s.count(n / i) && (n / i) != n)
return false;
}
}
}
return true;
}
int main() {
optimizar_io int n;
cin >> n;
vector<int> v(n);
set<int> s;
fore(i, 0, n) {
cin >> v[i];
bucket[v[i]]++;
s.insert(v[i]);
}
int cont = 0;
fore(i, 0, n) {
if (is(s, v[i]))
cont++;
}
cout << cont << endl;
} | replace | 20 | 21 | 20 | 21 | TLE | |
p02642 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL << 30;
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
sort(all(a));
vector<bool> ok(n, false);
rep(i, n) {
if (ok[a[i]])
continue;
for (int j = 2 * a[i]; j <= a[n - 1]; j += a[i])
ok[j] = true;
if (a[i] == a[i + 1])
ok[a[i]] = true;
}
int ans = 0;
rep(i, n) {
if (!ok[a[i]]) {
ans++;
// cout<<a[i]<<endl;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL << 30;
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
sort(all(a));
vector<bool> ok(1000010, false);
rep(i, n) {
if (ok[a[i]])
continue;
for (int j = 2 * a[i]; j <= a[n - 1]; j += a[i])
ok[j] = true;
if (a[i] == a[i + 1])
ok[a[i]] = true;
}
int ans = 0;
rep(i, n) {
if (!ok[a[i]]) {
ans++;
// cout<<a[i]<<endl;
}
}
cout << ans << endl;
} | replace | 15 | 16 | 15 | 16 | 0 | |
p02642 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <vector>
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
const int MAXN = 2e5 + 10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x & (-x))
using namespace std;
// getline(cin,s);
// set<ll>::iterator it;
// map<int,int>::iterator it;
typedef long long ll;
// ai/aj!=0(1=<j<=n)
int need[MAXN];
int a[MAXN];
int main() {
int n;
int max1 = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]), max1 = max(max1, a[i]);
for (int i = 1; i <= n; i++) {
for (int j = a[i]; j <= max1; j += a[i]) {
need[j]++;
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
if (need[a[i]] == 1)
ans++;
}
printf("%d\n", ans);
return 0;
} | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <vector>
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
const int MAXN = 2e5 + 10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x & (-x))
using namespace std;
// getline(cin,s);
// set<ll>::iterator it;
// map<int,int>::iterator it;
typedef long long ll;
// ai/aj!=0(1=<j<=n)
int need[1000005];
int a[MAXN];
int main() {
int n;
int max1 = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]), max1 = max(max1, a[i]);
for (int i = 1; i <= n; i++) {
for (int j = a[i]; j <= max1; j += a[i]) {
need[j]++;
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
if (need[a[i]] == 1)
ans++;
}
printf("%d\n", ans);
return 0;
} | replace | 29 | 30 | 29 | 30 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3;
int main() {
int n, x;
cin >> n;
map<int, int> arr;
vector<int> v;
map<int, int> mp;
for (int i = 0; i < n; i++) {
cin >> x;
v.push_back(x);
mp[x]++;
}
sort(v.begin(), v.end());
int ans = 0;
for (int i = 0; i < n; i++) {
if (arr[v[i]] == 0) {
for (int j = v[i] * 2; j < N; j += v[i]) {
arr[j]++;
}
if (mp[v[i]] <= 1)
ans++;
}
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3;
int main() {
int n, x;
cin >> n;
map<int, int> arr;
vector<int> v;
map<int, int> mp;
for (int i = 0; i < n; i++) {
cin >> x;
v.push_back(x);
mp[x]++;
}
sort(v.begin(), v.end());
int ans = 0;
for (int i = 0; i < n; i++) {
if (arr[v[i]] == 0) {
for (int j = v[i]; j < N; j += v[i]) {
arr[j]++;
}
if (mp[v[i]] <= 1)
ans++;
}
}
cout << ans;
return 0;
}
| replace | 19 | 20 | 19 | 20 | TLE | |
p02642 | C++ | Time Limit Exceeded | #include <iostream>
#include <map>
#include <vector>
using namespace std;
#define FOR(it, A) for (auto it = A.begin(); it != A.end(); it++)
int main() {
int N;
cin >> N;
map<int, int> A;
map<int, int>::iterator it1, it2;
vector<int> overlapped;
for (int i = 0; i < N; i++) {
int a;
cin >> a;
it1 = A.find(a);
if (it1 == A.end())
A.insert(make_pair(a, 0));
else {
overlapped.push_back(a);
}
}
int count = 0;
int gop; // 1부터 곱해나가
int k;
FOR(it1, A) { // 작은 것
// Ai가 A
// Aj가 B
if (it1->second == 0) {
FOR(it2, A) { // 큰 것
gop = 2;
k = 0;
if (it1 != it2) { // 둘이 다를 때
while (!(k > A.rbegin()->first)) {
k = it1->first * gop;
if (k == it2->first) { // 배수의 관계야
it2->second = 1; // 큰 거만 1
}
gop++;
}
}
}
}
}
FOR(it1, overlapped) {
it2 = A.find(*it1);
it2->second = 1;
}
FOR(it1, A) {
if (it1->second == 0)
count++;
}
cout << count << endl;
return 0;
} | #include <iostream>
#include <map>
#include <vector>
using namespace std;
#define FOR(it, A) for (auto it = A.begin(); it != A.end(); it++)
int main() {
int N;
cin >> N;
map<int, int> A;
map<int, int>::iterator it1, it2;
vector<int> overlapped;
for (int i = 0; i < N; i++) {
int a;
cin >> a;
it1 = A.find(a);
if (it1 == A.end())
A.insert(make_pair(a, 0));
else {
overlapped.push_back(a);
}
}
int count = 0;
int gop; // 1부터 곱해나가
int k;
FOR(it1, A) { // 작은 것
// Ai가 A
// Aj가 B
if (it1->second == 0) { // 1이면 이미 누군가의 배수야
k = 0;
gop = 2;
while (!(k > A.rbegin()->first)) {
k = it1->first * gop;
it2 = A.find(k);
if (it2 != A.end())
it2->second = 1;
gop++;
}
}
}
FOR(it1, overlapped) {
it2 = A.find(*it1);
it2->second = 1;
}
FOR(it1, A) {
if (it1->second == 0)
count++;
}
cout << count << endl;
return 0;
} | replace | 29 | 42 | 29 | 38 | TLE | |
p02642 | C++ | Time Limit Exceeded |
// Problem : D - Not Divisible
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
long n;
cin >> n;
vector<bool> sieve(1000001, false);
vector<long> a(n);
for (long i = 0; i < n; i++)
cin >> a[i];
sort(a.begin(), a.end());
long count = 0;
for (long i = 0; i < n; i++) {
if (!sieve[a[i]] && (i == n - 1 || a[i + 1] != a[i]))
count++;
long j = a[i];
while (j <= (long)1e6) {
sieve[j] = true;
j += a[i];
}
}
cout << count << "\n";
return 0;
}
|
// Problem : D - Not Divisible
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
long n;
cin >> n;
vector<bool> sieve(1000001, false);
vector<long> a(n);
for (long i = 0; i < n; i++)
cin >> a[i];
sort(a.begin(), a.end());
long count = 0;
for (long i = 0; i < n; i++) {
if (!sieve[a[i]] && (i == n - 1 || a[i + 1] != a[i]))
count++;
if (!sieve[a[i]]) {
long j = a[i];
while (j <= (long)1e6) {
sieve[j] = true;
j += a[i];
}
}
}
cout << count << "\n";
return 0;
}
| replace | 27 | 31 | 27 | 33 | TLE | |
p02642 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for (llint(x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for (llint(x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
using namespace std;
typedef pair<llint, llint> P;
int n;
int a[200005], cnt[200005];
vector<int> vec[1000005];
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
cnt[a[i]]++;
}
for (int i = 1; i <= 1000000; i++) {
for (int j = i; j <= 1000000; j += i)
vec[j].push_back(i);
}
int ans = 0;
for (int i = 1; i <= n; i++) {
int sum = 0;
for (int j = 0; j < vec[a[i]].size(); j++) {
sum += cnt[vec[a[i]][j]];
}
if (sum == 1)
ans++;
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for (llint(x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for (llint(x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
using namespace std;
typedef pair<llint, llint> P;
int n;
int a[200005], cnt[1000005];
vector<int> vec[1000005];
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
cnt[a[i]]++;
}
for (int i = 1; i <= 1000000; i++) {
for (int j = i; j <= 1000000; j += i)
vec[j].push_back(i);
}
int ans = 0;
for (int i = 1; i <= n; i++) {
int sum = 0;
for (int j = 0; j < vec[a[i]].size(); j++) {
sum += cnt[vec[a[i]][j]];
}
if (sum == 1)
ans++;
}
cout << ans << endl;
return 0;
} | replace | 28 | 29 | 28 | 29 | TLE | |
p02642 | C++ | Runtime Error | #pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi = acos(-1);
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int>> matrix;
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS \
std::ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define reset(x, v) memset(x, v, sizeof(x))
#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
inline ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m) {
if (n == 0)
return 1;
ll p = power(a, n / 2, m);
p = (p % m * p % m) % m;
if (n % 2)
return (p % m * a % m) % m;
else
return p;
}
const double EPS = 1e-9;
const ll MOD = 998244353;
const ll hell = 1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);
double startTime;
double getCurrentTime() {
return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int N = 200005;
int f[N + 1];
int present[N + 1];
void solve() {
int n;
cin >> n;
int x;
for (int i = 0; i < n; i++) {
cin >> x;
f[x]++;
present[x] = 1;
}
for (int i = N; i >= 1; i--) {
for (int j = 2 * i; j <= N; j += i)
f[j] += f[i];
}
int ans = 0;
for (int i = 1; i <= N; i++)
if (f[i] == 1 && present[i]) {
ans++;
}
cout << ans << endl;
}
int32_t main() {
IOS;
int t;
t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
| #pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi = acos(-1);
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int>> matrix;
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS \
std::ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define reset(x, v) memset(x, v, sizeof(x))
#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
inline ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m) {
if (n == 0)
return 1;
ll p = power(a, n / 2, m);
p = (p % m * p % m) % m;
if (n % 2)
return (p % m * a % m) % m;
else
return p;
}
const double EPS = 1e-9;
const ll MOD = 998244353;
const ll hell = 1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);
double startTime;
double getCurrentTime() {
return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int N = 1000005;
int f[N + 1];
int present[N + 1];
void solve() {
int n;
cin >> n;
int x;
for (int i = 0; i < n; i++) {
cin >> x;
f[x]++;
present[x] = 1;
}
for (int i = N; i >= 1; i--) {
for (int j = 2 * i; j <= N; j += i)
f[j] += f[i];
}
int ans = 0;
for (int i = 1; i <= N; i++)
if (f[i] == 1 && present[i]) {
ans++;
}
cout << ans << endl;
}
int32_t main() {
IOS;
int t;
t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
| replace | 75 | 76 | 75 | 76 | 0 | |
p02642 | C++ | Time Limit Exceeded | #include <iostream>
int A[200001] = {};
int n_divisor[1000001] = {};
int main() {
int N;
std::cin >> N;
for (int i = 1; i <= N; i++) {
std::cin >> A[i];
}
for (int i = 1; i <= N; i++) {
int a = A[i];
for (int j = 1; a * j <= 1000000; j++) {
n_divisor[a * j]++;
}
}
int count = 0;
for (int i = 1; i <= N; i++) {
if (n_divisor[A[i]] == 1) {
count++;
}
}
std::cout << count << std::endl;
} | #include <iostream>
int A[200001] = {};
int n_divisor[1000001] = {};
int main() {
int N;
std::cin >> N;
for (int i = 1; i <= N; i++) {
std::cin >> A[i];
}
for (int i = 1; i <= N; i++) {
n_divisor[A[i]]++;
if (n_divisor[A[i]] == 1) {
for (int j = 2; A[i] * j <= 1000000; j++) {
n_divisor[A[i] * j]++;
}
}
}
int count = 0;
for (int i = 1; i <= N; i++) {
if (n_divisor[A[i]] == 1) {
count++;
}
}
std::cout << count << std::endl;
} | replace | 13 | 16 | 13 | 18 | TLE |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.