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
p02573
C++
Runtime Error
#include <bits/stdc++.h> #define ks \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define fr first #define sc second #define pb push_back #define pf push_front #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pa; template <class T> inline void read(T &res) { char c; T flag = 1; while ((c = getchar()) < '0' || c > '9') if (c == '-') flag = -1; res = c - '0'; while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0'; res *= flag; } void wenjian() { freopen("concatenation.in", "r", stdin); freopen("concatenation.out", "w", stdout); } void tempwj() { freopen("hash.in", "r", stdin); freopen("hash.out", "w", stdout); } ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll qpow(ll a, ll b, ll mod) { a %= mod; ll ans = 1; while (b) { if (b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } struct chongzai { int c; bool operator<(const chongzai &b) const { return c > b.c; } } s; const int maxn = 1e5 + 177; const ll mod = 0x3f3f3f3f3f3f3f3f; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; int maxx = 1; int fa[maxn], siz[maxn]; int d[maxn]; int get(int now) { if (now == fa[now]) { return now; } int root = get(fa[now]); d[now] += d[fa[now]]; return fa[now] = root; } void bcj(int x, int y) { int xx = get(x); int yy = get(y); if (xx != yy) { fa[xx] = yy; d[xx] = siz[yy]; siz[yy] += siz[xx]; maxx = max(maxx, siz[yy]); } } int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { fa[i] = i; siz[i] = 1; } int a, b; for (int i = 1; i <= m; i++) { scanf("%d%d", &a, &b); bcj(a, b); } printf("%d\n", maxx); }
#include <bits/stdc++.h> #define ks \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define fr first #define sc second #define pb push_back #define pf push_front #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pa; template <class T> inline void read(T &res) { char c; T flag = 1; while ((c = getchar()) < '0' || c > '9') if (c == '-') flag = -1; res = c - '0'; while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0'; res *= flag; } void wenjian() { freopen("concatenation.in", "r", stdin); freopen("concatenation.out", "w", stdout); } void tempwj() { freopen("hash.in", "r", stdin); freopen("hash.out", "w", stdout); } ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll qpow(ll a, ll b, ll mod) { a %= mod; ll ans = 1; while (b) { if (b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } struct chongzai { int c; bool operator<(const chongzai &b) const { return c > b.c; } } s; const int maxn = 4e5 + 177; const ll mod = 0x3f3f3f3f3f3f3f3f; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; int maxx = 1; int fa[maxn], siz[maxn]; int d[maxn]; int get(int now) { if (now == fa[now]) { return now; } int root = get(fa[now]); d[now] += d[fa[now]]; return fa[now] = root; } void bcj(int x, int y) { int xx = get(x); int yy = get(y); if (xx != yy) { fa[xx] = yy; d[xx] = siz[yy]; siz[yy] += siz[xx]; maxx = max(maxx, siz[yy]); } } int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { fa[i] = i; siz[i] = 1; } int a, b; for (int i = 1; i <= m; i++) { scanf("%d%d", &a, &b); bcj(a, b); } printf("%d\n", maxx); }
replace
50
51
50
51
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> // #include<atcoder/all> using namespace std; // using namespace atcoder; #define rep(i, n) for (ll i = 0; i < n; i++) #define repl(i, l, r) for (ll i = (l); i < (r); i++) #define per(i, n) for (ll i = n - 1; i >= 0; i--) #define perl(i, r, l) for (ll i = r - 1; i >= l; i--) #define fi first #define se second #define pb push_back #define ins insert #define all(x) (x).begin(), (x).end() using ll = long long; using vl = vector<ll>; using vvl = vector<vector<ll>>; const ll MOD = 1000000007; const ll MOD9 = 998244353; const int inf = 1e9 + 10; const ll INF = 4e18; const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1}; using Graph = vector<vector<int>>; // dijkstra  struct edge { ll to, cost; }; typedef pair<ll, ll> P; struct graph { ll V; vector<vector<edge>> G; vector<ll> d; graph(ll n) { init(n); } void init(ll n) { V = n; G.resize(V); d.resize(V); rep(i, V) { d[i] = INF; } } void add_edge(ll s, ll t, ll cost) { edge e; e.to = t, e.cost = cost; G[s].push_back(e); } void dijkstra(ll s) { rep(i, V) { d[i] = INF; } d[s] = 0; priority_queue<P, vector<P>, greater<P>> que; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); ll v = p.second; if (d[v] < p.first) continue; for (auto e : G[v]) { if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } } }; // dijkstra end class UnionFind { public: ll par[100005]; ll depth[100005]; ll nGroup[100005]; UnionFind(ll n) { init(n); } void init(ll n) { for (ll i = 0; i < n; i++) { par[i] = i; depth[i] = 0; nGroup[i] = 1; } } ll root(ll x) { if (par[x] == x) { return x; } else { 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; if (depth[x] < depth[y]) { par[x] = y; nGroup[y] += nGroup[x]; nGroup[x] = 0; } else { par[y] = x; nGroup[x] += nGroup[y]; nGroup[y] = 0; if (depth[x] == depth[y]) depth[x]++; } } }; // unionfind end // nCr const ll MAX = 500010; ll 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; } } // nCr end // tree DP vector<ll> depth; vector<ll> f; vector<ll> g; void dfs(const Graph &G, ll v, ll p, ll d) { depth[v] = d; for (auto nv : G[v]) { if (nv == p) continue; dfs(G, nv, v, d + 1); } f[v] = 1; g[v] = 1; for (auto c : G[v]) { if (c == p) continue; f[v] *= g[c]; f[v] %= MOD; g[v] *= f[c]; g[v] %= MOD; } f[v] += g[v]; f[v] %= MOD; } // tree DP end template <ll MOD> struct Fp { ll val; constexpr Fp(ll v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr ll getmod() { return MOD; } constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=(const Fp &r) noexcept { ll a = r.val, b = MOD, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, ll n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; using mint = Fp<MOD>; mint calc(ll N, ll K) { mint res = 1; for (ll n = 0; n < K; ++n) { res *= (N - n); res /= (n + 1); } return res; } mint COM(ll n, ll k) { if (k == 0) return 1; if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { ll n, m; cin >> n >> m; UnionFind tree(n); for (ll i = 0; i < m; i++) { ll a, b; cin >> a >> b; a--; b--; tree.unite(a, b); } ll k = 0; rep(i, n) { k = max(k, tree.nGroup[i]); } cout << k << endl; }
#include <bits/stdc++.h> // #include<atcoder/all> using namespace std; // using namespace atcoder; #define rep(i, n) for (ll i = 0; i < n; i++) #define repl(i, l, r) for (ll i = (l); i < (r); i++) #define per(i, n) for (ll i = n - 1; i >= 0; i--) #define perl(i, r, l) for (ll i = r - 1; i >= l; i--) #define fi first #define se second #define pb push_back #define ins insert #define all(x) (x).begin(), (x).end() using ll = long long; using vl = vector<ll>; using vvl = vector<vector<ll>>; const ll MOD = 1000000007; const ll MOD9 = 998244353; const int inf = 1e9 + 10; const ll INF = 4e18; const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1}; using Graph = vector<vector<int>>; // dijkstra  struct edge { ll to, cost; }; typedef pair<ll, ll> P; struct graph { ll V; vector<vector<edge>> G; vector<ll> d; graph(ll n) { init(n); } void init(ll n) { V = n; G.resize(V); d.resize(V); rep(i, V) { d[i] = INF; } } void add_edge(ll s, ll t, ll cost) { edge e; e.to = t, e.cost = cost; G[s].push_back(e); } void dijkstra(ll s) { rep(i, V) { d[i] = INF; } d[s] = 0; priority_queue<P, vector<P>, greater<P>> que; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); ll v = p.second; if (d[v] < p.first) continue; for (auto e : G[v]) { if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } } }; // dijkstra end class UnionFind { public: ll par[200005]; ll depth[200005]; ll nGroup[200005]; UnionFind(ll n) { init(n); } void init(ll n) { for (ll i = 0; i < n; i++) { par[i] = i; depth[i] = 0; nGroup[i] = 1; } } ll root(ll x) { if (par[x] == x) { return x; } else { 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; if (depth[x] < depth[y]) { par[x] = y; nGroup[y] += nGroup[x]; nGroup[x] = 0; } else { par[y] = x; nGroup[x] += nGroup[y]; nGroup[y] = 0; if (depth[x] == depth[y]) depth[x]++; } } }; // unionfind end // nCr const ll MAX = 500010; ll 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; } } // nCr end // tree DP vector<ll> depth; vector<ll> f; vector<ll> g; void dfs(const Graph &G, ll v, ll p, ll d) { depth[v] = d; for (auto nv : G[v]) { if (nv == p) continue; dfs(G, nv, v, d + 1); } f[v] = 1; g[v] = 1; for (auto c : G[v]) { if (c == p) continue; f[v] *= g[c]; f[v] %= MOD; g[v] *= f[c]; g[v] %= MOD; } f[v] += g[v]; f[v] %= MOD; } // tree DP end template <ll MOD> struct Fp { ll val; constexpr Fp(ll v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr ll getmod() { return MOD; } constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=(const Fp &r) noexcept { ll a = r.val, b = MOD, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, ll n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; using mint = Fp<MOD>; mint calc(ll N, ll K) { mint res = 1; for (ll n = 0; n < K; ++n) { res *= (N - n); res /= (n + 1); } return res; } mint COM(ll n, ll k) { if (k == 0) return 1; if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { ll n, m; cin >> n >> m; UnionFind tree(n); for (ll i = 0; i < m; i++) { ll a, b; cin >> a >> b; a--; b--; tree.unite(a, b); } ll k = 0; rep(i, n) { k = max(k, tree.nGroup[i]); } cout << k << endl; }
replace
73
76
73
76
0
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; #define forn(i, n) for (ll i = 0; i < ll(n); i++) class DisjointSet { vector<ll> Parent, Rank; public: DisjointSet(ll n) { forn(i, n + 1) Parent.push_back(i), Rank.push_back(0); } ll Find(ll x) { while (Parent[x] != x) x = Parent[x]; return x; } void Union(ll x, ll y) { ll u = Find(x); ll v = Find(y); if (u == v) return; if (Rank[u] > Rank[v]) Parent[v] = u; else { Parent[u] = v; if (Rank[u] == Rank[v]) Rank[u]++; } return; } }; int main() { ll n, m; cin >> n >> m; DisjointSet dis(n); ll j, k; ll ans = 1; forn(i, m) { cin >> j >> k; dis.Union(j, k); } map<ll, ll> mp; forn(i, n) { ll u = dis.Find(i + 1); mp[u]++; ans = max(mp[u], ans); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; #define forn(i, n) for (ll i = 0; i < ll(n); i++) class DisjointSet { vector<ll> Parent, Rank; public: DisjointSet(ll n) { forn(i, n + 1) Parent.push_back(i), Rank.push_back(0); } ll Find(ll x) { if (Parent[x] == x) return x; else Parent[x] = Find(Parent[x]); return Parent[x]; } void Union(ll x, ll y) { ll u = Find(x); ll v = Find(y); if (u == v) return; if (Rank[u] > Rank[v]) Parent[v] = u; else { Parent[u] = v; if (Rank[u] == Rank[v]) Rank[u]++; } return; } }; int main() { ll n, m; cin >> n >> m; DisjointSet dis(n); ll j, k; ll ans = 1; forn(i, m) { cin >> j >> k; dis.Union(j, k); } map<ll, ll> mp; forn(i, n) { ll u = dis.Find(i + 1); mp[u]++; ans = max(mp[u], ans); } cout << ans << endl; return 0; }
replace
12
15
12
17
TLE
p02573
C++
Runtime Error
// コンパイラ最適化用 #pragma GCC optimize("Ofast") #define _GLIBCXX_DEBUG // インクルード(アルファベット順) #include <algorithm> //sort,二分探索,など #include <bits/stdc++.h> #include <bitset> //固定長bit集合 #include <chrono> //実行時間計測 #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,accumulate #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; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<int, int> pii; typedef pair<ll, ld> pld; typedef pair<pii, int> ppiii; typedef pair<pii, ll> ppiill; typedef pair<pll, ll> ppllll; typedef pair<pli, int> pplii; typedef map<int, int> mii; typedef deque<ll> dll; typedef queue<ll> qll; typedef priority_queue<ll> pqll; typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<vector<int>> vvint; typedef vector<vector<pll>> vvpll; // マクロ // 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() #define SIZE(x) ll(x.size()) // 定数 #define INF 1000000000000 // 10^12:∞ #define MOD 1000000007 // 10^9+7:合同式の法 #define MAXR 100000 // 10^5:配列の最大のrange // 略記 #define cin(x) cin >> x struct UnionFind { vector<int> r; UnionFind(int N) { r = vector<int>(N, -1); } int root(int x) { if (r[x] < 0) return x; return r[x] = root(r[x]); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (r[x] > r[y]) swap(x, y); r[x] += r[y]; r[y] = x; return true; } int size(int x) { return -r[root(x)]; } }; int main() { int N, M; cin >> N >> M; UnionFind UF(N); for (int i = 0; i < M; i++) { int A, B; cin >> A >> B; A -= -1; B -= -1; UF.unite(A, B); } int ans = 0; for (int i = 0; i < N; i++) { ans = max(ans, UF.size(i)); } cout << ans << endl; }
// コンパイラ最適化用 #pragma GCC optimize("Ofast") #define _GLIBCXX_DEBUG // インクルード(アルファベット順) #include <algorithm> //sort,二分探索,など #include <bits/stdc++.h> #include <bitset> //固定長bit集合 #include <chrono> //実行時間計測 #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,accumulate #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; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<int, int> pii; typedef pair<ll, ld> pld; typedef pair<pii, int> ppiii; typedef pair<pii, ll> ppiill; typedef pair<pll, ll> ppllll; typedef pair<pli, int> pplii; typedef map<int, int> mii; typedef deque<ll> dll; typedef queue<ll> qll; typedef priority_queue<ll> pqll; typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<vector<int>> vvint; typedef vector<vector<pll>> vvpll; // マクロ // 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() #define SIZE(x) ll(x.size()) // 定数 #define INF 1000000000000 // 10^12:∞ #define MOD 1000000007 // 10^9+7:合同式の法 #define MAXR 100000 // 10^5:配列の最大のrange // 略記 #define cin(x) cin >> x struct UnionFind { vector<int> r; UnionFind(int N) { r = vector<int>(N, -1); } int root(int x) { if (r[x] < 0) return x; return r[x] = root(r[x]); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (r[x] > r[y]) swap(x, y); r[x] += r[y]; r[y] = x; return true; } int size(int x) { return -r[root(x)]; } }; int main() { int N, M; cin >> N >> M; UnionFind UF(N); for (int i = 0; i < M; i++) { int A, B; cin >> A >> B; A -= 1; B -= 1; UF.unite(A, B); } int ans = 0; for (int i = 0; i < N; i++) { ans = max(ans, UF.size(i)); } cout << ans << endl; }
replace
100
102
100
102
-6
/usr/include/c++/12/debug/vector:442: In function: std::debug::vector<_Tp, _Allocator>::reference std::debug::vector<_Tp, _Allocator>::operator[](size_type) [with _Tp = int; _Allocator = std::allocator<int>; reference = int&; size_type = long unsigned int] Error: attempt to subscript container with out-of-bounds index 5, but container only holds 5 elements. Objects involved in the operation: sequence "this" @ 0x7ffde5198b90 { type = std::debug::vector<int, std::allocator<int> >; }
p02573
C++
Runtime Error
// This file is a "Hello, world!" in C++ language by GCC for wandbox. #include <algorithm> #include <bits/stdc++.h> #include <cstdlib> #include <iostream> using namespace std; vector<bool> seen; int dfs(const vector<vector<int>> &G, int v) { int size = 1, p = 0; seen[v] = true; // v を訪問済にする // v から行ける各頂点 next_v について for (auto next_v : G[v]) { if (seen[next_v]) continue; // next_v が探索済だったらスルー // dfs(G, next_v); // 再帰的に探索 p = dfs(G, next_v); size += p; } return size; } int main() { int n, i, j, m, ans = 0; int a[100000], b[100000]; cin >> n >> m; vector<vector<int>> group(n); seen.assign(n, false); for (i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i] -= 1; b[i] -= 1; group.at(a[i]).push_back(b[i]); group.at(b[i]).push_back(a[i]); } for (i = 0; i < n; i++) { if (seen[i] == false) { // ans=dfs(group,i); ans = max(ans, dfs(group, i)); } } cout << ans << endl; }
// This file is a "Hello, world!" in C++ language by GCC for wandbox. #include <algorithm> #include <bits/stdc++.h> #include <cstdlib> #include <iostream> using namespace std; vector<bool> seen; int dfs(const vector<vector<int>> &G, int v) { int size = 1, p = 0; seen[v] = true; // v を訪問済にする // v から行ける各頂点 next_v について for (auto next_v : G[v]) { if (seen[next_v]) continue; // next_v が探索済だったらスルー // dfs(G, next_v); // 再帰的に探索 p = dfs(G, next_v); size += p; } return size; } int main() { int n, i, j, m, ans = 0; int a[200010], b[200010]; cin >> n >> m; vector<vector<int>> group(n); seen.assign(n, false); for (i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i] -= 1; b[i] -= 1; group.at(a[i]).push_back(b[i]); group.at(b[i]).push_back(a[i]); } for (i = 0; i < n; i++) { if (seen[i] == false) { // ans=dfs(group,i); ans = max(ans, dfs(group, i)); } } cout << ans << endl; }
replace
23
24
23
24
0
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define SP << " " #define LLi long long int using namespace std; void PV(vector<int> pvv) { rep(i, pvv.size()) cout << pvv[i] SP; cout << endl; } void PVL(vector<LLi> pvv) { rep(i, pvv.size()) cout << pvv[i] SP; cout << endl; } bool VV(vector<int> vv1, vector<int> vv2) { if (vv1.size() != vv2.size()) return false; rep(i, vv1.size()) if (vv1[i] != vv2[i]) return false; return true; } bool VVL(vector<LLi> vv1, vector<LLi> vv2) { if (vv1.size() != vv2.size()) return false; rep(i, vv1.size()) if (vv1[i] != vv2[i]) return false; return true; } // vecotr<LLi>の総和 LLi SML(vector<LLi> smv) { LLi tmp = 0; rep(i, smv.size()) tmp += smv[i]; return tmp; } struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 vector<int> siz; // siz[i]:iの属する木に含まれる点の数 UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) par[i] = i; siz.resize(par.size(), 1); // 最初は全てサイズ1 } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } int tsize(int x) { // siz[x]の木の根を見に行き、サイズを返す if (par[x] == x) return siz[x]; return tsize(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); // xの根をrx int ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける siz[rx] += siz[ry]; // 根で管理 siz[ry] = siz[rx]; // 根で管理 } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; int main() { int n, m, a, b, ma = 0; cin >> n >> m; UnionFind uf(n); rep(i, m) { cin >> a >> b; uf.unite(a - 1, b - 1); } rep(i, n) ma = max(ma, uf.tsize(i)); cout << ma << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define SP << " " #define LLi long long int using namespace std; void PV(vector<int> pvv) { rep(i, pvv.size()) cout << pvv[i] SP; cout << endl; } void PVL(vector<LLi> pvv) { rep(i, pvv.size()) cout << pvv[i] SP; cout << endl; } bool VV(vector<int> vv1, vector<int> vv2) { if (vv1.size() != vv2.size()) return false; rep(i, vv1.size()) if (vv1[i] != vv2[i]) return false; return true; } bool VVL(vector<LLi> vv1, vector<LLi> vv2) { if (vv1.size() != vv2.size()) return false; rep(i, vv1.size()) if (vv1[i] != vv2[i]) return false; return true; } // vecotr<LLi>の総和 LLi SML(vector<LLi> smv) { LLi tmp = 0; rep(i, smv.size()) tmp += smv[i]; return tmp; } struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 vector<int> siz; // siz[i]:iの属する木に含まれる点の数 UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) par[i] = i; siz.resize(par.size(), 1); // 最初は全てサイズ1 } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } int tsize(int x) { // siz[x]の木の根を見に行き、サイズを返す if (par[x] == x) return siz[x]; par[x] = root(par[x]); return tsize(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); // xの根をrx int ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける siz[rx] += siz[ry]; // 根で管理 siz[ry] = siz[rx]; // 根で管理 } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; int main() { int n, m, a, b, ma = 0; cin >> n >> m; UnionFind uf(n); rep(i, m) { cin >> a >> b; uf.unite(a - 1, b - 1); } rep(i, n) ma = max(ma, uf.tsize(i)); cout << ma << endl; return 0; }
insert
62
62
62
63
TLE
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; vector<int> e[200005]; int n, m, ans; bool vis[200005]; int bfs(int x) { queue<int> q; int num = 1; q.push(x); vis[x] = 1; while (!q.empty()) { int k = q.front(); q.pop(); for (int i = 0; i < e[k].size(); ++i) if (!vis[e[k][i]]) { vis[e[k][i]] = 1; ++num; q.push(e[k][i]); } } if (num > ans) ans = num; } int main() { cin >> n >> m; for (int i = 0; i < m; ++i) { int x, y; cin >> x >> y; e[x].push_back(y); e[y].push_back(x); } for (int i = 1; i <= n; ++i) if (!vis[i]) bfs(i); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> e[200005]; int n, m, ans; bool vis[200005]; void bfs(int x) { queue<int> q; int num = 1; q.push(x); vis[x] = 1; while (!q.empty()) { int k = q.front(); q.pop(); for (int i = 0; i < e[k].size(); ++i) if (!vis[e[k][i]]) { vis[e[k][i]] = 1; ++num; q.push(e[k][i]); } } if (num > ans) ans = num; } int main() { cin >> n >> m; for (int i = 0; i < m; ++i) { int x, y; cin >> x >> y; e[x].push_back(y); e[y].push_back(x); } for (int i = 1; i <= n; ++i) if (!vis[i]) bfs(i); cout << ans; return 0; }
replace
5
6
5
6
0
p02573
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define MP make_pair #define PB push_back #define SZ size() #define B begin() #define E end() #define ll long long #define REP(i, a, n) for (ll i = a; i < n; ++i) #define RED(i, n, a) for (ll i = n; i >= a; --i) #define m9 1000000007 #define endl "\n" #define F first #define S second #define ld long double #define eps 0.00000000001 #define MAX 1000000007 #define vll vector<ll> #define pll pair<ll, ll> using namespace std; ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } ll powc(ll a, ll b) { if (b < 0) { return -1; } ll res = 1; while (b > 0) { if (b & 1) { res *= a; } a *= a; // res%=m9, a%=m9; b >>= 1; } return res; } vector<vector<ll>> graph(1e5 + 10); vector<ll> visited(2e5 + 10, 0); ll cnt = 0; void dfs(ll in) { cnt++; visited[in] = 1; REP(i, 0, (ll)graph[in].SZ) { if (!visited[graph[in][i]]) { dfs(graph[in][i]); } } } /// target expert int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, m; cin >> n >> m; REP(i, 0, m) { ll u, v; cin >> u >> v; graph[u].PB(v), graph[v].PB(u); } ll ans = 0; REP(i, 1, n + 1) { if (!visited[i]) { cnt = 0; dfs(i); } ans = max(ans, cnt); } cout << ans; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define MP make_pair #define PB push_back #define SZ size() #define B begin() #define E end() #define ll long long #define REP(i, a, n) for (ll i = a; i < n; ++i) #define RED(i, n, a) for (ll i = n; i >= a; --i) #define m9 1000000007 #define endl "\n" #define F first #define S second #define ld long double #define eps 0.00000000001 #define MAX 1000000007 #define vll vector<ll> #define pll pair<ll, ll> using namespace std; ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } ll powc(ll a, ll b) { if (b < 0) { return -1; } ll res = 1; while (b > 0) { if (b & 1) { res *= a; } a *= a; // res%=m9, a%=m9; b >>= 1; } return res; } vector<vector<ll>> graph(2e5 + 10); vector<ll> visited(2e5 + 10, 0); ll cnt = 0; void dfs(ll in) { cnt++; visited[in] = 1; REP(i, 0, (ll)graph[in].SZ) { if (!visited[graph[in][i]]) { dfs(graph[in][i]); } } } /// target expert int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, m; cin >> n >> m; REP(i, 0, m) { ll u, v; cin >> u >> v; graph[u].PB(v), graph[v].PB(u); } ll ans = 0; REP(i, 1, n + 1) { if (!visited[i]) { cnt = 0; dfs(i); } ans = max(ans, cnt); } cout << ans; }
replace
54
55
54
55
0
p02573
C++
Runtime Error
// C++ implementation of the above approach #include <bits/stdc++.h> using namespace std; const int maxx = 100005; vector<int> graph[maxx]; void dfs(int curr, int &cnt, int *visited, vector<int> &duringdfs) { visited[curr] = 1; ++cnt; duringdfs.push_back(curr); for (auto &child : graph[curr]) { if (visited[child] == 0) { dfs(child, cnt, visited, duringdfs); } } } void MaximumVisit(int n) { int visited[maxx]; memset(visited, 0, sizeof visited); int ans[maxx]; memset(ans, 0, sizeof ans); vector<int> duringdfs; for (int i = 1; i <= n; ++i) { duringdfs.clear(); int cnt = 0; if (visited[i] == 0) { cnt = 0; dfs(i, cnt, visited, duringdfs); } for (auto &x : duringdfs) { ans[x] = cnt; } } int an = 0; for (int i = 1; i <= n; ++i) { an = max(an, ans[i]); } cout << an; return; } int main() { int n, k, a, b; cin >> n >> k; for (int i = 0; i < k; i++) { cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } MaximumVisit(n); return 0; }
// C++ implementation of the above approach #include <bits/stdc++.h> using namespace std; const int maxx = 200005; vector<int> graph[maxx]; void dfs(int curr, int &cnt, int *visited, vector<int> &duringdfs) { visited[curr] = 1; ++cnt; duringdfs.push_back(curr); for (auto &child : graph[curr]) { if (visited[child] == 0) { dfs(child, cnt, visited, duringdfs); } } } void MaximumVisit(int n) { int visited[maxx]; memset(visited, 0, sizeof visited); int ans[maxx]; memset(ans, 0, sizeof ans); vector<int> duringdfs; for (int i = 1; i <= n; ++i) { duringdfs.clear(); int cnt = 0; if (visited[i] == 0) { cnt = 0; dfs(i, cnt, visited, duringdfs); } for (auto &x : duringdfs) { ans[x] = cnt; } } int an = 0; for (int i = 1; i <= n; ++i) { an = max(an, ans[i]); } cout << an; return; } int main() { int n, k, a, b; cin >> n >> k; for (int i = 0; i < k; i++) { cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } MaximumVisit(n); return 0; }
replace
3
4
3
4
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; using ll = long long; #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define YESNO(T) \ if (T) { \ cout << "YES" << endl; \ } else { \ cout << "NO" << endl; \ } #define yesno(T) \ if (T) { \ cout << "yes" << endl; \ } else { \ cout << "no" << endl; \ } #define YesNo(T) \ if (T) { \ cout << "Yes" << endl; \ } else { \ cout << "No" << endl; \ } const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; const double pi = 3.14159265358979; struct UnionFind { vector<ll> d; // 親(負)…木のsize*(-1) // 子(正)…親のindex UnionFind(ll n) { d = vector<ll>(n, -1); } // 初期化 ll find(ll x) { if (d[x] < 0) return x; return d[x] = find(d[x]); } // 親のindexを返す bool unite(ll x, ll 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(ll x, ll y) { return find(x) == find(y) ? true : false; } // xとyの親が同じか判定する ll size(ll x) { return -d[find(x)]; } // xが属する木のsizeを返す }; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, m; cin >> n >> m; UnionFind uf(n); rep(i, m) { ll a, b; cin >> a >> b; a--; b--; uf.unite(a, b); } ll ans = 0; rep(i, m) { ans = max(ans, uf.size(i)); } cout << ans << endl; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; using ll = long long; #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define YESNO(T) \ if (T) { \ cout << "YES" << endl; \ } else { \ cout << "NO" << endl; \ } #define yesno(T) \ if (T) { \ cout << "yes" << endl; \ } else { \ cout << "no" << endl; \ } #define YesNo(T) \ if (T) { \ cout << "Yes" << endl; \ } else { \ cout << "No" << endl; \ } const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; const double pi = 3.14159265358979; struct UnionFind { vector<ll> d; // 親(負)…木のsize*(-1) // 子(正)…親のindex UnionFind(ll n) { d = vector<ll>(n, -1); } // 初期化 ll find(ll x) { if (d[x] < 0) return x; return d[x] = find(d[x]); } // 親のindexを返す bool unite(ll x, ll 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(ll x, ll y) { return find(x) == find(y) ? true : false; } // xとyの親が同じか判定する ll size(ll x) { return -d[find(x)]; } // xが属する木のsizeを返す }; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, m; cin >> n >> m; UnionFind uf(n); rep(i, m) { ll a, b; cin >> a >> b; a--; b--; uf.unite(a, b); } ll ans = 0; rep(i, n) { ans = max(ans, uf.size(i)); } cout << ans << endl; }
replace
87
88
87
88
0
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long struct UnionFind { vector<int> par; vector<int> siz; UnionFind(int n) : par(n), siz(n) { for (int i = 0; i < n; i++) { par[i] = i; siz[i] = 1; } } int root(int x) { if (par[x] == x) return x; else return par[x] = root(par[x]); } int size(int x) { if (par[x] == x) return siz[x]; else return siz[x] = size(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx != ry) { par[ry] = rx; siz[rx] += siz[ry]; } } bool same(int x, int y) { return root(x) == root(y); } }; signed main() { // cout << fixed << setprecision(10) << flush; int n, m; cin >> n >> m; UnionFind uf(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; uf.unite(a - 1, b - 1); } int maxsize = 0; for (int i = 0; i < n; i++) { maxsize = max(maxsize, uf.size(i)); } cout << maxsize << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long struct UnionFind { vector<int> par; vector<int> siz; UnionFind(int n) : par(n), siz(n) { for (int i = 0; i < n; i++) { par[i] = i; siz[i] = 1; } } int root(int x) { if (par[x] == x) return x; else return par[x] = root(par[x]); } int size(int x) { return siz[root(x)]; } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx != ry) { par[ry] = rx; siz[rx] += siz[ry]; } } bool same(int x, int y) { return root(x) == root(y); } }; signed main() { // cout << fixed << setprecision(10) << flush; int n, m; cin >> n >> m; UnionFind uf(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; uf.unite(a - 1, b - 1); } int maxsize = 0; for (int i = 0; i < n; i++) { maxsize = max(maxsize, uf.size(i)); } cout << maxsize << endl; return 0; }
replace
22
28
22
23
TLE
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long struct UnionFind { vector<int> par; vector<int> siz; UnionFind(int n) : par(n), siz(n) { for (int i = 0; i < n; i++) { par[i] = i; siz[i] = 1; } } int root(int x) { if (par[x] == x) return x; else return par[x] = root(par[x]); } int size(int x) { if (par[x] == x) return siz[x]; else return siz[x] = size(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx != ry) { par[ry] = rx; siz[rx] += siz[ry]; } } bool same(int x, int y) { return root(x) == root(y); } }; signed main() { // cout << fixed << setprecision(10) << flush; int n, m; cin >> n >> m; UnionFind uf(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; uf.unite(a - 1, b - 1); } int maxsize = 0; for (int i = 0; i < n; i++) { maxsize = max(maxsize, uf.size(i)); } cout << maxsize << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long struct UnionFind { vector<int> par; vector<int> siz; UnionFind(int n) : par(n), siz(n) { for (int i = 0; i < n; i++) { par[i] = i; siz[i] = 1; } } int root(int x) { if (par[x] == x) return x; else return par[x] = root(par[x]); } int size(int x) { if (par[x] == x) return siz[x]; else return siz[x] = size(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx != ry) { par[ry] = rx; siz[rx] += siz[ry]; } } bool same(int x, int y) { return root(x) == root(y); } }; signed main() { // cout << fixed << setprecision(10) << flush; int n, m; cin >> n >> m; UnionFind uf(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; uf.unite(a - 1, b - 1); } int maxsize = 0; for (int i = 0; i < n; i++) { maxsize = max(maxsize, uf.siz[i]); } cout << maxsize << endl; return 0; }
replace
56
57
56
57
TLE
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> #pragma GCC optimize(3) #define endl '\n' #define ll long long #define ld long double #define ull unsigned long long using namespace std; struct _IO { _IO() { ios::sync_with_stdio(0); cin.tie(0); } } _io; int parent[200005], value[200005]; int maxn = 1; int find(int a) { if (parent[a] == a) { return a; } else { return find(parent[a]); } } void freedom(int n) { for (int i = 1; i <= n; i++) { parent[i] = i; value[i] = 1; } return; } void unionxy(int a, int b) { if (find(a) == find(b)) { return; } else { value[find(a)] += value[find(b)]; maxn = max(maxn, value[find(a)]); parent[find(b)] = find(a); } } int main() { int n, m; cin >> n >> m; freedom(n); for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; unionxy(a, b); } cout << maxn << endl; }
#include <bits/stdc++.h> #pragma GCC optimize(3) #define endl '\n' #define ll long long #define ld long double #define ull unsigned long long using namespace std; struct _IO { _IO() { ios::sync_with_stdio(0); cin.tie(0); } } _io; int parent[200005], value[200005]; int maxn = 1; int find(int a) { if (parent[a] == a) { return a; } else { return find(parent[a]); } } void freedom(int n) { for (int i = 1; i <= n; i++) { parent[i] = i; value[i] = 1; } return; } void unionxy(int a, int b) { if (find(a) == find(b)) { return; } else { value[find(a)] += value[find(b)]; maxn = max(maxn, value[find(a)]); parent[find(b)] = find(a); parent[b] = parent[find(b)]; parent[a] = parent[find(a)]; } } int main() { int n, m; cin >> n >> m; freedom(n); for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; unionxy(a, b); } cout << maxn << endl; }
insert
39
39
39
41
TLE
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define repp(i, n, m) for (int(i) = (n); (i) < (m); (i)++) #define repn(i, n) for (int(i) = 1; (i) <= (n); (i)++) #define repr(i, n) for (int(i) = (n - 1); (i) >= 0; (i)--) #define all(x) (x).begin(), (x).end() #define lint long long #define ulint unsigned long long #define ldou long double #define fi first #define se second #define setpre(x) std::cout << fixed << setprecision(x) #define ii(x) \ int x; \ cin >> (x) #define ii2(x, y) \ int x, y; \ cin >> (x) >> (y) #define ii3(x, y, z) \ int x, y, z; \ cin >> (x) >> (y) >> (z) #define out(x) cout << (x) << endl #define outs(x) cout << (x) << " " #define yn(x) cout << ((x) ? ("Yes") : ("No")) << endl #define YN(x) cout << ((x) ? ("YES") : ("NO")) << endl #define bit_c(x) __builtin_popcountll(x) inline void logger() { std::cout << " [LOGGER] " << endl; } template <typename A, typename... B> void logger(const A &a, const B &...b) { cout << a << " , "; logger(b...); } typedef pair<lint, lint> P; const lint MOD = 1000000007; const lint MOD9 = 998244353; const lint INF = MOD * MOD; const int MAX = 100005; /* ...o(^-^)o... */ vector<int> to[MAX]; bool seen[MAX]; int dfs(int s) { seen[s] = true; int tmp = 1; for (auto t : to[s]) { if (seen[t]) continue; tmp += dfs(t); } return tmp; } int main() { int n, m; cin >> n >> m; rep(i, m) { int a, b; cin >> a >> b; a--; b--; to[a].push_back(b); to[b].push_back(a); } int ans = 0; rep(i, n) { if (seen[i]) continue; seen[i] = true; int connect = dfs(i); ans = max(connect, ans); } out(ans); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define repp(i, n, m) for (int(i) = (n); (i) < (m); (i)++) #define repn(i, n) for (int(i) = 1; (i) <= (n); (i)++) #define repr(i, n) for (int(i) = (n - 1); (i) >= 0; (i)--) #define all(x) (x).begin(), (x).end() #define lint long long #define ulint unsigned long long #define ldou long double #define fi first #define se second #define setpre(x) std::cout << fixed << setprecision(x) #define ii(x) \ int x; \ cin >> (x) #define ii2(x, y) \ int x, y; \ cin >> (x) >> (y) #define ii3(x, y, z) \ int x, y, z; \ cin >> (x) >> (y) >> (z) #define out(x) cout << (x) << endl #define outs(x) cout << (x) << " " #define yn(x) cout << ((x) ? ("Yes") : ("No")) << endl #define YN(x) cout << ((x) ? ("YES") : ("NO")) << endl #define bit_c(x) __builtin_popcountll(x) inline void logger() { std::cout << " [LOGGER] " << endl; } template <typename A, typename... B> void logger(const A &a, const B &...b) { cout << a << " , "; logger(b...); } typedef pair<lint, lint> P; const lint MOD = 1000000007; const lint MOD9 = 998244353; const lint INF = MOD * MOD; const int MAX = 200005; /* ...o(^-^)o... */ vector<int> to[MAX]; bool seen[MAX]; int dfs(int s) { seen[s] = true; int tmp = 1; for (auto t : to[s]) { if (seen[t]) continue; tmp += dfs(t); } return tmp; } int main() { int n, m; cin >> n >> m; rep(i, m) { int a, b; cin >> a >> b; a--; b--; to[a].push_back(b); to[b].push_back(a); } int ans = 0; rep(i, n) { if (seen[i]) continue; seen[i] = true; int connect = dfs(i); ans = max(connect, ans); } out(ans); }
replace
39
40
39
40
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> #include <cstdio> #include <map> #include <math.h> #include <queue> #include <set> using namespace std; using ll = long long; ll find(ll x, vector<ll> &par) { if (par.at(x) == x) { return x; } else { return par.at(x) = find(par.at(x), par); } } int main() { ll N, M; cin >> N >> M; vector<ll> A(M), B(M); vector<ll> par(N), rank(N), size(N); for (ll i = 0; i < N; i++) { par.at(i) = i; rank.at(i) = 0; size.at(i) = 1; } for (ll i = 0; i < M; i++) { cin >> A.at(i) >> B.at(i); ll x = find(A.at(i), par); ll y = find(B.at(i), par); if (x != y) { if (rank.at(x) < rank.at(y)) { par.at(x) = par.at(y); size.at(x) += size.at(y); size.at(y) = size.at(x); } else { par.at(y) = par.at(x); if (rank.at(x) == rank.at(y)) rank.at(x)++; size.at(x) += size.at(y); size.at(y) = size.at(x); } } } ll maxsize = 0; for (ll i = 0; i < N; i++) { ll x = find(i, par); ll a = size.at(x); if (a > maxsize) maxsize = a; } cout << maxsize; }
#include <bits/stdc++.h> #include <cstdio> #include <map> #include <math.h> #include <queue> #include <set> using namespace std; using ll = long long; ll find(ll x, vector<ll> &par) { if (par.at(x) == x) { return x; } else { return par.at(x) = find(par.at(x), par); } } int main() { ll N, M; cin >> N >> M; vector<ll> A(M), B(M); vector<ll> par(N), rank(N), size(N); for (ll i = 0; i < N; i++) { par.at(i) = i; rank.at(i) = 0; size.at(i) = 1; } for (ll i = 0; i < M; i++) { cin >> A.at(i) >> B.at(i); ll x = find(A.at(i) - 1, par); ll y = find(B.at(i) - 1, par); if (x != y) { if (rank.at(x) < rank.at(y)) { par.at(x) = par.at(y); size.at(x) += size.at(y); size.at(y) = size.at(x); } else { par.at(y) = par.at(x); if (rank.at(x) == rank.at(y)) rank.at(x)++; size.at(x) += size.at(y); size.at(y) = size.at(x); } } } ll maxsize = 0; for (ll i = 0; i < N; i++) { ll x = find(i, par); ll a = size.at(x); if (a > maxsize) maxsize = a; } cout << maxsize; }
replace
31
33
31
33
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)
p02573
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 vs = vector<string>; using vb = vector<bool>; using pll = pair<ll, ll>; using vpll = vector<pll>; const ll oo = 0x3f3f3f3f3f3f3f3fLL; const double eps = 1e-9; #define sz(c) ll((c).size()) #define all(c) begin(c), end(c) #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back #define xx first #define yy second #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--) #define TR(X) \ ({ \ if (1) \ cerr << "TR: " << (#X) << " = " << (X) << endl; \ }) vvl adj; int main() { cin.sync_with_stdio(0); ll N, M; cin >> N >> M; adj.resize(N); FOR(i, 0, M) { ll a, b; cin >> a >> b; a--; b--; if (count(all(adj[a]), b)) { continue; } adj[a].pb(b); adj[b].pb(a); } ll largest = 0; vb visited(N); FOR(i, 0, N) { queue<ll> q; q.push(i); ll count = 0; while (sz(q)) { ll cur = q.front(); q.pop(); if (visited[cur]) { continue; } visited[cur] = true; count++; for (ll neigh : adj[cur]) { q.push(neigh); } } largest = max(largest, count); } cout << largest << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; using vvl = vector<vl>; using vs = vector<string>; using vb = vector<bool>; using pll = pair<ll, ll>; using vpll = vector<pll>; const ll oo = 0x3f3f3f3f3f3f3f3fLL; const double eps = 1e-9; #define sz(c) ll((c).size()) #define all(c) begin(c), end(c) #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back #define xx first #define yy second #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--) #define TR(X) \ ({ \ if (1) \ cerr << "TR: " << (#X) << " = " << (X) << endl; \ }) vvl adj; int main() { cin.sync_with_stdio(0); ll N, M; cin >> N >> M; adj.resize(N); FOR(i, 0, M) { ll a, b; cin >> a >> b; a--; b--; adj[a].pb(b); adj[b].pb(a); } ll largest = 0; vb visited(N); FOR(i, 0, N) { queue<ll> q; q.push(i); ll count = 0; while (sz(q)) { ll cur = q.front(); q.pop(); if (visited[cur]) { continue; } visited[cur] = true; count++; for (ll neigh : adj[cur]) { q.push(neigh); } } largest = max(largest, count); } cout << largest << endl; }
delete
44
48
44
44
TLE
p02573
C++
Runtime Error
#include <iostream> using namespace std; const int maN = 1e5; int parent[maN]; int sz[maN]; void make_set(int v) { parent[v] = v; } int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void union_sets(int a, int b) { int u = find_set(a); int v = find_set(b); if (u != v) { if (sz[u] < sz[v]) { // swap(u, v); parent[u] = v; sz[v] += sz[u]; } else { parent[v] = u; sz[u] += sz[v]; } } } int main() { int n, m; cin >> n >> m; for (int i = 0; i <= n; ++i) { parent[i] = i; sz[i] = 1; } for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; --a, --b; union_sets(a, b); } int max_set = 1; for (int i = 0; i < n; ++i) { // cout << sz[i] << " "; if (max_set < sz[i]) max_set = sz[i]; } cout << max_set; return 0; }
#include <iostream> using namespace std; const int maN = 2e5 + 5; int parent[maN]; int sz[maN]; void make_set(int v) { parent[v] = v; } int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void union_sets(int a, int b) { int u = find_set(a); int v = find_set(b); if (u != v) { if (sz[u] < sz[v]) { // swap(u, v); parent[u] = v; sz[v] += sz[u]; } else { parent[v] = u; sz[u] += sz[v]; } } } int main() { int n, m; cin >> n >> m; for (int i = 0; i <= n; ++i) { parent[i] = i; sz[i] = 1; } for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; --a, --b; union_sets(a, b); } int max_set = 1; for (int i = 0; i < n; ++i) { // cout << sz[i] << " "; if (max_set < sz[i]) max_set = sz[i]; } cout << max_set; return 0; }
replace
2
3
2
3
0
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; multimap<int, int> relation; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; bool flg = true; auto p = relation.equal_range(a); for (auto it = p.first; it != p.second; ++it) { if (it->second == b) { flg = false; break; } } if (flg) { relation.emplace(a, b); relation.emplace(b, a); } } // 探索する。 vector<int> visit(n + 1, -1); int max_count = 1; for (int i = 1; i <= n; i++) { int cnt_wk = 0; auto p = relation.count(i); // cout<<"======"<<endl; // cout<<endl; // cout<<"i="<<i<<endl; // cout<<"p="<<p<<endl; // cout<<"visit="<<visit.at(i)<<endl; if (p != 0 && visit.at(i) == -1) { // 空では無く未訪問の場合 // cout<<"--"<<endl; queue<int> que; que.push(i); // iからスタート // BFS開始(キューが空になるまで探索を行う) while (!que.empty()) { int v = que.front(); // cout<<"v="<<v<<endl; que.pop(); visit.at(v) = 0; // 訪問済みにする。 cnt_wk++; // vからたどれるところを調べる。 auto p = relation.equal_range(v); for (auto it = p.first; it != p.second; ++it) { if (visit[it->second] != -1) continue; visit[it->second] = 0; que.push(it->second); } } max_count = max(max_count, cnt_wk); } } cout << max_count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; multimap<int, int> relation; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; // bool flg=true; // auto p = relation.equal_range(a); // for (auto it = p.first; it != p.second; ++it) { // if(it->second==b){ // flg=false; // break; // } // } // if(flg){ relation.emplace(a, b); relation.emplace(b, a); // } } // 探索する。 vector<int> visit(n + 1, -1); int max_count = 1; for (int i = 1; i <= n; i++) { int cnt_wk = 0; auto p = relation.count(i); // cout<<"======"<<endl; // cout<<endl; // cout<<"i="<<i<<endl; // cout<<"p="<<p<<endl; // cout<<"visit="<<visit.at(i)<<endl; if (p != 0 && visit.at(i) == -1) { // 空では無く未訪問の場合 // cout<<"--"<<endl; queue<int> que; que.push(i); // iからスタート // BFS開始(キューが空になるまで探索を行う) while (!que.empty()) { int v = que.front(); // cout<<"v="<<v<<endl; que.pop(); visit.at(v) = 0; // 訪問済みにする。 cnt_wk++; // vからたどれるところを調べる。 auto p = relation.equal_range(v); for (auto it = p.first; it != p.second; ++it) { if (visit[it->second] != -1) continue; visit[it->second] = 0; que.push(it->second); } } max_count = max(max_count, cnt_wk); } } cout << max_count << endl; return 0; }
replace
13
25
13
25
TLE
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int bfs(int s, vector<vector<int>> &adj, vector<int> visited) { queue<int> q; q.push(s); visited[s] = 1; int size = 1; while (!q.empty()) { int t = q.front(); q.pop(); for (auto x : adj[t]) { if (visited[x] == 0) { q.push(x); visited[x] = 1; size++; } } } return size; } void solve() { int n, m; cin >> n >> m; vector<vector<int>> adj(n + 1); for (int i = 0; i < m; i++) { int l, r; cin >> l >> r; // cout<<l<<r ; adj[l].push_back(r); adj[r].push_back(l); } vector<int> visited(n + 1); int res = 0; for (int i = 1; i <= n; i++) { if (visited[i] == 0) { int answer = bfs(i, adj, visited); res = max(res, answer); } } cout << res; } int main() { int y; y = 1; // cin>>y ; while (y--) { solve(); } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int bfs(int s, vector<vector<int>> &adj, vector<int> &visited) { queue<int> q; q.push(s); visited[s] = 1; int size = 1; while (!q.empty()) { int t = q.front(); q.pop(); for (auto x : adj[t]) { if (visited[x] == 0) { q.push(x); visited[x] = 1; size++; } } } return size; } void solve() { int n, m; cin >> n >> m; vector<vector<int>> adj(n + 1); for (int i = 0; i < m; i++) { int l, r; cin >> l >> r; // cout<<l<<r ; adj[l].push_back(r); adj[r].push_back(l); } vector<int> visited(n + 1); int res = 0; for (int i = 1; i <= n; i++) { if (visited[i] == 0) { int answer = bfs(i, adj, visited); res = max(res, answer); } } cout << res; } int main() { int y; y = 1; // cin>>y ; while (y--) { solve(); } }
replace
4
5
4
5
TLE
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<int, ll> pil; typedef pair<ll, int> pli; #define Fi first #define Se second #define _Out(a) cerr << #a << " = " << (a) << endl const int INF = 0x3f3f3f3f, MAXN = 1e3 + 7; const ll LINF = 0x3f3f3f3f3f3f3f3f, MOD = 1e9 + 7; const db Pi = acos(-1), EPS = 1e-6; void test() { cerr << "\n"; } template <typename T, typename... Args> void test(T x, Args... args) { cerr << x << " "; test(args...); } inline ll qpow(ll a, ll b) { return b ? ((b & 1) ? a * qpow(a * a % MOD, b >> 1) % MOD : qpow(a * a % MOD, b >> 1)) % MOD : 1; } inline ll qpow(ll a, ll b, ll c) { return b ? ((b & 1) ? a * qpow(a * a % c, b >> 1, c) % c : qpow(a * a % c, b >> 1, c)) % c : 1; } inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll cede(ll a, ll b) { if (b < 0) return cede(-a, -b); if (a < 0) return a / b; return (a + b - 1) / b; } inline ll flde(ll a, ll b) { if (b < 0) return flde(-a, -b); if (a < 0) return (a - b + 1) / b; return a / b; } inline int sign(db x) { return x < -EPS ? -1 : x > EPS; } inline int dbcmp(db l, db r) { return sign(l - r); } namespace Fast_IO { // orz laofu const int MAXL((1 << 18) + 1); int iof, iotp; char ioif[MAXL], *ioiS, *ioiT, ioof[MAXL], *iooS = ioof, *iooT = ioof + MAXL - 1, ioc, iost[55]; char Getchar() { if (ioiS == ioiT) { ioiS = ioif; ioiT = ioiS + fread(ioif, 1, MAXL, stdin); return (ioiS == ioiT ? EOF : *ioiS++); } else return (*ioiS++); } void Write() { fwrite(ioof, 1, iooS - ioof, stdout); iooS = ioof; } void Putchar(char x) { *iooS++ = x; if (iooS == iooT) Write(); } inline int read() { int x = 0; for (iof = 1, ioc = Getchar(); ioc < '0' || ioc > '9';) iof = ioc == '-' ? -1 : 1, ioc = Getchar(); for (x = 0; ioc <= '9' && ioc >= '0'; ioc = Getchar()) x = (x << 3) + (x << 1) + (ioc ^ 48); return x * iof; } inline long long read_ll() { long long x = 0; for (iof = 1, ioc = Getchar(); ioc < '0' || ioc > '9';) iof = ioc == '-' ? -1 : 1, ioc = Getchar(); for (x = 0; ioc <= '9' && ioc >= '0'; ioc = Getchar()) x = (x << 3) + (x << 1) + (ioc ^ 48); return x * iof; } template <class Int> void Print(Int x, char ch = '\0') { if (!x) Putchar('0'); if (x < 0) Putchar('-'), x = -x; while (x) iost[++iotp] = x % 10 + '0', x /= 10; while (iotp) Putchar(iost[iotp--]); if (ch) Putchar(ch); } void Getstr(char *s, int &l) { for (ioc = Getchar(); ioc < 'a' || ioc > 'z';) ioc = Getchar(); for (l = 0; ioc <= 'z' && ioc >= 'a'; ioc = Getchar()) s[l++] = ioc; s[l] = 0; } void Putstr(const char *s) { for (int i = 0, n = strlen(s); i < n; ++i) Putchar(s[i]); } } // namespace Fast_IO using namespace Fast_IO; int fa[MAXN], siz[MAXN]; int fifa(int x) { return fa[x] == x ? x : fa[x] = fifa(fa[x]); } void work() { int n = read(), m = read(); for (int i = 1; i <= n; i++) fa[i] = i, siz[i] = 1; int ans = 1; for (int i = 1; i <= m; i++) { int x = read(), y = read(); int fx = fifa(x), fy = fifa(y); if (fx != fy) { siz[fy] += siz[fx]; ans = max(ans, siz[fy]); fa[fx] = fy; } } printf("%d\n", ans); } int main() { // std::ios::sync_with_stdio(false); // int T=read();for(int cas=1;cas<=T;cas++) // int T;scanf("%d",&T);for(int i=1;i<=T;i++) work(); // Write(); } /* 3 6 9 2 1 1 1 4 1 3 3 6 9 2 1 1 1 5 1 4 3 6 9 2 1 1 1 5 1 5 3 6 9 2 1 1 1 8 1 6 3 6 9 2 1 1 1 8 1 7 4 5 6 4 1 1 4 3 999 1 10 10 10 4 1 1 3 7 999 1 100 10 10 4 1 1 8 9 999 1 100 */
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<int, ll> pil; typedef pair<ll, int> pli; #define Fi first #define Se second #define _Out(a) cerr << #a << " = " << (a) << endl const int INF = 0x3f3f3f3f, MAXN = 3e5 + 7; const ll LINF = 0x3f3f3f3f3f3f3f3f, MOD = 1e9 + 7; const db Pi = acos(-1), EPS = 1e-6; void test() { cerr << "\n"; } template <typename T, typename... Args> void test(T x, Args... args) { cerr << x << " "; test(args...); } inline ll qpow(ll a, ll b) { return b ? ((b & 1) ? a * qpow(a * a % MOD, b >> 1) % MOD : qpow(a * a % MOD, b >> 1)) % MOD : 1; } inline ll qpow(ll a, ll b, ll c) { return b ? ((b & 1) ? a * qpow(a * a % c, b >> 1, c) % c : qpow(a * a % c, b >> 1, c)) % c : 1; } inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll cede(ll a, ll b) { if (b < 0) return cede(-a, -b); if (a < 0) return a / b; return (a + b - 1) / b; } inline ll flde(ll a, ll b) { if (b < 0) return flde(-a, -b); if (a < 0) return (a - b + 1) / b; return a / b; } inline int sign(db x) { return x < -EPS ? -1 : x > EPS; } inline int dbcmp(db l, db r) { return sign(l - r); } namespace Fast_IO { // orz laofu const int MAXL((1 << 18) + 1); int iof, iotp; char ioif[MAXL], *ioiS, *ioiT, ioof[MAXL], *iooS = ioof, *iooT = ioof + MAXL - 1, ioc, iost[55]; char Getchar() { if (ioiS == ioiT) { ioiS = ioif; ioiT = ioiS + fread(ioif, 1, MAXL, stdin); return (ioiS == ioiT ? EOF : *ioiS++); } else return (*ioiS++); } void Write() { fwrite(ioof, 1, iooS - ioof, stdout); iooS = ioof; } void Putchar(char x) { *iooS++ = x; if (iooS == iooT) Write(); } inline int read() { int x = 0; for (iof = 1, ioc = Getchar(); ioc < '0' || ioc > '9';) iof = ioc == '-' ? -1 : 1, ioc = Getchar(); for (x = 0; ioc <= '9' && ioc >= '0'; ioc = Getchar()) x = (x << 3) + (x << 1) + (ioc ^ 48); return x * iof; } inline long long read_ll() { long long x = 0; for (iof = 1, ioc = Getchar(); ioc < '0' || ioc > '9';) iof = ioc == '-' ? -1 : 1, ioc = Getchar(); for (x = 0; ioc <= '9' && ioc >= '0'; ioc = Getchar()) x = (x << 3) + (x << 1) + (ioc ^ 48); return x * iof; } template <class Int> void Print(Int x, char ch = '\0') { if (!x) Putchar('0'); if (x < 0) Putchar('-'), x = -x; while (x) iost[++iotp] = x % 10 + '0', x /= 10; while (iotp) Putchar(iost[iotp--]); if (ch) Putchar(ch); } void Getstr(char *s, int &l) { for (ioc = Getchar(); ioc < 'a' || ioc > 'z';) ioc = Getchar(); for (l = 0; ioc <= 'z' && ioc >= 'a'; ioc = Getchar()) s[l++] = ioc; s[l] = 0; } void Putstr(const char *s) { for (int i = 0, n = strlen(s); i < n; ++i) Putchar(s[i]); } } // namespace Fast_IO using namespace Fast_IO; int fa[MAXN], siz[MAXN]; int fifa(int x) { return fa[x] == x ? x : fa[x] = fifa(fa[x]); } void work() { int n = read(), m = read(); for (int i = 1; i <= n; i++) fa[i] = i, siz[i] = 1; int ans = 1; for (int i = 1; i <= m; i++) { int x = read(), y = read(); int fx = fifa(x), fy = fifa(y); if (fx != fy) { siz[fy] += siz[fx]; ans = max(ans, siz[fy]); fa[fx] = fy; } } printf("%d\n", ans); } int main() { // std::ios::sync_with_stdio(false); // int T=read();for(int cas=1;cas<=T;cas++) // int T;scanf("%d",&T);for(int i=1;i<=T;i++) work(); // Write(); } /* 3 6 9 2 1 1 1 4 1 3 3 6 9 2 1 1 1 5 1 4 3 6 9 2 1 1 1 5 1 5 3 6 9 2 1 1 1 8 1 6 3 6 9 2 1 1 1 8 1 7 4 5 6 4 1 1 4 3 999 1 10 10 10 4 1 1 3 7 999 1 100 10 10 4 1 1 8 9 999 1 100 */
replace
11
12
11
12
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int MAX_N = 1e5 + 5; const int MAX_L = 20; // ~ Log N const long long MOD = 1e9 + 7; const long long INF = 1e9 + 7; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<vi> vvi; #define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl #define LSOne(S) (S & (-S)) #define isBitSet(S, i) ((S >> i) & 1) void add_self(int &a, int b) { a += b; a %= MOD; } int parent[MAX_N], sz[MAX_N]; void make_set(int v) { parent[v] = v; sz[v] = 1; } int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (a != b) { if (sz[a] < sz[b]) swap(a, b); parent[b] = a; sz[a] += sz[b]; } } void solve() { int n, m; cin >> n >> m; map<int, int> mp; for (int i = 0; i < n; i++) make_set(i + 1); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; union_sets(a, b); } int ans = 1; unordered_map<int, int> m2; for (int i = 1; i <= n; i++) { m2[find_set(i)]++; // if(mp.find(i)!=mp.end()) ans = max(ans, m2[find_set(i)]); } cout << ans << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int tc = 1; // cin >> tc; for (int t = 1; t <= tc; t++) { // cout << "Case #" << t << ": "; solve(); } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int MAX_N = 2e5 + 5; const int MAX_L = 20; // ~ Log N const long long MOD = 1e9 + 7; const long long INF = 1e9 + 7; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<vi> vvi; #define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl #define LSOne(S) (S & (-S)) #define isBitSet(S, i) ((S >> i) & 1) void add_self(int &a, int b) { a += b; a %= MOD; } int parent[MAX_N], sz[MAX_N]; void make_set(int v) { parent[v] = v; sz[v] = 1; } int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (a != b) { if (sz[a] < sz[b]) swap(a, b); parent[b] = a; sz[a] += sz[b]; } } void solve() { int n, m; cin >> n >> m; map<int, int> mp; for (int i = 0; i < n; i++) make_set(i + 1); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; union_sets(a, b); } int ans = 1; unordered_map<int, int> m2; for (int i = 1; i <= n; i++) { m2[find_set(i)]++; // if(mp.find(i)!=mp.end()) ans = max(ans, m2[find_set(i)]); } cout << ans << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int tc = 1; // cin >> tc; for (int t = 1; t <= tc; t++) { // cout << "Case #" << t << ": "; solve(); } }
replace
11
12
11
12
0
p02573
C++
Runtime Error
/* ID: Bipin Singh [bipinsingh061] LANG: C++ TASK: gift1 */ #include <bits/stdc++.h> using namespace std; #define deb(x) cout << "\n" << (#x) << " = " << (x) << "\n" #define int long long int void inputoutput() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } void dfs(int src, bool *vis, vector<int> v[], int &ans) { vis[src] = true; // cout<<src<<" "; ++ans; for (auto it : v[src]) { if (!vis[it]) dfs(it, vis, v, ans); } } int mod = 1e9 + 7; void update(vector<int> &D, int l, int r, int x) { D[l] += x; D[r + 1] -= x; } int32_t main() { inputoutput(); int n, m; cin >> n; cin >> m; vector<int> v[200000]; bool vis[200000]; memset(vis, false, sizeof(vis)); for (int i = 1; i <= m; ++i) { int a, b; cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } // for(int i=1 ; i<=n ; ++i) // { // cout<<i<<"->"; // for(auto it : v[i]) // cout<<it<<" "; // cout<<"\n"; // } int comp = 0; // unordered_set<int> result; int sol = INT_MIN; for (int i = 1; i <= n; ++i) { if (!vis[i]) { int ans = 0; dfs(i, vis, v, ans); sol = max(sol, ans); ++comp; } } cout << sol; return 0; }
/* ID: Bipin Singh [bipinsingh061] LANG: C++ TASK: gift1 */ #include <bits/stdc++.h> using namespace std; #define deb(x) cout << "\n" << (#x) << " = " << (x) << "\n" #define int long long int void inputoutput() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } void dfs(int src, bool *vis, vector<int> v[], int &ans) { vis[src] = true; // cout<<src<<" "; ++ans; for (auto it : v[src]) { if (!vis[it]) dfs(it, vis, v, ans); } } int mod = 1e9 + 7; void update(vector<int> &D, int l, int r, int x) { D[l] += x; D[r + 1] -= x; } int32_t main() { inputoutput(); int n, m; cin >> n; cin >> m; vector<int> v[200500]; bool vis[200500]; memset(vis, false, sizeof(vis)); for (int i = 1; i <= m; ++i) { int a, b; cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } // for(int i=1 ; i<=n ; ++i) // { // cout<<i<<"->"; // for(auto it : v[i]) // cout<<it<<" "; // cout<<"\n"; // } int comp = 0; // unordered_set<int> result; int sol = INT_MIN; for (int i = 1; i <= n; ++i) { if (!vis[i]) { int ans = 0; dfs(i, vis, v, ans); sol = max(sol, ans); ++comp; } } cout << sol; return 0; }
replace
45
47
45
47
0
p02573
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; class UnionFind { public: UnionFind(int &n) { r = vector<int>(n + 1, -1); } int findRoot(int x) { if (r[x] < 0) return x; else r[x] = findRoot(r[x]); } void unite(int &x, int &y) { x = findRoot(x); y = findRoot(y); if (x == y) return; if (r[x] > r[y]) swap(x, y); r[x] += r[y]; r[y] = x; return; } int size(int &x) { return -r[findRoot(x)]; } private: vector<int> r; }; int main() { int n, m, a, b; cin >> n >> m; UnionFind uf(n); for (int i = 0; i < m; ++i) { cin >> a >> b; uf.unite(a, b); } int ans = 0; for (int i = 1; i <= n; ++i) ans = max(ans, uf.size(i)); cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; class UnionFind { public: UnionFind(int &n) { r = vector<int>(n + 1, -1); } int findRoot(int x) { if (r[x] < 0) return x; return findRoot(r[x]); } void unite(int &x, int &y) { x = findRoot(x); y = findRoot(y); if (x == y) return; if (r[x] > r[y]) swap(x, y); r[x] += r[y]; r[y] = x; return; } int size(int &x) { return -r[findRoot(x)]; } private: vector<int> r; }; int main() { int n, m, a, b; cin >> n >> m; UnionFind uf(n); for (int i = 0; i < m; ++i) { cin >> a >> b; uf.unite(a, b); } int ans = 0; for (int i = 1; i <= n; ++i) ans = max(ans, uf.size(i)); cout << ans << endl; return 0; }
replace
17
19
17
18
-11
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long #define ALL(x) x.begin(), x.end() #define MOD (1000000000 + 7) using namespace std; #define PI 3.14159265359 #define tMOD 998244353 #define mkpr(x, y) make_pair(x, y) int N, M; int v[200400]; int vs[203000] = {0}; int root(int i) { if (v[i] == i) { return i; } else { return root(v[i]); } } int margego(int tibi, int deka) { int rtibi = root(tibi), rdeka = root(deka); if (rtibi == rdeka) { return 0; } else { if (vs[rtibi] > vs[rdeka]) swap(rtibi, rdeka); vs[rtibi] = vs[rdeka] + vs[rtibi]; v[rdeka] = rtibi; } return 0; } int main() { cin >> N >> M; for (int i = 0; i < N; i++) { v[i] = i; vs[i] = 1; } for (int i = 0; i < M; i++) { int tmp, tmp1; cin >> tmp >> tmp1; margego(tmp - 1, tmp1 - 1); } int ans = 0; for (int i = 0; i < N; i++) { ans = max(ans, vs[i]); } cout << ans << endl; }
#include <bits/stdc++.h> #define ll long long #define ALL(x) x.begin(), x.end() #define MOD (1000000000 + 7) using namespace std; #define PI 3.14159265359 #define tMOD 998244353 #define mkpr(x, y) make_pair(x, y) int N, M; int v[200400]; int vs[203000] = {0}; int root(int i) { if (v[i] == i) { return i; } else { return root(v[i]); } } int margego(int tibi, int deka) { int rtibi = root(tibi), rdeka = root(deka); if (rtibi == rdeka) { return 0; } else { if (vs[rtibi] < vs[rdeka]) swap(rtibi, rdeka); vs[rtibi] = vs[rdeka] + vs[rtibi]; v[rdeka] = rtibi; } return 0; } int main() { cin >> N >> M; for (int i = 0; i < N; i++) { v[i] = i; vs[i] = 1; } for (int i = 0; i < M; i++) { int tmp, tmp1; cin >> tmp >> tmp1; margego(tmp - 1, tmp1 - 1); } int ans = 0; for (int i = 0; i < N; i++) { ans = max(ans, vs[i]); } cout << ans << endl; }
replace
25
26
25
26
TLE
p02573
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; class Group { public: vector<int> root; int maxSize = -1; Group(int n) { root = vector<int>(n, -1); } int getRoot(int c) { return root[c] < 0 == c ? c : getRoot(root[c]); } void merge(int a, int b) { int rootA = getRoot(a); int rootB = getRoot(b); if (rootA != rootB) { root[rootA] += root[rootB]; root[rootB] = rootA; maxSize = root[rootA] < maxSize ? root[rootA] : maxSize; } } int getMax() { return -maxSize; } }; int main() { int n, m; cin >> n >> m; Group group(n); int a, b; for (int i = 0; i < m; i++) { cin >> a >> b; group.merge(--a, --b); } cout << group.getMax(); return 0; }
#include <iostream> #include <vector> using namespace std; class Group { public: vector<int> root; int maxSize = -1; Group(int n) { root = vector<int>(n, -1); } int getRoot(int c) { return root[c] < 0 ? c : root[c] = getRoot(root[c]); } void merge(int a, int b) { int rootA = getRoot(a); int rootB = getRoot(b); if (rootA != rootB) { root[rootA] += root[rootB]; root[rootB] = rootA; maxSize = root[rootA] < maxSize ? root[rootA] : maxSize; } } int getMax() { return -maxSize; } }; int main() { int n, m; cin >> n >> m; Group group(n); int a, b; for (int i = 0; i < m; i++) { cin >> a >> b; group.merge(--a, --b); } cout << group.getMax(); return 0; }
replace
12
13
12
13
TLE
p02573
C++
Runtime Error
#include <iostream> #include <queue> #include <vector> using namespace std; bool t[100]; vector<int> e[100]; int dfs(int v) { int y = 1; t[v] = true; for (int i = 0; i < e[v].size(); i++) { int u = e[v][i]; if (!t[u]) { y += dfs(u); } } return y; } int main() { int n; int m; cin >> n; cin >> m; for (int i = 0; i < m; i++) { int a; int b; cin >> a; cin >> b; a--; b--; e[a].push_back(b); e[b].push_back(a); } int ans = 0; for (int i = 0; i < n; i++) { if (!t[i]) { int x = dfs(i); ans = max(ans, x); } } cout << ans; return 0; }
#include <iostream> #include <queue> #include <vector> using namespace std; bool t[200010]; vector<int> e[200010]; int dfs(int v) { int y = 1; t[v] = true; for (int i = 0; i < e[v].size(); i++) { int u = e[v][i]; if (!t[u]) { y += dfs(u); } } return y; } int main() { int n; int m; cin >> n; cin >> m; for (int i = 0; i < m; i++) { int a; int b; cin >> a; cin >> b; a--; b--; e[a].push_back(b); e[b].push_back(a); } int ans = 0; for (int i = 0; i < n; i++) { if (!t[i]) { int x = dfs(i); ans = max(ans, x); } } cout << ans; return 0; }
replace
4
6
4
6
0
p02574
C++
Time Limit Exceeded
#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; std::vector<int> Eratosthenes(const int N) { std::vector<bool> is_prime(N + 1); for (int i = 0; i <= N; i++) { is_prime[i] = true; } std::vector<int> P; for (int i = 2; i <= N; i++) { if (is_prime[i]) { for (int j = 2 * i; j <= N; j += i) { is_prime[j] = false; } P.emplace_back(i); } } return P; } int main() { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; bool ok1 = true, ok2 = true; // 2 int g = __gcd(a[0], a[1]); rep(i, n) g = __gcd(g, a[i]); if (g != 1) ok2 = false; // 1 set<int> se; vector<int> e = Eratosthenes(1000005); rep(i, n) { set<int> cnt; rep(j, e.size()) { while (a[i] % e[j] == 0) { a[i] /= e[j]; cnt.insert(e[j]); } } if (a[i] != 1) cnt.insert(a[i]); for (auto &p : cnt) { if (se.find(p) != se.end()) ok1 = false; se.insert(p); } } if (ok1) { cout << "pairwise coprime" << endl; return 0; } if (ok2) { cout << "setwise coprime" << endl; return 0; } cout << "not coprime" << endl; }
#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; std::vector<int> Eratosthenes(const int N) { std::vector<bool> is_prime(N + 1); for (int i = 0; i <= N; i++) { is_prime[i] = true; } std::vector<int> P; for (int i = 2; i <= N; i++) { if (is_prime[i]) { for (int j = 2 * i; j <= N; j += i) { is_prime[j] = false; } P.emplace_back(i); } } return P; } int main() { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; bool ok1 = true, ok2 = true; // 2 int g = __gcd(a[0], a[1]); rep(i, n) g = __gcd(g, a[i]); if (g != 1) ok2 = false; // 1 set<int> se; vector<int> e = Eratosthenes(1000005); rep(i, n) { set<int> cnt; rep(j, e.size()) { if ((ll)e[j] * e[j] > a[i]) break; while (a[i] % e[j] == 0) { a[i] /= e[j]; cnt.insert(e[j]); } } if (a[i] != 1) cnt.insert(a[i]); for (auto &p : cnt) { if (se.find(p) != se.end()) ok1 = false; se.insert(p); } } if (ok1) { cout << "pairwise coprime" << endl; return 0; } if (ok2) { cout << "setwise coprime" << endl; return 0; } cout << "not coprime" << endl; }
insert
40
40
40
42
TLE
p02574
C++
Runtime Error
#include <bits/stdc++.h> #define sp putchar(' ') #define en putchar('\n') #define MOD(x) ((((x) % Mod) + Mod) % Mod) #define int64_t int const int MAXN = 500005; using namespace std; int n, m; int64_t a; bool isP[MAXN]; vector<int> primes; void getP() { memset(isP, true, sizeof(isP)); isP[0] = isP[1] = false; primes.clear(); for (int i = 2; i < MAXN; ++i) { if (!isP[i]) continue; primes.push_back(i); for (int j = 2; 1LL * j * i < MAXN; ++j) { isP[j * i] = false; } } } int factor[20][2]; int factCnt; int getFactor(int x) { factCnt = 0; for (int i = 0; primes[i] < x; ++i) { if (isP[x]) break; if (x % primes[i] == 0) { for (factor[factCnt][1] = 0; x % primes[i] == 0; x /= primes[i]) { ++factor[factCnt][1]; } factor[factCnt++][0] = primes[i]; } } if (x != 1) { factor[factCnt][1] = 1; factor[factCnt++][0] = x; } return factCnt; } unordered_set<int64_t> s; int main() { getP(); // getFactor(24) ; ios::sync_with_stdio(false); while (cin >> n) { s.clear(); int64_t gcds; bool isOk = true; for (int i = 1; i <= n; ++i) { cin >> a; getFactor(a); // cout << "factors of "<< a<<":" << endl ; // for(int i = 0;i < factCnt; ++i) { // cout << factor[i][0] << "," << factor[i][1] << endl ; // } gcds = (i == 1) ? a : __gcd(gcds, a); for (int j = 0; j < factCnt; ++j) { if (s.count(factor[j][0])) { isOk = false; break; } s.insert(factor[j][0]); } } if (isOk) { cout << "pairwise coprime" << endl; } else if (gcds == 1) { cout << "setwise coprime" << endl; } else { cout << "not coprime" << endl; } } }
#include <bits/stdc++.h> #define sp putchar(' ') #define en putchar('\n') #define MOD(x) ((((x) % Mod) + Mod) % Mod) #define int64_t int const int MAXN = 1000005; using namespace std; int n, m; int64_t a; bool isP[MAXN]; vector<int> primes; void getP() { memset(isP, true, sizeof(isP)); isP[0] = isP[1] = false; primes.clear(); for (int i = 2; i < MAXN; ++i) { if (!isP[i]) continue; primes.push_back(i); for (int j = 2; 1LL * j * i < MAXN; ++j) { isP[j * i] = false; } } } int factor[20][2]; int factCnt; int getFactor(int x) { factCnt = 0; for (int i = 0; primes[i] < x; ++i) { if (isP[x]) break; if (x % primes[i] == 0) { for (factor[factCnt][1] = 0; x % primes[i] == 0; x /= primes[i]) { ++factor[factCnt][1]; } factor[factCnt++][0] = primes[i]; } } if (x != 1) { factor[factCnt][1] = 1; factor[factCnt++][0] = x; } return factCnt; } unordered_set<int64_t> s; int main() { getP(); // getFactor(24) ; ios::sync_with_stdio(false); while (cin >> n) { s.clear(); int64_t gcds; bool isOk = true; for (int i = 1; i <= n; ++i) { cin >> a; getFactor(a); // cout << "factors of "<< a<<":" << endl ; // for(int i = 0;i < factCnt; ++i) { // cout << factor[i][0] << "," << factor[i][1] << endl ; // } gcds = (i == 1) ? a : __gcd(gcds, a); for (int j = 0; j < factCnt; ++j) { if (s.count(factor[j][0])) { isOk = false; break; } s.insert(factor[j][0]); } } if (isOk) { cout << "pairwise coprime" << endl; } else if (gcds == 1) { cout << "setwise coprime" << endl; } else { cout << "not coprime" << endl; } } }
replace
5
6
5
6
0
p02574
C++
Runtime Error
/// You just can't beat the person who never gives up /// ICPC next year // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int n, a[N]; int spf[N], vis[N], vid; bool is[N]; void sieve() { for (int i = 1; i < N; ++i) spf[i] = i; for (int i = 2; i * i < N; ++i) if (spf[i] == i) { for (int j = i * i; j < N; j += i) if (spf[j] == j) spf[j] = i; } } vector<int> factorize(int x) { vector<int> ret; ++vid; while (x != 1) { if (vis[spf[x]] != vid) ret.push_back(spf[x]); vis[spf[x]] = vid; x /= spf[x]; } return ret; } int x; bool Never_give_up() { sieve(); scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", a + i); x = __gcd(x, a[i]); } if (x != 1) return cout << "not coprime\n", 0; for (int i = n - 1; i >= 0; --i) { auto vec = factorize(a[i]); for (int j : vec) if (is[j]) return cout << "setwise coprime\n", 0; for (int j : vec) is[j] = 1; } cout << "pairwise coprime\n"; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // std::ios::sync_with_stdio(0); // cin.tie(0) ,cout.tie(0); int t = 1; // scanf("%d",&t); while (t--) { Never_give_up(); } return 0; }
/// You just can't beat the person who never gives up /// ICPC next year // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int n, a[N]; int spf[N], vis[N], vid; bool is[N]; void sieve() { for (int i = 1; i < N; ++i) spf[i] = i; for (int i = 2; i * i < N; ++i) if (spf[i] == i) { for (int j = i * i; j < N; j += i) if (spf[j] == j) spf[j] = i; } } vector<int> factorize(int x) { vector<int> ret; ++vid; while (x != 1) { if (vis[spf[x]] != vid) ret.push_back(spf[x]); vis[spf[x]] = vid; x /= spf[x]; } return ret; } int x; bool Never_give_up() { sieve(); scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", a + i); x = __gcd(x, a[i]); } if (x != 1) return cout << "not coprime\n", 0; for (int i = n - 1; i >= 0; --i) { auto vec = factorize(a[i]); for (int j : vec) if (is[j]) return cout << "setwise coprime\n", 0; for (int j : vec) is[j] = 1; } cout << "pairwise coprime\n"; return 0; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // std::ios::sync_with_stdio(0); // cin.tie(0) ,cout.tie(0); int t = 1; // scanf("%d",&t); while (t--) { Never_give_up(); } return 0; }
insert
53
53
53
54
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> using namespace std; // FILE *fi = freopen("1.txt", "r", stdin); // FILE *fo = freopen("1", "w", stdout); // FILE *fi = freopen("P.inp", "r", stdin); // FILE *fo = freopen("P.out", "w", stdout); bool used[1000001]; void bfs(int x) { queue<int> q; if (used[x]) return; q.push(x); used[x] = true; while (q.size()) { int u = q.front(); q.pop(); used[u] = true; u += x; if (!used[u] && u <= 1e6) q.push(u); } return; } int a[1000001]; int Min[1000001]; int main() { //------------------------------ // Faster ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //------------------------------ int N = 1e6; for (int i = 1; i <= N; i++) Min[i] = i; for (int i = 2; i <= sqrt(N); i++) { for (int j = i; j <= N; j += i) { Min[j] = min(Min[j], i); } } int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } bool ok = false; int G = 0; for (int i = n; i >= 1; i--) { G = __gcd(G, a[i]); if (a[i] == 1) continue; vector<int> U; while (a[i] > 1) { int x = Min[a[i]]; if (used[x]) { ok = true; } U.push_back(x); a[i] /= x; } for (auto x : U) bfs(x); } if (ok == false) { cout << "pairwise coprime"; } else if (ok == true && G == 1) { cout << "setwise coprime"; } else { cout << "not coprime"; } return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; // FILE *fi = freopen("1.txt", "r", stdin); // FILE *fo = freopen("1", "w", stdout); // FILE *fi = freopen("P.inp", "r", stdin); // FILE *fo = freopen("P.out", "w", stdout); bool used[1000001]; void bfs(int x) { queue<int> q; if (used[x]) return; q.push(x); used[x] = true; while (q.size()) { int u = q.front(); q.pop(); used[u] = true; u += x; if (u <= 1e6 && !used[u]) q.push(u); } return; } int a[1000001]; int Min[1000001]; int main() { //------------------------------ // Faster ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //------------------------------ int N = 1e6; for (int i = 1; i <= N; i++) Min[i] = i; for (int i = 2; i <= sqrt(N); i++) { for (int j = i; j <= N; j += i) { Min[j] = min(Min[j], i); } } int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } bool ok = false; int G = 0; for (int i = n; i >= 1; i--) { G = __gcd(G, a[i]); if (a[i] == 1) continue; vector<int> U; while (a[i] > 1) { int x = Min[a[i]]; if (used[x]) { ok = true; } U.push_back(x); a[i] /= x; } for (auto x : U) bfs(x); } if (ok == false) { cout << "pairwise coprime"; } else if (ok == true && G == 1) { cout << "setwise coprime"; } else { cout << "not coprime"; } return 0; }
replace
19
20
19
20
0
p02574
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long #define MODV 1000000007 #define INFLL LLONG_MAX // 9223372036854775807 #define EPS 1e-9 #define rep(i, n) for (ll i = 0, i##_len = (ll)(n); i < i##_len; i++) #define repf(i, n) for (ll i = 1, i##_len = (ll)(n + 1); i < i##_len; i++) #define all(v) v.begin(), v.end() #define endl "\n" #define vi vector<ll> #define vvi vector<vector<ll>> #define Yes() cout << "Yes" << endl #define YES() cout << "YES" << endl #define No() cout << "No" << endl #define NO() cout << "NO" << endl #define Init() \ std::ios::sync_with_stdio(false); \ std::cin.tie(0); \ std::cout << fixed << setprecision(15); template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } using namespace std; // 約数列挙:nの約数を昇順に返す。 vector<long long> enumDivisors(long long n) { vector<long long> ret; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (n / i != i) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); return ret; } int main() { Init(); ll n; cin >> n; ll allGcd = -1; vi a(n); rep(i, n) { cin >> a[i]; if (i == 0) allGcd = a[i]; else allGcd = __gcd(allGcd, a[i]); } vector<bool> used(1000001, false); bool pc = true; rep(i, n) { auto eDiv = enumDivisors(a[i]); for (auto &num : eDiv) { if (num <= 1) continue; if (used[num]) { pc = false; break; } else { used[num] = true; } if (!pc) break; } } if (pc) cout << "pairwise coprime" << endl; else if (!pc && allGcd == 1) cout << "setwise coprime" << endl; else cout << "not coprime" << endl; }
#include <bits/stdc++.h> #define ll long long #define MODV 1000000007 #define INFLL LLONG_MAX // 9223372036854775807 #define EPS 1e-9 #define rep(i, n) for (ll i = 0, i##_len = (ll)(n); i < i##_len; i++) #define repf(i, n) for (ll i = 1, i##_len = (ll)(n + 1); i < i##_len; i++) #define all(v) v.begin(), v.end() #define endl "\n" #define vi vector<ll> #define vvi vector<vector<ll>> #define Yes() cout << "Yes" << endl #define YES() cout << "YES" << endl #define No() cout << "No" << endl #define NO() cout << "NO" << endl #define Init() \ std::ios::sync_with_stdio(false); \ std::cin.tie(0); \ std::cout << fixed << setprecision(15); template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } using namespace std; // 約数列挙:nの約数を昇順に返す。 vector<long long> enumDivisors(long long n) { vector<long long> ret; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (n / i != i) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); return ret; } int main() { Init(); ll n; cin >> n; ll allGcd = -1; vi a(n); rep(i, n) { cin >> a[i]; if (i == 0) allGcd = a[i]; else allGcd = __gcd(allGcd, a[i]); } vector<bool> used(1000001, false); bool pc = true; rep(i, n) { auto eDiv = enumDivisors(a[i]); for (auto &num : eDiv) { if (num <= 1) continue; if (used[num]) { pc = false; break; } else { used[num] = true; } if (!pc) break; } if (!pc) break; } if (pc) cout << "pairwise coprime" << endl; else if (!pc && allGcd == 1) cout << "setwise coprime" << endl; else cout << "not coprime" << endl; }
insert
79
79
79
81
TLE
p02574
C++
Runtime Error
// CPP program to find the number of pairs // such that gcd equals to 1 #include <bits/stdc++.h> using namespace std; #define N 100050 int lpf[N], mobius[N]; // Function to calculate least // prime factor of each number void least_prime_factor() { for (int i = 2; i < N; i++) // If it is a prime number if (!lpf[i]) for (int j = i; j < N; j += i) // For all multiples which are not // visited yet. if (!lpf[j]) lpf[j] = i; } // Function to find the value of Mobius function // for all the numbers from 1 to n void Mobius() { for (int i = 1; i < N; i++) { // If number is one if (i == 1) mobius[i] = 1; else { // If number has a squared prime factor if (lpf[i / lpf[i]] == lpf[i]) mobius[i] = 0; // Multiply -1 with the previous number else mobius[i] = -1 * mobius[i / lpf[i]]; } } } // Function to find the number of pairs // such that gcd equals to 1 int gcd_pairs(int a[], int n) { // To store maximum number int maxi = 0; // To store frequency of each number int fre[N] = {0}; // Find frequency and maximum number for (int i = 0; i < n; i++) { fre[a[i]]++; maxi = max(a[i], maxi); } least_prime_factor(); Mobius(); // To store number of pairs with gcd equals to 1 int ans = 0; // Traverse through the all possible elements for (int i = 1; i <= maxi; i++) { if (!mobius[i]) continue; int temp = 0; for (int j = i; j <= maxi; j += i) temp += fre[j]; ans += temp * (temp - 1) / 2 * mobius[i]; } // Return the number of pairs return ans; } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } // Driver code int main() { int n; cin >> n; int arr[n]; cin >> arr[0]; int tmp1 = arr[0]; for (int j = 1; j < n; j++) { cin >> arr[j]; tmp1 = gcd(tmp1, arr[j]); } int tmp; // Function call tmp = gcd_pairs(arr, n); // cout<<tmp1<<"\n"; if (2 * tmp == n * (n - 1)) { cout << "pairwise coprime"; } else if (tmp1 == 1) { cout << "setwise coprime"; } else { cout << "not coprime"; } return 0; }
// CPP program to find the number of pairs // such that gcd equals to 1 #include <bits/stdc++.h> using namespace std; #define N 1000050 int lpf[N], mobius[N]; // Function to calculate least // prime factor of each number void least_prime_factor() { for (int i = 2; i < N; i++) // If it is a prime number if (!lpf[i]) for (int j = i; j < N; j += i) // For all multiples which are not // visited yet. if (!lpf[j]) lpf[j] = i; } // Function to find the value of Mobius function // for all the numbers from 1 to n void Mobius() { for (int i = 1; i < N; i++) { // If number is one if (i == 1) mobius[i] = 1; else { // If number has a squared prime factor if (lpf[i / lpf[i]] == lpf[i]) mobius[i] = 0; // Multiply -1 with the previous number else mobius[i] = -1 * mobius[i / lpf[i]]; } } } // Function to find the number of pairs // such that gcd equals to 1 int gcd_pairs(int a[], int n) { // To store maximum number int maxi = 0; // To store frequency of each number int fre[N] = {0}; // Find frequency and maximum number for (int i = 0; i < n; i++) { fre[a[i]]++; maxi = max(a[i], maxi); } least_prime_factor(); Mobius(); // To store number of pairs with gcd equals to 1 int ans = 0; // Traverse through the all possible elements for (int i = 1; i <= maxi; i++) { if (!mobius[i]) continue; int temp = 0; for (int j = i; j <= maxi; j += i) temp += fre[j]; ans += temp * (temp - 1) / 2 * mobius[i]; } // Return the number of pairs return ans; } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } // Driver code int main() { int n; cin >> n; int arr[n]; cin >> arr[0]; int tmp1 = arr[0]; for (int j = 1; j < n; j++) { cin >> arr[j]; tmp1 = gcd(tmp1, arr[j]); } int tmp; // Function call tmp = gcd_pairs(arr, n); // cout<<tmp1<<"\n"; if (2 * tmp == n * (n - 1)) { cout << "pairwise coprime"; } else if (tmp1 == 1) { cout << "setwise coprime"; } else { cout << "not coprime"; } return 0; }
replace
5
6
5
6
0
p02574
C++
Time Limit Exceeded
// #pragma GCC target("avx2") #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <prettyprint.hpp> #define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__); #else #define debug(...) 83; #endif void d_err() { cerr << endl; } template <typename H, typename... T> void d_err(H h, T... t) { cerr << h << " "; d_err(t...); } template <typename T> void print(T x) { cout << x << "\n"; } #define ALL(x) (x).begin(), (x).end() #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i) #define REP(i, n) FOR(i, 0, n) #define REVREP(i, n) REVFOR(i, 0, n) #define fi first #define se second #define pb push_back #define mp make_pair #define eb emplace_back #define bcnt __builtin_popcountll typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<ll, ll> Pll; typedef pair<int, int> Pin; ll INF = 1e16; int inf = 1e9; ll MOD = 1e9 + 7; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; } void SOE(ll N, vi &p) { int m = int(floor(sqrt(N))) + 1; int s[m]; REP(i, m) s[i] = i; FOR(i, 2, m) { if (s[i] != i) continue; p.pb(i); for (int j = i + i; j <= m; j += i) { s[j] = i; } } } void solve(int n, vll &a) { ll g = a[0]; REP(i, n) g = __gcd(g, a[i]); vector<int> prime; SOE(1e7, prime); map<int, int> l, m; REP(i, n) { for (auto &e : prime) { if (a[i] % e != 0) continue; int cnt = 0; while (a[i] % e == 0) { a[i] /= e; cnt++; } m[e] += cnt; l[e] = max(l[e], cnt); } if (a[i] > 1) { m[a[i]] += 1; l[a[i]] = max(l[a[i]], 1); } } bool f = false; if (l.size() == m.size()) { f = true; for (auto &p : l) { f &= l[p.fi] == m[p.fi]; } } if (f) { print("pairwise coprime"); } else { if (g == 1) { print("setwise coprime"); } else print("not coprime"); } } int tle(int n, vll &a) { ll g = a[0]; REP(i, n) g = __gcd(g, a[i]); bool f = true; REP(i, n) FOR(j, i + 1, n) { f &= __gcd(a[i], a[j]) == 1; // debug(a[i], a[j], __gcd(a[i], a[j])) } if (f) { return 1; } else { if (g == 1) return 2; return 3; } } int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); int n; cin >> n; vll a(n); REP(i, n) cin >> a[i]; solve(n, a); }
// #pragma GCC target("avx2") #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <prettyprint.hpp> #define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__); #else #define debug(...) 83; #endif void d_err() { cerr << endl; } template <typename H, typename... T> void d_err(H h, T... t) { cerr << h << " "; d_err(t...); } template <typename T> void print(T x) { cout << x << "\n"; } #define ALL(x) (x).begin(), (x).end() #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i) #define REP(i, n) FOR(i, 0, n) #define REVREP(i, n) REVFOR(i, 0, n) #define fi first #define se second #define pb push_back #define mp make_pair #define eb emplace_back #define bcnt __builtin_popcountll typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<ll, ll> Pll; typedef pair<int, int> Pin; ll INF = 1e16; int inf = 1e9; ll MOD = 1e9 + 7; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; } void SOE(ll N, vi &p) { int m = int(floor(sqrt(N))) + 1; int s[m]; REP(i, m) s[i] = i; FOR(i, 2, m) { if (s[i] != i) continue; p.pb(i); for (int j = i + i; j <= m; j += i) { s[j] = i; } } } void solve(int n, vll &a) { ll g = a[0]; REP(i, n) g = __gcd(g, a[i]); vector<int> prime; SOE(1e6, prime); map<int, int> l, m; REP(i, n) { for (auto &e : prime) { if (a[i] % e != 0) continue; int cnt = 0; while (a[i] % e == 0) { a[i] /= e; cnt++; } m[e] += cnt; l[e] = max(l[e], cnt); } if (a[i] > 1) { m[a[i]] += 1; l[a[i]] = max(l[a[i]], 1); } } bool f = false; if (l.size() == m.size()) { f = true; for (auto &p : l) { f &= l[p.fi] == m[p.fi]; } } if (f) { print("pairwise coprime"); } else { if (g == 1) { print("setwise coprime"); } else print("not coprime"); } } int tle(int n, vll &a) { ll g = a[0]; REP(i, n) g = __gcd(g, a[i]); bool f = true; REP(i, n) FOR(j, i + 1, n) { f &= __gcd(a[i], a[j]) == 1; // debug(a[i], a[j], __gcd(a[i], a[j])) } if (f) { return 1; } else { if (g == 1) return 2; return 3; } } int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); int n; cin >> n; vll a(n); REP(i, n) cin >> a[i]; solve(n, a); }
replace
78
79
78
79
TLE
p02574
C++
Runtime Error
// AUTHOR - NAVEEN KUMAR(@naveen19991124) #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update // #include<boost/multiprecision/cpp_int.hpp> // #inlcude<boost/multiprecision/cpp_dec_float.hpp> #define ll long long #define ld long double #define F first #define S second #define nl "\n" #define mem(v) memset(v, 0, sizeof(v)) #define all(v) v.begin(), v.end() #define srt(v) sort(all(v)) #define rsrt(v) sort(v.rbegin(), v.rend()) #define pb push_back #define f(a) for (ll i = 0; i < a; i++) #define rep(i, a, b) for (ll i = a; i < b; i++) #define rrep(i, a, b) for (ll i = a; i > b; i--) #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pair<ll, ll>> #define mp make_pair #define trace(a) cout << a << "\n"; #define trace2(a, b) cout << a << " " << b << "\n"; #define trace3(a, b, c) cout << a << " " << b << " " << c << "\n"; #define dbgarr(a) \ for (auto y : a) { \ cout << y << " "; \ } \ cout << "\n"; #define dbgparr(a) \ for (auto y : a) { \ cout << y.F << " " << y.S << "\n"; \ } \ cout << "\n"; #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } #define hell 1000000007 #define INF (ll)(1e18 + 5) #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); using namespace std; using namespace std::chrono; using namespace __gnu_pbds; // using boost :: multiprecision :: cpp_int; // using boost :: multiprecision :: cpp_dec_float_50; // using boost :: multiprecision :: cpp_dec_float_100; // Ordered Sets typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order() // Value at given index 0-based // order_of_key() // Index returned where element is to be // inserted(lower_bound())(if present return index) // Debug section void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } void out(vector<ll> arr) { for (auto i : arr) { cout << i << " "; } cout << "\n"; } void out(vector<pair<ll, ll>> par) { for (auto i : par) { cout << i.F << " " << i.S << "\n"; } } void out(set<ll> arr) { for (auto i : arr) { cout << i << " "; } cout << "\n"; } void out(multiset<ll> arr) { for (auto i : arr) { cout << i << " "; } cout << "\n"; } // Power functions ll power(ll a, ll n) { ll p = 1; while (n > 0) { if (n % 2) { p = p * a; } n >>= 1; a *= a; } return p; } ll power(ll a, ll n, ll mod) { ll p = 1; while (n > 0) { if (n % 2) { p = p * a; p %= mod; } n >>= 1; a *= a; a %= mod; } return p % mod; } // Mod functions ll modInverse(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) { return 0; } while (a > 1) { ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) { x += m0; } return x; } inline ll add(ll a, ll b) { return (((a >= hell) ? a % hell : a) + ((b >= hell) ? b % hell : b) + hell) % hell; } inline ll subt(ll a, ll b) { return (a - b + hell) % hell; } inline ll mult(ll a, ll b) { return (1ll * ((a >= hell) ? a % hell : a) * ((b >= hell) ? b % hell : b)) % hell; } // Miscellaneous 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 mylog(ll n, ll b) { ll i = 1; ll ans = 0; while (1) { if (i > n / b) { break; } i = i * b; ans++; } return ans; } // Comparators bool compare(const pair<ll, ll> &a, const pair<ll, ll> &b) { if (a.first == b.first) { return a.second < b.second; } return a.first < b.first; } bool comparerev(const pair<ll, ll> &a, const pair<ll, ll> &b) { if (a.first == b.first) { return a.second > b.second; } return a.first > b.first; } const ll d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1}; const ll d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1}; #define N 100005 ll lpf[N], mobius[N]; ll fre[N]; // Function to calculate least // prime factor of each number void least_prime_factor() { // cout<<"insid3e\n"; for (ll i = 2; i < N; i++) // If it is a prime number if (!lpf[i]) for (ll j = i; j < N; j += i) // For all multiples which are not // visited yet. if (!lpf[j]) lpf[j] = i; } // Function to find the value of Mobius function // for all the numbers from 1 to n void Mobius() { // cout<<"insid2e\n"; for (ll i = 1; i < N; i++) { // If number is one if (i == 1) mobius[i] = 1; else { // If number has a squared prime factor if (lpf[i / lpf[i]] == lpf[i]) mobius[i] = 0; // Multiply -1 with the previous number else mobius[i] = -1 * mobius[i / lpf[i]]; } } } // Function to find the number of pairs // such that gcd equals to 1 ll gcd_pairs(ll a[], ll n) { // cout<<"here\n"; // To store maximum number // cout<<"inside\n"; ll maxi = 0; // To store frequency of each number // Find frequency and maximum number for (ll i = 0; i < n; i++) { fre[a[i]]++; maxi = max(a[i], maxi); } least_prime_factor(); Mobius(); // cout<<"INside1\n"; // To store number of pairs with gcd equals to 1 ll ans = 0; // Traverse through the all possible elements for (ll i = 1; i <= maxi; i++) { if (!mobius[i]) continue; ll temp = 0; for (int j = i; j <= maxi; j += i) temp += fre[j]; ans += temp * (temp - 1) / 2 * mobius[i]; } // Return the number of pairs return ans; } // MAIN CODE int main() { // fast ll t = 1; // cin>>t; while (t--) { ll n; cin >> n; mem(fre); ll arr[n]; ll ans = 2; f(n) { cin >> arr[i]; } ll val = arr[0]; f(n) { val = gcd(val, arr[i]); } // cout<<"ok\n"; if (val == 1) { ans = 1; // cout<<"ok1\n"; ll temp = gcd_pairs(arr, n); // cout<<"ok1\n"; if (temp == ((n - 1) * (n)) / 2) { ans = 0; } if (ans == 0) { cout << "pairwise coprime\n"; } else { cout << "setwise coprime\n"; } } else { cout << "not coprime\n"; } } return 0; }
// AUTHOR - NAVEEN KUMAR(@naveen19991124) #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update // #include<boost/multiprecision/cpp_int.hpp> // #inlcude<boost/multiprecision/cpp_dec_float.hpp> #define ll long long #define ld long double #define F first #define S second #define nl "\n" #define mem(v) memset(v, 0, sizeof(v)) #define all(v) v.begin(), v.end() #define srt(v) sort(all(v)) #define rsrt(v) sort(v.rbegin(), v.rend()) #define pb push_back #define f(a) for (ll i = 0; i < a; i++) #define rep(i, a, b) for (ll i = a; i < b; i++) #define rrep(i, a, b) for (ll i = a; i > b; i--) #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pair<ll, ll>> #define mp make_pair #define trace(a) cout << a << "\n"; #define trace2(a, b) cout << a << " " << b << "\n"; #define trace3(a, b, c) cout << a << " " << b << " " << c << "\n"; #define dbgarr(a) \ for (auto y : a) { \ cout << y << " "; \ } \ cout << "\n"; #define dbgparr(a) \ for (auto y : a) { \ cout << y.F << " " << y.S << "\n"; \ } \ cout << "\n"; #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } #define hell 1000000007 #define INF (ll)(1e18 + 5) #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); using namespace std; using namespace std::chrono; using namespace __gnu_pbds; // using boost :: multiprecision :: cpp_int; // using boost :: multiprecision :: cpp_dec_float_50; // using boost :: multiprecision :: cpp_dec_float_100; // Ordered Sets typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order() // Value at given index 0-based // order_of_key() // Index returned where element is to be // inserted(lower_bound())(if present return index) // Debug section void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } void out(vector<ll> arr) { for (auto i : arr) { cout << i << " "; } cout << "\n"; } void out(vector<pair<ll, ll>> par) { for (auto i : par) { cout << i.F << " " << i.S << "\n"; } } void out(set<ll> arr) { for (auto i : arr) { cout << i << " "; } cout << "\n"; } void out(multiset<ll> arr) { for (auto i : arr) { cout << i << " "; } cout << "\n"; } // Power functions ll power(ll a, ll n) { ll p = 1; while (n > 0) { if (n % 2) { p = p * a; } n >>= 1; a *= a; } return p; } ll power(ll a, ll n, ll mod) { ll p = 1; while (n > 0) { if (n % 2) { p = p * a; p %= mod; } n >>= 1; a *= a; a %= mod; } return p % mod; } // Mod functions ll modInverse(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) { return 0; } while (a > 1) { ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) { x += m0; } return x; } inline ll add(ll a, ll b) { return (((a >= hell) ? a % hell : a) + ((b >= hell) ? b % hell : b) + hell) % hell; } inline ll subt(ll a, ll b) { return (a - b + hell) % hell; } inline ll mult(ll a, ll b) { return (1ll * ((a >= hell) ? a % hell : a) * ((b >= hell) ? b % hell : b)) % hell; } // Miscellaneous 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 mylog(ll n, ll b) { ll i = 1; ll ans = 0; while (1) { if (i > n / b) { break; } i = i * b; ans++; } return ans; } // Comparators bool compare(const pair<ll, ll> &a, const pair<ll, ll> &b) { if (a.first == b.first) { return a.second < b.second; } return a.first < b.first; } bool comparerev(const pair<ll, ll> &a, const pair<ll, ll> &b) { if (a.first == b.first) { return a.second > b.second; } return a.first > b.first; } const ll d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1}; const ll d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1}; #define N 1000005 ll lpf[N], mobius[N]; ll fre[N]; // Function to calculate least // prime factor of each number void least_prime_factor() { // cout<<"insid3e\n"; for (ll i = 2; i < N; i++) // If it is a prime number if (!lpf[i]) for (ll j = i; j < N; j += i) // For all multiples which are not // visited yet. if (!lpf[j]) lpf[j] = i; } // Function to find the value of Mobius function // for all the numbers from 1 to n void Mobius() { // cout<<"insid2e\n"; for (ll i = 1; i < N; i++) { // If number is one if (i == 1) mobius[i] = 1; else { // If number has a squared prime factor if (lpf[i / lpf[i]] == lpf[i]) mobius[i] = 0; // Multiply -1 with the previous number else mobius[i] = -1 * mobius[i / lpf[i]]; } } } // Function to find the number of pairs // such that gcd equals to 1 ll gcd_pairs(ll a[], ll n) { // cout<<"here\n"; // To store maximum number // cout<<"inside\n"; ll maxi = 0; // To store frequency of each number // Find frequency and maximum number for (ll i = 0; i < n; i++) { fre[a[i]]++; maxi = max(a[i], maxi); } least_prime_factor(); Mobius(); // cout<<"INside1\n"; // To store number of pairs with gcd equals to 1 ll ans = 0; // Traverse through the all possible elements for (ll i = 1; i <= maxi; i++) { if (!mobius[i]) continue; ll temp = 0; for (int j = i; j <= maxi; j += i) temp += fre[j]; ans += temp * (temp - 1) / 2 * mobius[i]; } // Return the number of pairs return ans; } // MAIN CODE int main() { // fast ll t = 1; // cin>>t; while (t--) { ll n; cin >> n; mem(fre); ll arr[n]; ll ans = 2; f(n) { cin >> arr[i]; } ll val = arr[0]; f(n) { val = gcd(val, arr[i]); } // cout<<"ok\n"; if (val == 1) { ans = 1; // cout<<"ok1\n"; ll temp = gcd_pairs(arr, n); // cout<<"ok1\n"; if (temp == ((n - 1) * (n)) / 2) { ans = 0; } if (ans == 0) { cout << "pairwise coprime\n"; } else { cout << "setwise coprime\n"; } } else { cout << "not coprime\n"; } } return 0; }
replace
188
189
188
189
0
p02574
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; const int N = 1e6 + 9; vector<int> prime; bool flag[N]; void seive() { for (int i = 4; i < N; i += 2) flag[i] = true; for (int i = 3; i * i < N; i += 2) { if (!flag[i]) { for (int j = i * 3; j < N; j += i * 2) flag[j] = true; } } prime.push_back(2); for (int i = 3; i <= N; i += 2) { if (!flag[i]) prime.push_back(i); } } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int a[n]; for (int &i : a) cin >> i; seive(); // for(int i=0;i<20;i++)cout<<prime[i]<<" "; // cout<<endl; map<int, int> cnt; for (int i : a) { int temp = i; for (int x : prime) { if (x * x > temp) break; if (temp % x == 0) { cnt[x]++; while (temp % x == 0) temp /= x; } } if (temp > 1) cnt[temp]++; } bool flag = true; for (auto [x, y] : cnt) { if (y > 1) { flag = false; break; } } if (flag) { cout << "pairwise coprime" << endl; return 0; } int g = a[0]; for (int i = 1; i < n; i++) g = __gcd(g, a[i]); if (g == 1) cout << "setwise coprime" << endl; else cout << "not coprime" << endl; }
#include "bits/stdc++.h" using namespace std; const int N = 1e6 + 9; vector<int> prime; bool flag[N + 100]; void seive() { for (int i = 4; i < N; i += 2) flag[i] = true; for (int i = 3; i * i < N; i += 2) { if (!flag[i]) { for (int j = i * 3; j < N; j += i * 2) flag[j] = true; } } prime.push_back(2); for (int i = 3; i <= N; i += 2) { if (!flag[i]) prime.push_back(i); } } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int a[n]; for (int &i : a) cin >> i; seive(); // for(int i=0;i<20;i++)cout<<prime[i]<<" "; // cout<<endl; map<int, int> cnt; for (int i : a) { int temp = i; for (int x : prime) { if (x * x > temp) break; if (temp % x == 0) { cnt[x]++; while (temp % x == 0) temp /= x; } } if (temp > 1) cnt[temp]++; } bool flag = true; for (auto [x, y] : cnt) { if (y > 1) { flag = false; break; } } if (flag) { cout << "pairwise coprime" << endl; return 0; } int g = a[0]; for (int i = 1; i < n; i++) g = __gcd(g, a[i]); if (g == 1) cout << "setwise coprime" << endl; else cout << "not coprime" << endl; }
replace
6
7
6
7
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> #define A_MAX 1000000 #define A_MAX_HALF 500000 using namespace std; int min_factor[A_MAX + 1]; int q[A_MAX + 1]; int a[A_MAX + 1]; vector<int> primes{ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997}; int N; // 入力読み込みは uzzy 氏のコードを真似した const int cm = 1 << 22; char cn[cm], *ci = cn, ct; inline int getint() { int A = 0; while ((ct = *ci++) >= '0') A = A * 10 + ct - '0'; return A; } int main() { fread(cn, 1, cm, stdin); for (int i = 2; i <= A_MAX_HALF; ++i) { if (!min_factor[i]) { min_factor[i] = i; } int min_factor_i = min_factor[i]; for (int p : primes) { int n = i * p; if (n > A_MAX) { break; } min_factor[n] = p; if (p == min_factor_i) { q[n] = q[i]; break; } else { q[n] = i; } } } N = getint(); for (int i = 0; i < N; ++i) { ++a[getint()]; } int is_pairwise_coprime = 1; for (int n = A_MAX; n > 1; --n) { int an = a[n]; if (an) { if (an > 1) { if (an == N) { printf("not coprime\n"); return 0; } is_pairwise_coprime = 0; } a[min_factor[n]] += an; a[q[n]] += an; } } if (is_pairwise_coprime) { printf("pairwise coprime\n"); } else { printf("setwise coprime\n"); } return 0; }
#include <bits/stdc++.h> #define A_MAX 1000000 #define A_MAX_HALF 500000 using namespace std; int min_factor[A_MAX + 1]; int q[A_MAX + 1]; int a[A_MAX + 1]; vector<int> primes{ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997}; int N; // 入力読み込みは uzzy 氏のコードを真似した const int cm = 1 << 26; char cn[cm], *ci = cn, ct; inline int getint() { int A = 0; while ((ct = *ci++) >= '0') A = A * 10 + ct - '0'; return A; } int main() { fread(cn, 1, cm, stdin); for (int i = 2; i <= A_MAX_HALF; ++i) { if (!min_factor[i]) { min_factor[i] = i; } int min_factor_i = min_factor[i]; for (int p : primes) { int n = i * p; if (n > A_MAX) { break; } min_factor[n] = p; if (p == min_factor_i) { q[n] = q[i]; break; } else { q[n] = i; } } } N = getint(); for (int i = 0; i < N; ++i) { ++a[getint()]; } int is_pairwise_coprime = 1; for (int n = A_MAX; n > 1; --n) { int an = a[n]; if (an) { if (an > 1) { if (an == N) { printf("not coprime\n"); return 0; } is_pairwise_coprime = 0; } a[min_factor[n]] += an; a[q[n]] += an; } } if (is_pairwise_coprime) { printf("pairwise coprime\n"); } else { printf("setwise coprime\n"); } return 0; }
replace
26
27
26
27
0
p02574
C++
Time Limit Exceeded
// #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; const int INF = 1 << 29; const int NINF = -1 * INF; const long long LLINF = 1ll << 60; const long long LLNINF = -1 * LLINF; template <class Ch, class Tr, class Container> basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os, Container const &x) { os << "{ "; for (auto &y : x) os << y << " "; return os << "}"; } template <class X, class Y> ostream &operator<<(ostream &os, pair<X, Y> const &p) { return os << "[ " << p.first << ", " << p.second << "]"; } typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<double> vd; typedef vector<ld> vld; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef vector<vector<int>> vvi; typedef vector<vll> vvll; typedef vector<vd> vvd; typedef vector<vld> vvld; typedef uint_fast16_t fint16; typedef uint_fast32_t fint32; typedef uint_fast64_t fint64; #define mp make_pair #define pb push_back #define pf push_front #define all(x) x.begin(), x.end() #define revAll(x) x.rbegin(), x.rend() #define gcd(a, b) __gcd(a, b) #define popcount(x) __builtin_popcount(x) #define isize(x) (int)(x.size()) #define rep(i, n) for (int i = 0; i < n; i++) #define exists(x, m) m.find(x) != m.end() #define umap unordered_map #define uset unordered_set #define pq priority_queue const ll MOD = 1e9 + 7; template <typename T> struct Sieve_Struct { const T lim; vector<T> primes; vector<bool> composite; Sieve_Struct(T limit) : lim(limit) { primes = vector<T>(); composite = vector<bool>(lim + 1, false); for (T num = 2; num <= lim; num++) { if (!composite[num]) primes.pb(num); for (int i = 0; i < isize(primes) and num * primes[i] <= lim; i++) { composite[num * primes[i]] = true; if (num % primes[i] == 0) break; } } } bool is_composite(T x) { assert(x <= lim); return composite[x]; } template <typename U> pair<vector<U>, vector<bool>> sieve_range(U L, U R) { U sqrtn = ceil(sqrt(R)); assert(sqrtn <= lim); vector<U> primes_range = vector<U>(); vector<bool> composite_range = vector<bool>(R - L + 1, false); if (L == 1) composite_range[0] = true; for (const U &p : primes) { for (U mult = max((U)2, (U)L / p - 10); (ll)mult * p <= R; mult++) { ll cand = mult * p; if (cand >= L) composite_range[cand - L] = true; } } rep(i, isize(composite_range)) { if (!composite_range[i]) primes_range.pb(L + i); } return {primes_range, composite_range}; } umap<T, int> prime_factorization(T x) { assert(ceil(sqrt(x)) <= lim); umap<T, int> pf = umap<T, int>(); for (const T &p : primes) { while (x > 1 and x % p == 0) { pf[p]++; x /= p; } } if (x > 1) pf[x]++; return pf; } vector<T> prime_factors(T x) { assert(ceil(sqrt(x)) <= lim); vector<T> factors = vector<T>(); for (const T &p : primes) { if (x % p == 0) factors.pb(p); while (x > 1 and x % p == 0) x /= p; } if (x > 1) factors.pb(x); return factors; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vi A = vi(); int max_a = 0; rep(i, n) { int x; cin >> x; A.pb(x); max_a = max(max_a, x); } Sieve_Struct<int> s = Sieve_Struct<int>(1e7); umap<int, int> prime_freqs = umap<int, int>(); for (const int &a : A) { for (const int &f : s.prime_factors(a)) { prime_freqs[f]++; } } int max_freq = 0; for (const auto &[factor, freq] : prime_freqs) { max_freq = max(max_freq, freq); } if (max_freq <= 1) { cout << "pairwise coprime"; } else { cout << (max_freq < n ? "setwise coprime" : "not coprime"); } }
// #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; const int INF = 1 << 29; const int NINF = -1 * INF; const long long LLINF = 1ll << 60; const long long LLNINF = -1 * LLINF; template <class Ch, class Tr, class Container> basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os, Container const &x) { os << "{ "; for (auto &y : x) os << y << " "; return os << "}"; } template <class X, class Y> ostream &operator<<(ostream &os, pair<X, Y> const &p) { return os << "[ " << p.first << ", " << p.second << "]"; } typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<double> vd; typedef vector<ld> vld; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef vector<vector<int>> vvi; typedef vector<vll> vvll; typedef vector<vd> vvd; typedef vector<vld> vvld; typedef uint_fast16_t fint16; typedef uint_fast32_t fint32; typedef uint_fast64_t fint64; #define mp make_pair #define pb push_back #define pf push_front #define all(x) x.begin(), x.end() #define revAll(x) x.rbegin(), x.rend() #define gcd(a, b) __gcd(a, b) #define popcount(x) __builtin_popcount(x) #define isize(x) (int)(x.size()) #define rep(i, n) for (int i = 0; i < n; i++) #define exists(x, m) m.find(x) != m.end() #define umap unordered_map #define uset unordered_set #define pq priority_queue const ll MOD = 1e9 + 7; template <typename T> struct Sieve_Struct { const T lim; vector<T> primes; vector<bool> composite; Sieve_Struct(T limit) : lim(limit) { primes = vector<T>(); composite = vector<bool>(lim + 1, false); for (T num = 2; num <= lim; num++) { if (!composite[num]) primes.pb(num); for (int i = 0; i < isize(primes) and num * primes[i] <= lim; i++) { composite[num * primes[i]] = true; if (num % primes[i] == 0) break; } } } bool is_composite(T x) { assert(x <= lim); return composite[x]; } template <typename U> pair<vector<U>, vector<bool>> sieve_range(U L, U R) { U sqrtn = ceil(sqrt(R)); assert(sqrtn <= lim); vector<U> primes_range = vector<U>(); vector<bool> composite_range = vector<bool>(R - L + 1, false); if (L == 1) composite_range[0] = true; for (const U &p : primes) { for (U mult = max((U)2, (U)L / p - 10); (ll)mult * p <= R; mult++) { ll cand = mult * p; if (cand >= L) composite_range[cand - L] = true; } } rep(i, isize(composite_range)) { if (!composite_range[i]) primes_range.pb(L + i); } return {primes_range, composite_range}; } umap<T, int> prime_factorization(T x) { assert(ceil(sqrt(x)) <= lim); umap<T, int> pf = umap<T, int>(); for (const T &p : primes) { while (x > 1 and x % p == 0) { pf[p]++; x /= p; } } if (x > 1) pf[x]++; return pf; } vector<T> prime_factors(T x) { assert(ceil(sqrt(x)) <= lim); vector<T> factors = vector<T>(); for (const T &p : primes) { if (x % p == 0) factors.pb(p); while (x > 1 and x % p == 0) x /= p; } if (x > 1) factors.pb(x); return factors; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vi A = vi(); int max_a = 0; rep(i, n) { int x; cin >> x; A.pb(x); max_a = max(max_a, x); } Sieve_Struct<int> s = Sieve_Struct<int>(1e3 + 100); umap<int, int> prime_freqs = umap<int, int>(); for (const int &a : A) { for (const int &f : s.prime_factors(a)) { prime_freqs[f]++; } } int max_freq = 0; for (const auto &[factor, freq] : prime_freqs) { max_freq = max(max_freq, freq); } if (max_freq <= 1) { cout << "pairwise coprime"; } else { cout << (max_freq < n ? "setwise coprime" : "not coprime"); } }
replace
150
151
150
151
TLE
p02574
C++
Runtime Error
// #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; const int INF = 1 << 29; const int NINF = -1 * INF; const long long LLINF = 1ll << 60; const long long LLNINF = -1 * LLINF; template <class Ch, class Tr, class Container> basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os, Container const &x) { os << "{ "; for (auto &y : x) os << y << " "; return os << "}"; } template <class X, class Y> ostream &operator<<(ostream &os, pair<X, Y> const &p) { return os << "[ " << p.first << ", " << p.second << "]"; } typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<double> vd; typedef vector<ld> vld; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef vector<vector<int>> vvi; typedef vector<vll> vvll; typedef vector<vd> vvd; typedef vector<vld> vvld; #define mp make_pair #define pb push_back #define pf push_front #define all(x) x.begin(), x.end() #define revAll(x) x.rbegin(), x.rend() #define gcd(a, b) __gcd(a, b) #define popcount(x) __builtin_popcount(x) #define isize(x) (int)(x.size()) #define rep(i, n) for (int i = 0; i < n; i++) #define exists(x, m) m.find(x) != m.end() #define umap unordered_map #define uset unordered_set #define pq priority_queue const ll MOD = 1e9 + 7; template <typename T> tuple<vector<T>, vector<bool>, vector<T>> prime_sieve(T lim) { vector<T> primes = vector<T>(); vector<T> lp = vector<T>(); vector<bool> composite = vector<bool>(lim + 1); for (T num = 2; num <= lim; num++) { if (!composite[num]) primes.pb(num); for (int i = 0; i < isize(primes) and num * primes[i] <= lim; i++) { composite[num * primes[i]] = true; if (num % primes[i] == 0) { lp[num] = primes[i]; break; } } } return {primes, composite, lp}; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vi A = vi(); int maxx = 0; rep(i, n) { int x; cin >> x; A.pb(x); maxx = max(maxx, x); } auto [primes, composite, lp] = prime_sieve((int)min(1e3 + 100, ceil(sqrt(maxx)) + 100)); umap<int, int> prime_freq = umap<int, int>(); for (const int &a : A) { int b = a; for (int i = 0; primes[i] * primes[i] <= b; i++) { if (b % primes[i] == 0) prime_freq[primes[i]]++; while (b % primes[i] == 0) b /= primes[i]; } if (b != 1) prime_freq[b]++; } int max_freq = 0; for (const auto &[p, freq] : prime_freq) { max_freq = max(max_freq, freq); } if (max_freq <= 1) { cout << "pairwise coprime"; } else { cout << (max_freq < n ? "setwise coprime" : "not coprime"); } }
// #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; const int INF = 1 << 29; const int NINF = -1 * INF; const long long LLINF = 1ll << 60; const long long LLNINF = -1 * LLINF; template <class Ch, class Tr, class Container> basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os, Container const &x) { os << "{ "; for (auto &y : x) os << y << " "; return os << "}"; } template <class X, class Y> ostream &operator<<(ostream &os, pair<X, Y> const &p) { return os << "[ " << p.first << ", " << p.second << "]"; } typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<double> vd; typedef vector<ld> vld; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef vector<vector<int>> vvi; typedef vector<vll> vvll; typedef vector<vd> vvd; typedef vector<vld> vvld; #define mp make_pair #define pb push_back #define pf push_front #define all(x) x.begin(), x.end() #define revAll(x) x.rbegin(), x.rend() #define gcd(a, b) __gcd(a, b) #define popcount(x) __builtin_popcount(x) #define isize(x) (int)(x.size()) #define rep(i, n) for (int i = 0; i < n; i++) #define exists(x, m) m.find(x) != m.end() #define umap unordered_map #define uset unordered_set #define pq priority_queue const ll MOD = 1e9 + 7; template <typename T> tuple<vector<T>, vector<bool>, vector<T>> prime_sieve(T lim) { vector<T> primes = vector<T>(); vector<T> lp = vector<T>(lim + 1, 0); vector<bool> composite = vector<bool>(lim + 1); for (T num = 2; num <= lim; num++) { if (!composite[num]) primes.pb(num); for (int i = 0; i < isize(primes) and num * primes[i] <= lim; i++) { composite[num * primes[i]] = true; if (num % primes[i] == 0) { lp[num] = primes[i]; break; } } } return {primes, composite, lp}; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vi A = vi(); int maxx = 0; rep(i, n) { int x; cin >> x; A.pb(x); maxx = max(maxx, x); } auto [primes, composite, lp] = prime_sieve((int)min(1e3 + 100, ceil(sqrt(maxx)) + 100)); umap<int, int> prime_freq = umap<int, int>(); for (const int &a : A) { int b = a; for (int i = 0; primes[i] * primes[i] <= b; i++) { if (b % primes[i] == 0) prime_freq[primes[i]]++; while (b % primes[i] == 0) b /= primes[i]; } if (b != 1) prime_freq[b]++; } int max_freq = 0; for (const auto &[p, freq] : prime_freq) { max_freq = max(max_freq, freq); } if (max_freq <= 1) { cout << "pairwise coprime"; } else { cout << (max_freq < n ? "setwise coprime" : "not coprime"); } }
replace
62
63
62
63
-11
p02574
C++
Runtime Error
// #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; const int INF = 1 << 29; const int NINF = -1 * INF; const long long LLINF = 1ll << 60; const long long LLNINF = -1 * LLINF; template <class Ch, class Tr, class Container> basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os, Container const &x) { os << "{ "; for (auto &y : x) os << y << " "; return os << "}"; } template <class X, class Y> ostream &operator<<(ostream &os, pair<X, Y> const &p) { return os << "[ " << p.first << ", " << p.second << "]"; } typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<double> vd; typedef vector<ld> vld; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef vector<vector<int>> vvi; typedef vector<vll> vvll; typedef vector<vd> vvd; typedef vector<vld> vvld; #define mp make_pair #define pb push_back #define pf push_front #define all(x) x.begin(), x.end() #define revAll(x) x.rbegin(), x.rend() #define gcd(a, b) __gcd(a, b) #define popcount(x) __builtin_popcount(x) #define isize(x) (int)(x.size()) #define rep(i, n) for (int i = 0; i < n; i++) #define exists(x, m) m.find(x) != m.end() #define umap unordered_map #define uset unordered_set #define pq priority_queue const ll MOD = 1e9 + 7; vll primes_up_to(ll lim) { vll primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}; if (lim <= 71) return {primes.begin(), upper_bound(all(primes), lim)}; for (int num = 73; num <= lim; num++) { bool is_prime = true; for (int i = 0; primes[i] * primes[i] <= num; i++) { if (num % primes[i] == 0) { is_prime = false; break; } } if (is_prime) primes.pb(num); } return primes; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vi A = vi(); int maxx = 0; rep(i, n) { int x; cin >> x; A.pb(x); maxx = max(maxx, x); } vll primes = primes_up_to(maxx); map<int, int> prime_freq = map<int, int>(); for (const int &a : A) { int b = a; for (int i = 0; primes[i] * primes[i] <= b; i++) { if (b % primes[i] == 0) prime_freq[primes[i]]++; while (b % primes[i] == 0) b /= primes[i]; } if (b != 1) prime_freq[b]++; } int max_freq = 0; for (const auto &[p, freq] : prime_freq) { max_freq = max(max_freq, freq); } if (max_freq <= 1) { cout << "pairwise coprime"; } else { cout << (max_freq < n ? "setwise coprime" : "not coprime"); } }
// #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; const int INF = 1 << 29; const int NINF = -1 * INF; const long long LLINF = 1ll << 60; const long long LLNINF = -1 * LLINF; template <class Ch, class Tr, class Container> basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os, Container const &x) { os << "{ "; for (auto &y : x) os << y << " "; return os << "}"; } template <class X, class Y> ostream &operator<<(ostream &os, pair<X, Y> const &p) { return os << "[ " << p.first << ", " << p.second << "]"; } typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<double> vd; typedef vector<ld> vld; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef vector<vector<int>> vvi; typedef vector<vll> vvll; typedef vector<vd> vvd; typedef vector<vld> vvld; #define mp make_pair #define pb push_back #define pf push_front #define all(x) x.begin(), x.end() #define revAll(x) x.rbegin(), x.rend() #define gcd(a, b) __gcd(a, b) #define popcount(x) __builtin_popcount(x) #define isize(x) (int)(x.size()) #define rep(i, n) for (int i = 0; i < n; i++) #define exists(x, m) m.find(x) != m.end() #define umap unordered_map #define uset unordered_set #define pq priority_queue const ll MOD = 1e9 + 7; vll primes_up_to(ll lim) { vll primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}; if (lim <= 71) return {primes.begin(), upper_bound(all(primes), lim)}; for (int num = 73; num <= lim; num++) { bool is_prime = true; for (int i = 0; primes[i] * primes[i] <= num; i++) { if (num % primes[i] == 0) { is_prime = false; break; } } if (is_prime) primes.pb(num); } return primes; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vi A = vi(); int maxx = 0; rep(i, n) { int x; cin >> x; A.pb(x); maxx = max(maxx, x); } vll primes = primes_up_to(1e6); map<int, int> prime_freq = map<int, int>(); for (const int &a : A) { int b = a; for (int i = 0; primes[i] * primes[i] <= b; i++) { if (b % primes[i] == 0) prime_freq[primes[i]]++; while (b % primes[i] == 0) b /= primes[i]; } if (b != 1) prime_freq[b]++; } int max_freq = 0; for (const auto &[p, freq] : prime_freq) { max_freq = max(max_freq, freq); } if (max_freq <= 1) { cout << "pairwise coprime"; } else { cout << (max_freq < n ? "setwise coprime" : "not coprime"); } }
replace
91
92
91
92
0
p02574
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define int long long using namespace std; vector<int> primes(int x) { vector<int> ret; for (int i = 2; i * i <= x; i++) { if (x % i) continue; while (x % i == 0) x /= i; ret.push_back(i); } if (x != 1) ret.push_back(x); return ret; } signed main() { int N; cin >> N; vector<int> A(N); map<int, int> primes_cnt; for (auto &x : A) { cin >> x; for (auto e : primes(x)) { primes_cnt[e]++; } } int ma = 0; for (auto p : primes_cnt) { ma = max(ma, p.second); } if (ma == N) { cout << "not coprime\n"; } else if (ma > 1) { cout << "setwise coprime\n"; } else { cout << "pairwise coprime\n"; } }
#include <bits/stdc++.h> #define int long long using namespace std; vector<int> primes(int x) { vector<int> ret; if (x % 2 == 0) { ret.push_back(2); while (x % 2 == 0) x /= 2; } for (int i = 3; i * i <= x; i += 2) { if (x % i) continue; while (x % i == 0) x /= i; ret.push_back(i); } if (x != 1) ret.push_back(x); return ret; } signed main() { int N; cin >> N; vector<int> A(N); map<int, int> primes_cnt; for (auto &x : A) { cin >> x; for (auto e : primes(x)) { primes_cnt[e]++; } } int ma = 0; for (auto p : primes_cnt) { ma = max(ma, p.second); } if (ma == N) { cout << "not coprime\n"; } else if (ma > 1) { cout << "setwise coprime\n"; } else { cout << "pairwise coprime\n"; } }
replace
5
6
5
11
TLE
p02574
C++
Time Limit Exceeded
#pragma GCC optimize(3, "Ofast", "inline") #include <bits/stdc++.h> #define ios std::ios::sync_with_stdio(false) #define rep(i, a, n) for (int i = a; i <= n; i++) #define per(i, n, a) for (int i = n; i >= a; i--) #define repp(i, a, b) for (int i = a; i < b; i++) #define mm(a, n) memset(a, n, sizeof(a)) #define pb push_back #define all(x) (x).begin(), (x).end() #define fi first #define se second #define il inline #define int long long #define ll long long #define ull unsigned long long #define MOD 1000000007 #define pi 3.14159265358979323 #define SZ(x) ((ll)(x).size()) #define debug(x) cout << #x << ": " << x << endl; #define debug2(x, y) \ cout << #x << ": " << x << " | " << #y << ": " << y << endl; #define debug3(x, y, z) \ cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define debug4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; using namespace std; const ll INF(0x3f3f3f3f3f3f3f3fll); const int inf(0x3f3f3f3f); template <typename T> void read(T &res) { bool flag = false; char ch; while (!isdigit(ch = getchar())) (ch == '-') && (flag = true); for (res = ch - 48; isdigit(ch = getchar()); res = (res << 1) + (res << 3) + ch - 48) ; flag && (res = -res); } template <typename T> void Out(T x) { if (x < 0) putchar('-'), x = -x; if (x > 9) Out(x / 10); putchar(x % 10 + '0'); } 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 pow_mod(ll x, ll n, ll mod) { ll res = 1; while (n) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } ll fact_pow(ll n, ll p) { ll res = 0; while (n) { n /= p; res += n; } return res; } ll mult(ll a, ll b, ll p) { a %= p; b %= p; ll r = 0, v = a; while (b) { if (b & 1) { r += v; if (r > p) r -= p; } v <<= 1; if (v > p) v -= p; b >>= 1; } return r; } ll quick_pow(ll a, ll b, ll p) { ll r = 1, v = a % p; while (b) { if (b & 1) r = mult(r, v, p); v = mult(v, v, p); b >>= 1; } return r; } bool CH(ll a, ll n, ll x, ll t) { ll r = quick_pow(a, x, n); ll z = r; for (ll i = 1; i <= t; i++) { r = mult(r, r, n); if (r == 1 && z != 1 && z != n - 1) return true; z = r; } return r != 1; } bool Miller_Rabin(ll n) { if (n < 2) return false; if (n == 2) return true; if (!(n & 1)) return false; ll x = n - 1, t = 0; while (!(x & 1)) { x >>= 1; t++; } srand(time(NULL)); ll o = 8; for (ll i = 0; i < o; i++) { ll a = rand() % (n - 1) + 1; if (CH(a, n, x, t)) return false; } return true; } ll exgcd1(ll a, ll b, ll &x, ll &y) { if (!b) { x = 1, y = 0; return a; } ll t = exgcd1(b, a % b, y, x); y -= a / b * x; return t; } ll get_inv(ll a, ll mod) { ll x, y; ll d = exgcd1(a, mod, x, y); return d == 1 ? (x % mod + mod) % mod : -1; } void exgcd(ll a, ll b, ll &x, ll &y) { if (!b) { x = 1, y = 0; return; } exgcd(b, a % b, x, y); ll t = x; x = y, y = t - (a / b) * y; } ll INV(ll a, ll b) { ll x, y; return exgcd(a, b, x, y), (x % b + b) % b; } ll crt(ll x, ll p, ll mod) { return INV(p / mod, mod) * (p / mod) * x; } ll FAC(ll x, ll a, ll b) { if (!x) return 1; ll ans = 1; for (ll i = 1; i <= b; i++) if (i % a) ans *= i, ans %= b; ans = pow_mod(ans, x / b, b); for (ll i = 1; i <= x % b; i++) if (i % a) ans *= i, ans %= b; return ans * FAC(x / a, a, b) % b; } ll C(ll n, ll m, ll a, ll b) { ll N = FAC(n, a, b), M = FAC(m, a, b), Z = FAC(n - m, a, b), sum = 0, i; for (i = n; i; i = i / a) sum += i / a; for (i = m; i; i = i / a) sum -= i / a; for (i = n - m; i; i = i / a) sum -= i / a; return N * pow_mod(a, sum, b) % b * INV(M, b) % b * INV(Z, b) % b; } ll exlucas(ll n, ll m, ll p) { ll t = p, ans = 0, i; for (i = 2; i * i <= p; i++) { ll k = 1; while (t % i == 0) { k *= i, t /= i; } ans += crt(C(n, m, i, k), p, k), ans %= p; } if (t > 1) ans += crt(C(n, m, t, t), p, t), ans %= p; return ans % p; } /* int prime[100000],minprime[100000]; int euler(int n) {int c=0,i,j;for(i=2;i<=n;i++){if(!minprime[i])prime[++c]=i,minprime[i]=i;for(j=1;j<=c&&i*prime[j]<=n;j++) {minprime[i*prime[j]]=prime[j];if(i%prime[j]==0)break;}}return c;} struct Tree{ll l,r,sum,lazy,maxn,minn;}tree[100000]; il void push_up(ll rt) {tree[rt].sum=tree[rt<<1].sum+tree[rt<<1|1].sum; tree[rt].maxn=max(tree[rt<<1].maxn,tree[rt<<1|1].maxn); tree[rt].minn=min(tree[rt<<1].minn,tree[rt<<1|1].minn);} il void push_down(ll rt , ll length) {if(tree[rt].lazy){tree[rt<<1].lazy+=tree[rt].lazy;tree[rt<<1|1].lazy+=tree[rt].lazy; tree[rt<<1].sum+=(length-(length>>1))*tree[rt].lazy;tree[rt<<1|1].sum+=(length>>1)*tree[rt].lazy; tree[rt<<1].minn+=tree[rt].lazy;tree[rt<<1|1].minn+=tree[rt].lazy; tree[rt<<1].maxn+=tree[rt].lazy;tree[rt<<1|1].maxn+=tree[rt].lazy;tree[rt].lazy=0;}} il void build(ll l , ll r , ll rt , ll *aa) {tree[rt].lazy=0;tree[rt].l=l;tree[rt].r=r;if(l==r) {tree[rt].sum=aa[l];tree[rt].minn=tree[rt].sum;tree[rt].maxn=tree[rt].sum;return;} ll mid=(l+r)>>1;build(l,mid,rt<<1,aa);build(mid+1,r,rt<<1|1,aa);push_up(rt);} il void update_range(ll L , ll R , ll key , ll rt) {if(tree[rt].r<L||tree[rt].l>R)return;if(L<=tree[rt].l&&R>=tree[rt].r){tree[rt].sum+=(tree[rt].r-tree[rt].l+1)*key; tree[rt].minn+=key;tree[rt].maxn+=key;tree[rt].lazy+=key;return;}push_down(rt,tree[rt].r-tree[rt].l+1); ll mid=(tree[rt].r+tree[rt].l)>>1;if(L<=mid)update_range(L,R,key,rt << 1); if(R>mid)update_range(L,R,key,rt << 1 | 1);push_up(rt);} il ll query_range(ll L, ll R, ll rt) {if(L<=tree[rt].l&&R>=tree[rt].r){return tree[rt].sum;}push_down(rt,tree[rt].r-tree[rt].l+1); ll mid=(tree[rt].r+tree[rt].l)>>1;ll ans=0;if(L<=mid)ans+=query_range(L,R,rt << 1); if(R>mid)ans+=query_range(L,R,rt << 1 | 1);return ans;} il ll query_min(ll L,ll R,ll rt) {if(L<=tree[rt].l&&R>=tree[rt].r){return tree[rt].minn;}push_down(rt,tree[rt].r-tree[rt].l+1); ll mid=(tree[rt].r+tree[rt].l)>>1;ll ans=(0x3f3f3f3f3f3f3f3fll);if(L<=mid)ans=min(ans,query_min(L,R,rt << 1)); if(R>mid)ans=min(ans,query_min(L,R,rt << 1 | 1));return ans;} il ll query_max(ll L, ll R, ll rt) {if(L<=tree[rt].l&&R>=tree[rt].r){return tree[rt].maxn;}push_down(rt,tree[rt].r-tree[rt].l+1); ll mid=(tree[rt].r+tree[rt].l)>>1;ll ans=-(0x3f3f3f3f3f3f3f3fll);if(L<=mid)ans=max(ans,query_max(L,R,rt << 1)); if(R>mid)ans=max(ans,query_max(L,R,rt << 1 | 1));return ans;} namespace linear_seq{ typedef vector<ll> VI;const ll N=1e5+10,mod = 1e9 + 7; ll Rx[N],Ba[N],_c[N],_md[N];VI Md; ll PMD(ll a,ll b){ll Rx=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)Rx=Rx*a%mod;a=a*a%mod;}return Rx;} void MUL(ll *a,ll *b,ll k){repp(i,0,k+k)_c[i]=0;repp(i,0,k)if(a[i])repp(j,0,k)_c[i+j]=(_c[i+j]+a[i]*b[j])%mod; for(ll i=k+k-1;i>=k;i--)if(_c[i])repp(j,0,SZ(Md))_c[i-k+Md[j]]=(_c[i-k+Md[j]]-_c[i]*_md[Md[j]])%mod; repp(i,0,k)a[i]=_c[i];}ll Solve(ll n,VI a,VI b){ll ans=0,pnt=0,k=a.size();assert(SZ(a)==SZ(b)); repp(i,0,k)_md[k-1-i]=-a[i];_md[k]=1;Md.clear();repp(i,0,k)if(_md[i]!=0)Md.push_back(i);repp(i,0,k)Rx[i]=Ba[i]=0; Rx[0]=1;while((1ll<<pnt)<=n)pnt++;for(ll p=pnt;p>=0;p--){MUL(Rx,Rx,k);if((n>>p)&1){for(ll i=k-1;i>=0;i--)Rx[i+1]=Rx[i]; Rx[0]=0;repp(j,0,SZ(Md))Rx[Md[j]]=(Rx[Md[j]]-Rx[k]*_md[Md[j]])%mod;}}repp(i,0,k) ans=(ans+Rx[i]*b[i])%mod; if(ans<0)ans+=mod;return ans;}VI BM(VI s){VI C(1,1),B(1,1);ll L=0,m=1,b=1;repp(n,0,SZ(s)){ll d=0; repp(i,0,L+1)d=(d+(ll)C[i]*s[n-i])%mod;if(d==0)++m;else if(2*L<=n){VI T=C;ll c=mod-d*PMD(b,mod-2)%mod; while(SZ(C)<SZ(B)+m)C.push_back(0);repp(i,0,SZ(B))C[i+m]=(C[i+m]+c*B[i])%mod;L=n+1-L;B=T;b=d;m=1;} else{ll c=mod-d*PMD(b,mod-2)%mod;while(SZ(C)<SZ(B)+m)C.push_back(0); repp(i,0,SZ(B))C[i+m]=(C[i+m]+c*B[i])%mod;++m;}}return C;} ll Gao(VI a,ll n){VI c=BM(a);c.erase(c.begin());n--;repp(i,0,SZ(c))c[i]=(mod-c[i])%mod; return Solve(n,c,VI(a.begin(),a.begin()+SZ(c)));}}; */ const int N = 1e6 + 10; struct Edge { int nex, to; } edge[N << 1]; int head[N], TOT; void add_edge(int u, int v) { edge[++TOT].nex = head[u]; edge[TOT].to = v; head[u] = TOT; } int a[N]; int cnt[N]; signed main() { ios; cin.tie(0), cout.tie(0); int n; cin >> n; rep(i, 1, n) cin >> a[i]; rep(i, 1, n) { int x = a[i]; int sq = sqrt(x); for (int j = 2; j <= sq; j++) { if (x % j == 0) { while (x % j == 0) x /= j; cnt[j]++; } } if (x > 1) cnt[x]++; } int g = a[1], flag = 0; rep(i, 1, N - 10) if (cnt[i] > 1) flag = 1; if (!flag) return cout << "pairwise coprime\n", 0; rep(i, 2, n) g = gcd(g, a[i]); if (g == 1) cout << "setwise coprime\n"; else cout << "not coprime\n"; return 0; }
#pragma GCC optimize(3, "Ofast", "inline") #include <bits/stdc++.h> #define ios std::ios::sync_with_stdio(false) #define rep(i, a, n) for (int i = a; i <= n; i++) #define per(i, n, a) for (int i = n; i >= a; i--) #define repp(i, a, b) for (int i = a; i < b; i++) #define mm(a, n) memset(a, n, sizeof(a)) #define pb push_back #define all(x) (x).begin(), (x).end() #define fi first #define se second #define il inline #define int long long #define ll long long #define ull unsigned long long #define MOD 1000000007 #define pi 3.14159265358979323 #define SZ(x) ((ll)(x).size()) #define debug(x) cout << #x << ": " << x << endl; #define debug2(x, y) \ cout << #x << ": " << x << " | " << #y << ": " << y << endl; #define debug3(x, y, z) \ cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define debug4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; using namespace std; const ll INF(0x3f3f3f3f3f3f3f3fll); const int inf(0x3f3f3f3f); template <typename T> void read(T &res) { bool flag = false; char ch; while (!isdigit(ch = getchar())) (ch == '-') && (flag = true); for (res = ch - 48; isdigit(ch = getchar()); res = (res << 1) + (res << 3) + ch - 48) ; flag && (res = -res); } template <typename T> void Out(T x) { if (x < 0) putchar('-'), x = -x; if (x > 9) Out(x / 10); putchar(x % 10 + '0'); } 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 pow_mod(ll x, ll n, ll mod) { ll res = 1; while (n) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } ll fact_pow(ll n, ll p) { ll res = 0; while (n) { n /= p; res += n; } return res; } ll mult(ll a, ll b, ll p) { a %= p; b %= p; ll r = 0, v = a; while (b) { if (b & 1) { r += v; if (r > p) r -= p; } v <<= 1; if (v > p) v -= p; b >>= 1; } return r; } ll quick_pow(ll a, ll b, ll p) { ll r = 1, v = a % p; while (b) { if (b & 1) r = mult(r, v, p); v = mult(v, v, p); b >>= 1; } return r; } bool CH(ll a, ll n, ll x, ll t) { ll r = quick_pow(a, x, n); ll z = r; for (ll i = 1; i <= t; i++) { r = mult(r, r, n); if (r == 1 && z != 1 && z != n - 1) return true; z = r; } return r != 1; } bool Miller_Rabin(ll n) { if (n < 2) return false; if (n == 2) return true; if (!(n & 1)) return false; ll x = n - 1, t = 0; while (!(x & 1)) { x >>= 1; t++; } srand(time(NULL)); ll o = 8; for (ll i = 0; i < o; i++) { ll a = rand() % (n - 1) + 1; if (CH(a, n, x, t)) return false; } return true; } ll exgcd1(ll a, ll b, ll &x, ll &y) { if (!b) { x = 1, y = 0; return a; } ll t = exgcd1(b, a % b, y, x); y -= a / b * x; return t; } ll get_inv(ll a, ll mod) { ll x, y; ll d = exgcd1(a, mod, x, y); return d == 1 ? (x % mod + mod) % mod : -1; } void exgcd(ll a, ll b, ll &x, ll &y) { if (!b) { x = 1, y = 0; return; } exgcd(b, a % b, x, y); ll t = x; x = y, y = t - (a / b) * y; } ll INV(ll a, ll b) { ll x, y; return exgcd(a, b, x, y), (x % b + b) % b; } ll crt(ll x, ll p, ll mod) { return INV(p / mod, mod) * (p / mod) * x; } ll FAC(ll x, ll a, ll b) { if (!x) return 1; ll ans = 1; for (ll i = 1; i <= b; i++) if (i % a) ans *= i, ans %= b; ans = pow_mod(ans, x / b, b); for (ll i = 1; i <= x % b; i++) if (i % a) ans *= i, ans %= b; return ans * FAC(x / a, a, b) % b; } ll C(ll n, ll m, ll a, ll b) { ll N = FAC(n, a, b), M = FAC(m, a, b), Z = FAC(n - m, a, b), sum = 0, i; for (i = n; i; i = i / a) sum += i / a; for (i = m; i; i = i / a) sum -= i / a; for (i = n - m; i; i = i / a) sum -= i / a; return N * pow_mod(a, sum, b) % b * INV(M, b) % b * INV(Z, b) % b; } ll exlucas(ll n, ll m, ll p) { ll t = p, ans = 0, i; for (i = 2; i * i <= p; i++) { ll k = 1; while (t % i == 0) { k *= i, t /= i; } ans += crt(C(n, m, i, k), p, k), ans %= p; } if (t > 1) ans += crt(C(n, m, t, t), p, t), ans %= p; return ans % p; } /* int prime[100000],minprime[100000]; int euler(int n) {int c=0,i,j;for(i=2;i<=n;i++){if(!minprime[i])prime[++c]=i,minprime[i]=i;for(j=1;j<=c&&i*prime[j]<=n;j++) {minprime[i*prime[j]]=prime[j];if(i%prime[j]==0)break;}}return c;} struct Tree{ll l,r,sum,lazy,maxn,minn;}tree[100000]; il void push_up(ll rt) {tree[rt].sum=tree[rt<<1].sum+tree[rt<<1|1].sum; tree[rt].maxn=max(tree[rt<<1].maxn,tree[rt<<1|1].maxn); tree[rt].minn=min(tree[rt<<1].minn,tree[rt<<1|1].minn);} il void push_down(ll rt , ll length) {if(tree[rt].lazy){tree[rt<<1].lazy+=tree[rt].lazy;tree[rt<<1|1].lazy+=tree[rt].lazy; tree[rt<<1].sum+=(length-(length>>1))*tree[rt].lazy;tree[rt<<1|1].sum+=(length>>1)*tree[rt].lazy; tree[rt<<1].minn+=tree[rt].lazy;tree[rt<<1|1].minn+=tree[rt].lazy; tree[rt<<1].maxn+=tree[rt].lazy;tree[rt<<1|1].maxn+=tree[rt].lazy;tree[rt].lazy=0;}} il void build(ll l , ll r , ll rt , ll *aa) {tree[rt].lazy=0;tree[rt].l=l;tree[rt].r=r;if(l==r) {tree[rt].sum=aa[l];tree[rt].minn=tree[rt].sum;tree[rt].maxn=tree[rt].sum;return;} ll mid=(l+r)>>1;build(l,mid,rt<<1,aa);build(mid+1,r,rt<<1|1,aa);push_up(rt);} il void update_range(ll L , ll R , ll key , ll rt) {if(tree[rt].r<L||tree[rt].l>R)return;if(L<=tree[rt].l&&R>=tree[rt].r){tree[rt].sum+=(tree[rt].r-tree[rt].l+1)*key; tree[rt].minn+=key;tree[rt].maxn+=key;tree[rt].lazy+=key;return;}push_down(rt,tree[rt].r-tree[rt].l+1); ll mid=(tree[rt].r+tree[rt].l)>>1;if(L<=mid)update_range(L,R,key,rt << 1); if(R>mid)update_range(L,R,key,rt << 1 | 1);push_up(rt);} il ll query_range(ll L, ll R, ll rt) {if(L<=tree[rt].l&&R>=tree[rt].r){return tree[rt].sum;}push_down(rt,tree[rt].r-tree[rt].l+1); ll mid=(tree[rt].r+tree[rt].l)>>1;ll ans=0;if(L<=mid)ans+=query_range(L,R,rt << 1); if(R>mid)ans+=query_range(L,R,rt << 1 | 1);return ans;} il ll query_min(ll L,ll R,ll rt) {if(L<=tree[rt].l&&R>=tree[rt].r){return tree[rt].minn;}push_down(rt,tree[rt].r-tree[rt].l+1); ll mid=(tree[rt].r+tree[rt].l)>>1;ll ans=(0x3f3f3f3f3f3f3f3fll);if(L<=mid)ans=min(ans,query_min(L,R,rt << 1)); if(R>mid)ans=min(ans,query_min(L,R,rt << 1 | 1));return ans;} il ll query_max(ll L, ll R, ll rt) {if(L<=tree[rt].l&&R>=tree[rt].r){return tree[rt].maxn;}push_down(rt,tree[rt].r-tree[rt].l+1); ll mid=(tree[rt].r+tree[rt].l)>>1;ll ans=-(0x3f3f3f3f3f3f3f3fll);if(L<=mid)ans=max(ans,query_max(L,R,rt << 1)); if(R>mid)ans=max(ans,query_max(L,R,rt << 1 | 1));return ans;} namespace linear_seq{ typedef vector<ll> VI;const ll N=1e5+10,mod = 1e9 + 7; ll Rx[N],Ba[N],_c[N],_md[N];VI Md; ll PMD(ll a,ll b){ll Rx=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)Rx=Rx*a%mod;a=a*a%mod;}return Rx;} void MUL(ll *a,ll *b,ll k){repp(i,0,k+k)_c[i]=0;repp(i,0,k)if(a[i])repp(j,0,k)_c[i+j]=(_c[i+j]+a[i]*b[j])%mod; for(ll i=k+k-1;i>=k;i--)if(_c[i])repp(j,0,SZ(Md))_c[i-k+Md[j]]=(_c[i-k+Md[j]]-_c[i]*_md[Md[j]])%mod; repp(i,0,k)a[i]=_c[i];}ll Solve(ll n,VI a,VI b){ll ans=0,pnt=0,k=a.size();assert(SZ(a)==SZ(b)); repp(i,0,k)_md[k-1-i]=-a[i];_md[k]=1;Md.clear();repp(i,0,k)if(_md[i]!=0)Md.push_back(i);repp(i,0,k)Rx[i]=Ba[i]=0; Rx[0]=1;while((1ll<<pnt)<=n)pnt++;for(ll p=pnt;p>=0;p--){MUL(Rx,Rx,k);if((n>>p)&1){for(ll i=k-1;i>=0;i--)Rx[i+1]=Rx[i]; Rx[0]=0;repp(j,0,SZ(Md))Rx[Md[j]]=(Rx[Md[j]]-Rx[k]*_md[Md[j]])%mod;}}repp(i,0,k) ans=(ans+Rx[i]*b[i])%mod; if(ans<0)ans+=mod;return ans;}VI BM(VI s){VI C(1,1),B(1,1);ll L=0,m=1,b=1;repp(n,0,SZ(s)){ll d=0; repp(i,0,L+1)d=(d+(ll)C[i]*s[n-i])%mod;if(d==0)++m;else if(2*L<=n){VI T=C;ll c=mod-d*PMD(b,mod-2)%mod; while(SZ(C)<SZ(B)+m)C.push_back(0);repp(i,0,SZ(B))C[i+m]=(C[i+m]+c*B[i])%mod;L=n+1-L;B=T;b=d;m=1;} else{ll c=mod-d*PMD(b,mod-2)%mod;while(SZ(C)<SZ(B)+m)C.push_back(0); repp(i,0,SZ(B))C[i+m]=(C[i+m]+c*B[i])%mod;++m;}}return C;} ll Gao(VI a,ll n){VI c=BM(a);c.erase(c.begin());n--;repp(i,0,SZ(c))c[i]=(mod-c[i])%mod; return Solve(n,c,VI(a.begin(),a.begin()+SZ(c)));}}; */ const int N = 1e6 + 10; struct Edge { int nex, to; } edge[N << 1]; int head[N], TOT; void add_edge(int u, int v) { edge[++TOT].nex = head[u]; edge[TOT].to = v; head[u] = TOT; } int a[N]; int cnt[N]; signed main() { ios; cin.tie(0), cout.tie(0); int n; cin >> n; rep(i, 1, n) cin >> a[i]; rep(i, 1, n) { int x = a[i]; for (int j = 2; j * j <= x; j++) { if (x % j == 0) { while (x % j == 0) x /= j; cnt[j]++; } } if (x > 1) cnt[x]++; } int g = a[1], flag = 0; rep(i, 1, N - 10) if (cnt[i] > 1) flag = 1; if (!flag) return cout << "pairwise coprime\n", 0; rep(i, 2, n) g = gcd(g, a[i]); if (g == 1) cout << "setwise coprime\n"; else cout << "not coprime\n"; return 0; }
replace
278
280
278
279
TLE
p02574
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <stdio.h> using namespace std; #include <vector> #define rep(i, n) for (ll i = 0; i < (n); i++) #define INF 1e9 #define llINF 1e18 #define base10_4 10000 // 1e4 #define base10_5 100000 // 1e5 #define base10_6 1000000 // 1e6 #define base10_7 10000000 // 1e7 #define base10_8 100000000 // 1e8 #define base10_9 1000000000 // 1e9 #define MOD 1000000007 #define pb push_back #define ll long long #define ld long double #define ull unsigned long long #define vint vector<int> #define vll vector<ll> // #include <stack> // #include <queue> // #include <iomanip> // cout << fixed << setprecision(15) << y << endl; string ans_Yes = "Yes"; string ans_No = "No"; string ans_yes = "yes"; string ans_no = "no"; vll A; ll B; ll C; ll N; ll M; ll K; ll ltmp; string stmp; double dtmp; vector<ll> prime_numbers; void getPrimeNumbers(ll n_max) { bool is_prime[n_max + 1]; for (ll ni = 0; ni <= n_max; ni++) { is_prime[ni] = true; } is_prime[0] = is_prime[1] = false; for (ll number = 2; number <= n_max; number++) { if (is_prime[number]) { prime_numbers.push_back(number); for (ll ni = number * 2; ni <= n_max; ni += number) { is_prime[ni] = false; } } } } ll llmin(ll a, ll b) { if (a >= b) return b; return a; } ll llmax(ll a, ll b) { if (a <= b) return b; return a; } /* max 448,000,000 map<string,ll> count_map; count_map['0']=0; for(auto x : count_map) { string key = x.first; ll value = x.second; } */ map<ll, ll> count_map; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> N; rep(ni, N) { cin >> ltmp; A.push_back(ltmp); count_map[ltmp]++; } sort(A.begin(), A.end()); getPrimeNumbers(A[N - 1] + 1); ll cnt_max = 0; // cout << prime_numbers.size() << endl; rep(pi, prime_numbers.size()) { ll cnt = 0; ll p0 = prime_numbers[pi]; for (ll pval = p0; pval <= A[N - 1]; pval += p0) { cnt += count_map[pval]; } cnt_max = llmax(cnt_max, cnt); // if(cnt_max==N) break; // else if(cnt_max>1 && ji_start>0) break; } if (cnt_max == N) cout << "not coprime" << endl; else if (cnt_max > 1) cout << "setwise coprime" << endl; else cout << "pairwise coprime" << endl; }
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <stdio.h> using namespace std; #include <vector> #define rep(i, n) for (ll i = 0; i < (n); i++) #define INF 1e9 #define llINF 1e18 #define base10_4 10000 // 1e4 #define base10_5 100000 // 1e5 #define base10_6 1000000 // 1e6 #define base10_7 10000000 // 1e7 #define base10_8 100000000 // 1e8 #define base10_9 1000000000 // 1e9 #define MOD 1000000007 #define pb push_back #define ll long long #define ld long double #define ull unsigned long long #define vint vector<int> #define vll vector<ll> // #include <stack> // #include <queue> // #include <iomanip> // cout << fixed << setprecision(15) << y << endl; string ans_Yes = "Yes"; string ans_No = "No"; string ans_yes = "yes"; string ans_no = "no"; vll A; ll B; ll C; ll N; ll M; ll K; ll ltmp; string stmp; double dtmp; vector<ll> prime_numbers; void getPrimeNumbers(ll n_max) { bool is_prime[n_max + 1]; for (ll ni = 0; ni <= n_max; ni++) { is_prime[ni] = true; } is_prime[0] = is_prime[1] = false; for (ll number = 2; number <= n_max; number++) { if (is_prime[number]) { prime_numbers.push_back(number); for (ll ni = number * 2; ni <= n_max; ni += number) { is_prime[ni] = false; } } } } ll llmin(ll a, ll b) { if (a >= b) return b; return a; } ll llmax(ll a, ll b) { if (a <= b) return b; return a; } /* max 448,000,000 map<string,ll> count_map; count_map['0']=0; for(auto x : count_map) { string key = x.first; ll value = x.second; } */ map<ll, ll> count_map; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> N; rep(ni, N) { cin >> ltmp; A.push_back(ltmp); count_map[ltmp]++; } sort(A.begin(), A.end()); getPrimeNumbers(A[N - 1] + 1); ll cnt_max = 0; // cout << prime_numbers.size() << endl; rep(pi, prime_numbers.size()) { ll cnt = 0; ll p0 = prime_numbers[pi]; for (ll pval = p0; pval <= A[N - 1]; pval += p0) { cnt += count_map[pval]; } cnt_max = llmax(cnt_max, cnt); if (cnt_max == N) break; else if (cnt_max > 1 && p0 > A[0]) break; } if (cnt_max == N) cout << "not coprime" << endl; else if (cnt_max > 1) cout << "setwise coprime" << endl; else cout << "pairwise coprime" << endl; }
replace
111
113
111
115
TLE
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define mem(a, b) memset(a, b, sizeof(a)) typedef long long LL; typedef pair<int, int> PII; #define X first #define Y second inline int read() { int x = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } return x * f; } const int maxN = 100000; int n, a[maxN + 10], have[maxN + 10]; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int isn[maxN + 10], prime[maxN + 10], len, GCD; bool vis[maxN + 10]; void init() { for (int i = 2; i <= maxN; i++) { if (!vis[i]) prime[++len] = i, isn[i] = i; for (int j = 1; j <= len; j++) { if (i * prime[j] > maxN) break; vis[i * prime[j]] = 1; isn[i * prime[j]] = prime[j]; if (i % prime[j] == 0) { break; } } } // for(int i=2;i<=100;i++)printf("%d %d\n",i,isn[i]); } int main() { init(); n = read(); a[1] = read(); GCD = a[1]; for (int i = 2; i <= n; i++) a[i] = read(), GCD = gcd(GCD, a[i]); if (GCD != 1) return puts("not coprime"), 0; for (int i = 1; i <= n; i++) { int tmp = a[i]; while (tmp > 1) { int h = isn[tmp]; have[isn[tmp]]++; if (have[isn[tmp]] > 1) return puts("setwise coprime"), 0; while (isn[tmp] == h) tmp /= isn[tmp]; } } puts("pairwise coprime"); return 0; } /* */
#include <bits/stdc++.h> using namespace std; #define mem(a, b) memset(a, b, sizeof(a)) typedef long long LL; typedef pair<int, int> PII; #define X first #define Y second inline int read() { int x = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } return x * f; } const int maxN = 1000000; int n, a[maxN + 10], have[maxN + 10]; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int isn[maxN + 10], prime[maxN + 10], len, GCD; bool vis[maxN + 10]; void init() { for (int i = 2; i <= maxN; i++) { if (!vis[i]) prime[++len] = i, isn[i] = i; for (int j = 1; j <= len; j++) { if (i * prime[j] > maxN) break; vis[i * prime[j]] = 1; isn[i * prime[j]] = prime[j]; if (i % prime[j] == 0) { break; } } } // for(int i=2;i<=100;i++)printf("%d %d\n",i,isn[i]); } int main() { init(); n = read(); a[1] = read(); GCD = a[1]; for (int i = 2; i <= n; i++) a[i] = read(), GCD = gcd(GCD, a[i]); if (GCD != 1) return puts("not coprime"), 0; for (int i = 1; i <= n; i++) { int tmp = a[i]; while (tmp > 1) { int h = isn[tmp]; have[isn[tmp]]++; if (have[isn[tmp]] > 1) return puts("setwise coprime"), 0; while (isn[tmp] == h) tmp /= isn[tmp]; } } puts("pairwise coprime"); return 0; } /* */
replace
21
22
21
22
0
p02574
C++
Runtime Error
// K-OS WITH THE OCDE #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long int ll; typedef long double db; #define TEST \ ll t; \ cin >> t; \ while (t--) #define vell vector<ll> #define pl pair<ll, ll> #define all(v) v.begin(), v.end() #define pb push_back #define ff first #define ss second #define mp make_pair #define dbg(x) cerr << #x << ": " << x << endl #define dbg2(x, y) cerr << #x << ": " << x << " || " << #y << ": " << y << endl #define endl "\n" #define MAX 1e18 #define MIN INT_MIN #define mod 1000000007 void solve() { ll n; cin >> n; ll a[n], g = 0; vell f(100000, 0); bool ok = true; for (ll i = 0; i < n; ++i) { cin >> a[i]; g = __gcd(g, a[i]); ll x = a[i]; for (ll j = 2; j * j <= x; ++j) { ll c = 0; while (x % j == 0) { c++; x /= j; } if (c > 0) { if (f[j] > 0) { ok = false; } f[j] += c; } } if (x > 1) { if (f[x] > 0) ok = false; f[x]++; } } if (ok) { cout << "pairwise coprime"; return; } if (g == 1) { cout << "setwise coprime"; return; } cout << "not coprime"; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); // TEST solve(); }
// K-OS WITH THE OCDE #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long int ll; typedef long double db; #define TEST \ ll t; \ cin >> t; \ while (t--) #define vell vector<ll> #define pl pair<ll, ll> #define all(v) v.begin(), v.end() #define pb push_back #define ff first #define ss second #define mp make_pair #define dbg(x) cerr << #x << ": " << x << endl #define dbg2(x, y) cerr << #x << ": " << x << " || " << #y << ": " << y << endl #define endl "\n" #define MAX 1e18 #define MIN INT_MIN #define mod 1000000007 void solve() { ll n; cin >> n; ll a[n], g = 0; vell f(1000002, 0); bool ok = true; for (ll i = 0; i < n; ++i) { cin >> a[i]; g = __gcd(g, a[i]); ll x = a[i]; for (ll j = 2; j * j <= x; ++j) { ll c = 0; while (x % j == 0) { c++; x /= j; } if (c > 0) { if (f[j] > 0) { ok = false; } f[j] += c; } } if (x > 1) { if (f[x] > 0) ok = false; f[x]++; } } if (ok) { cout << "pairwise coprime"; return; } if (g == 1) { cout << "setwise coprime"; return; } cout << "not coprime"; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); // TEST solve(); }
replace
57
58
57
58
-11
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; // const long long MOD = 998244353; const long long INF_LL = 1e18 + 11; const int INF_int = 1e9 + 11; #define ll long long #define mp std::make_pair #define rep(i, n) for (int i = 0; i < n; i++) #define lrep(i, n) for (long long i = 0; i < n; i++) #define All(a) a.begin(), a.end() #define Debug_Output_ALL(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl; // 最大公約数 long long gcd(long long a, long long b) { if (a < b) swap(a, b); while (a % b != 0) { swap(a, b); b = b % a; } return b; } vector<ll> makeprimes(long n) { bool judge[n + 1]; for (int i = 0; i <= n; i++) { judge[i] = true; } vector<ll> prime; for (int i = 2; i <= n; i++) { if (judge[i]) { for (int j = 2 * i; j <= n; j += i) { judge[j] = false; } prime.push_back(i); // ここでprimeに入れられる素数の条件を指定できる } } return prime; } int main() { int n; cin >> n; vector<ll> a; rep(i, n) { ll b; cin >> b; a.push_back(b); } ll t = a[0]; for (int i = 1; i < n; i++) t = gcd(t, a[i]); if (t != 1) { cout << "not coprime" << endl; return 0; } vector<ll> primes = makeprimes(1003); int s = primes.size(); vector<int> vec(s); fill(All(vec), 0); bool fl = true; set<int> st; rep(i, n) { rep(j, s) { ll now = primes[j]; if (a[i] % now == 0) vec[i]++; while (a[i] % now == 0) { a[i] /= now; } } if (st.empty()) st.insert(a[i]); else if (a[i] != 1) { if (st.count(a[i]) != 0) { fl = false; } else { st.insert(a[i]); } } } rep(i, s) { if (vec[i] >= 2) fl = false; } if (fl) cout << "pairwise coprime" << endl; else cout << "setwise coprime" << endl; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; // const long long MOD = 998244353; const long long INF_LL = 1e18 + 11; const int INF_int = 1e9 + 11; #define ll long long #define mp std::make_pair #define rep(i, n) for (int i = 0; i < n; i++) #define lrep(i, n) for (long long i = 0; i < n; i++) #define All(a) a.begin(), a.end() #define Debug_Output_ALL(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl; // 最大公約数 long long gcd(long long a, long long b) { if (a < b) swap(a, b); while (a % b != 0) { swap(a, b); b = b % a; } return b; } vector<ll> makeprimes(long n) { bool judge[n + 1]; for (int i = 0; i <= n; i++) { judge[i] = true; } vector<ll> prime; for (int i = 2; i <= n; i++) { if (judge[i]) { for (int j = 2 * i; j <= n; j += i) { judge[j] = false; } prime.push_back(i); // ここでprimeに入れられる素数の条件を指定できる } } return prime; } int main() { int n; cin >> n; vector<ll> a; rep(i, n) { ll b; cin >> b; a.push_back(b); } ll t = a[0]; for (int i = 1; i < n; i++) t = gcd(t, a[i]); if (t != 1) { cout << "not coprime" << endl; return 0; } vector<ll> primes = makeprimes(1003); int s = primes.size(); vector<int> vec(s); fill(All(vec), 0); bool fl = true; set<int> st; rep(i, n) { rep(j, s) { ll now = primes[j]; if (a[i] % now == 0) vec[j]++; while (a[i] % now == 0) { a[i] /= now; } } if (st.empty()) st.insert(a[i]); else if (a[i] != 1) { if (st.count(a[i]) != 0) { fl = false; } else { st.insert(a[i]); } } } rep(i, s) { if (vec[i] >= 2) fl = false; } if (fl) cout << "pairwise coprime" << endl; else cout << "setwise coprime" << endl; }
replace
67
68
67
68
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define pb push_back #define f(i, n) for (int i = 0; i < n; ++i) #define fi(i, st, n) for (int i = st; i <= n; ++i) #define veci vector<int> #define vecp vector<pair<int, int>> #define vecl vector<ll> int prime[1000000 + 10]; ll lcm(ll a, ll b) { return a * b / __gcd(a, b); } ll power(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) { res = (res * a) % mod; } a = (a * a) % mod; n = n / 2; } return res; } ll sum(int arr[], int n) { ll res = 0; f(i, n) { res += arr[i]; } return res; } void seive() { prime[1] = 0; for (int i = 2; i <= 1000000; i++) { prime[i] = 1; } for (ll i = 2; i <= 1000000; i++) { if (prime[i] == 1) { for (ll j = 2 * i; j <= 1000000; j += i) { prime[j] = i; } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin>>t; while (t--) { int n; cin >> n; int arr[n]; f(i, n) cin >> arr[i]; int ans = 0; f(i, n) ans = __gcd(ans, arr[i]); if (ans > 1) { cout << "not coprime\n"; } else { int c = 0; f(i, n) if (arr[i] == 1) c++; if (n > 100000 + c) { cout << "setwise coprime\n"; } else { int flag = 0; sort(arr, arr + n); int check[100000 + 10] = {0}; for (int i = 0; i < n; i++) { int temp = arr[i]; if (temp != 1) { for (int j = 2; j <= sqrt(arr[i]); j++) { if (temp % j == 0) { if (check[j] or check[temp / j]) { flag = 1; break; } check[j] = 1; check[temp / j] = 1; } } if (flag) break; if (check[arr[i]]) { flag = 1; break; } check[arr[i]] = 1; } } if (flag) cout << "setwise coprime\n"; else cout << "pairwise coprime\n"; } } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define pb push_back #define f(i, n) for (int i = 0; i < n; ++i) #define fi(i, st, n) for (int i = st; i <= n; ++i) #define veci vector<int> #define vecp vector<pair<int, int>> #define vecl vector<ll> int prime[1000000 + 10]; ll lcm(ll a, ll b) { return a * b / __gcd(a, b); } ll power(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) { res = (res * a) % mod; } a = (a * a) % mod; n = n / 2; } return res; } ll sum(int arr[], int n) { ll res = 0; f(i, n) { res += arr[i]; } return res; } void seive() { prime[1] = 0; for (int i = 2; i <= 1000000; i++) { prime[i] = 1; } for (ll i = 2; i <= 1000000; i++) { if (prime[i] == 1) { for (ll j = 2 * i; j <= 1000000; j += i) { prime[j] = i; } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin>>t; while (t--) { int n; cin >> n; int arr[n]; f(i, n) cin >> arr[i]; int ans = 0; f(i, n) ans = __gcd(ans, arr[i]); if (ans > 1) { cout << "not coprime\n"; } else { int c = 0; f(i, n) if (arr[i] == 1) c++; if (n > 100000 + c) { cout << "setwise coprime\n"; } else { int flag = 0; sort(arr, arr + n); int check[1000000 + 10] = {0}; for (int i = 0; i < n; i++) { int temp = arr[i]; if (temp != 1) { for (int j = 2; j <= sqrt(arr[i]); j++) { if (temp % j == 0) { if (check[j] or check[temp / j]) { flag = 1; break; } check[j] = 1; check[temp / j] = 1; } } if (flag) break; if (check[arr[i]]) { flag = 1; break; } check[arr[i]] = 1; } } if (flag) cout << "setwise coprime\n"; else cout << "pairwise coprime\n"; } } } return 0; }
replace
69
70
69
70
0
p02574
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; // #define int long long #define rep(i, a) for (int i = 0; i < (a); i++) #define repd(i, a) for (int i = (a)-1; i >= 0; i--) #define reps(i, a, j) for (int i = (j); i < (a); i++) #define deb(x) cout << #x << " " << x << endl; #define debs(x) cout << #x << " " << x << " "; #define deba(x) \ for (auto _i : x) \ cout << _i << " "; \ cout << endl; #define ms(a) memset(a, 0, sizeof(a)); #define mp make_pair #define eb emplace_back #define pii pair<int, int> #define all(a) a.begin(), a.end() int gcd(int x, int y) { int t; while (x % y) t = x, x = y, y = t % y; return y; } const int N = 1e6 + 1; bool prime[N + 10]; vector<int> k; bool present[N + 10]; void sieve() { memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= N; p++) { if (prime[p] == true) { for (int i = p * p; i <= N; i += p) { prime[i] = false; } } } for (int p = 2; p <= N; p++) if (prime[p]) k.eb(p); } bool pairwisecoprime(int arr[], int n) { repd(i, n) { int val = arr[i]; if (present[val] == true && val != 1) { return false; } for (auto x : k) { if (val % x == 0) { if (present[x] == true) return false; present[x] = true; while (val % x == 0) { present[val] = true; val /= x; } } if (val == 1) break; } } return true; } bool setwisecoprime(int arr[], int n) { int g = arr[0]; reps(i, n, 1) { g = gcd(g, arr[i]); if (g == 1) break; } if (g == 1) return true; else return false; } void solve() { sieve(); int n; cin >> n; int arr[n]; rep(i, n) cin >> arr[i]; if (pairwisecoprime(arr, n)) { cout << "pairwise coprime" << endl; } else if (setwisecoprime(arr, n)) { cout << "setwise coprime" << endl; } else { cout << "not coprime" << endl; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; t = 1; while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; // #define int long long #define rep(i, a) for (int i = 0; i < (a); i++) #define repd(i, a) for (int i = (a)-1; i >= 0; i--) #define reps(i, a, j) for (int i = (j); i < (a); i++) #define deb(x) cout << #x << " " << x << endl; #define debs(x) cout << #x << " " << x << " "; #define deba(x) \ for (auto _i : x) \ cout << _i << " "; \ cout << endl; #define ms(a) memset(a, 0, sizeof(a)); #define mp make_pair #define eb emplace_back #define pii pair<int, int> #define all(a) a.begin(), a.end() int gcd(int x, int y) { int t; while (x % y) t = x, x = y, y = t % y; return y; } const int N = 1e6 + 1; bool prime[N + 10]; vector<int> k; bool present[N + 10]; void sieve() { memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= N; p++) { if (prime[p] == true) { for (int i = p * p; i <= N; i += p) { prime[i] = false; } } } for (int p = 2; p <= N; p++) if (prime[p]) k.eb(p); } bool pairwisecoprime(int arr[], int n) { repd(i, n) { int val = arr[i]; if (present[val] == true && val != 1) { return false; } for (auto x : k) { if (prime[val] == true) { if (present[val] == true) { return false; } else { if (val != 1) present[val] = true; break; } } if (val % x == 0) { if (present[x] == true) return false; present[x] = true; while (val % x == 0) { present[val] = true; val /= x; } } if (val == 1) break; } } return true; } bool setwisecoprime(int arr[], int n) { int g = arr[0]; reps(i, n, 1) { g = gcd(g, arr[i]); if (g == 1) break; } if (g == 1) return true; else return false; } void solve() { sieve(); int n; cin >> n; int arr[n]; rep(i, n) cin >> arr[i]; if (pairwisecoprime(arr, n)) { cout << "pairwise coprime" << endl; } else if (setwisecoprime(arr, n)) { cout << "setwise coprime" << endl; } else { cout << "not coprime" << endl; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; t = 1; while (t--) solve(); }
insert
52
52
52
61
TLE
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define BIT(n) (1LL << (n)) #define BITF(n, i) (((n) >> (i)) & 1) #define REP(i, n) for (int i = 0; i < n; i++) #define FOR(i, m, n) for (int i = m; i < n; i++) #define REPI(i, x) for (int i = 1; i <= x; i++) #define FORI(i, m, n) for (int i = m; i <= n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define REPZ(i, x) for (int i = 0; i <= x; i++) #define FORA(i, n) for (auto &&i : n) #define POW(a, b) ((int)(pow(a, b) + .5)) #define MODULO(a, b) (((a) % (b)) < 0 ? (a) % (b) + (b) : (a) % (b)) #define DUMPOUT cerr // vector template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } // pair template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // vector template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "{"; REP(i, (int)vec.size()) os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", "); os << "}"; return os; } // map template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { os << "{"; FORA(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { os << "{"; FORA(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) DUMPOUT << ", "; dump_func(std::move(tail)...); } #ifdef DEBUG_ #define DEB #define DUMP(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #define PRINTARR(x, y) \ cerr << #x << "=\n"; \ for (auto itr = x; itr != y; itr++) \ cerr << *itr << " "; \ cerr << endl; #define PRINTARR2(x, i0, i1) \ cerr << #x << "=\n"; \ for (int ii0 = 0; ii0 < i0; ii0++) { \ for (int ii1 = 0; ii1 < i1; ii1++) \ cerr << x[ii0][ii1] << " "; \ cerr << endl; \ } #else #define DEB if (false) #define DUMP(...) #define PRINTARR(x, y) #define PRINTARR2(x, i0, i1) #endif #define ALL(v) v.begin(), v.end() #define fst first #define snd second #define mp make_pair #define pb push_back #define epb emplace_back #define int long long #define pint pair<int, int> #define pdouble pair<double, double> #define ld long double using namespace std; 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; } template <class T> using vec = std::vector<T>; template <class T> void print(const T &x) { cout << x << "\n"; } const int MOD = 1000000007, INF0 = 1061109567, INF = INF0 * INF0; const double EPS = 1e-7, PI = acos(-1.0); const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; /* [&] { return; }();下のスラッシュを2つ追加しただけ.上のスラッシュを2つにすれば外れる. //*/ #define MAXN 200100 #define MAXQ 1010 bool isPrime[(MAXQ + 1)]; int pList[(MAXQ + 1)]; int sizeP; // global void calcP() { sizeP = 0; fill(isPrime, isPrime + MAXQ + 1, true); isPrime[0] = isPrime[1] = false; for (int i = 2; i <= MAXQ; ++i) { if (isPrime[i]) { pList[sizeP++] = i; for (int j = i * 1LL * i; j <= MAXQ; j += i) { isPrime[j] = false; } } } } // 素因数分解 map<int, int> factorizeVal(int val) { map<int, int> ma; for (int i = 0; i < sizeP; i++) { int cnt = 0; int primeV = pList[i]; while (val % primeV == 0) { val /= primeV; cnt++; } if (cnt) { ma[primeV] += cnt; } if (val == 1) break; } if (val != 1) { ma[val]++; } return ma; } int a[MAXN]; signed main() { cin.tie(0), ios::sync_with_stdio(false); cout << fixed << setprecision(12); int N; cin >> N; REP(i, N) cin >> a[i]; calcP(); int ret = a[0]; REP(i, N - 1) { ret = __gcd(a[i + 1], ret); } map<int, int> ma2; REP(i, N) { map<int, int> ma = factorizeVal(a[i]); FORA(e, ma) { ma2[e.fst] += 1; DUMP(e.fst, e.snd); } } bool flg = true; FORA(e, ma2) { DUMP(e.fst, e.snd); flg = flg && e.snd == 1; } if (flg) { print("pairwise coprime"); } else { if (ret == 1) { print("setwise coprime"); } else { print("not coprime"); } } }
#include <bits/stdc++.h> using namespace std; #define BIT(n) (1LL << (n)) #define BITF(n, i) (((n) >> (i)) & 1) #define REP(i, n) for (int i = 0; i < n; i++) #define FOR(i, m, n) for (int i = m; i < n; i++) #define REPI(i, x) for (int i = 1; i <= x; i++) #define FORI(i, m, n) for (int i = m; i <= n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define REPZ(i, x) for (int i = 0; i <= x; i++) #define FORA(i, n) for (auto &&i : n) #define POW(a, b) ((int)(pow(a, b) + .5)) #define MODULO(a, b) (((a) % (b)) < 0 ? (a) % (b) + (b) : (a) % (b)) #define DUMPOUT cerr // vector template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } // pair template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // vector template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "{"; REP(i, (int)vec.size()) os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", "); os << "}"; return os; } // map template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { os << "{"; FORA(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { os << "{"; FORA(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) DUMPOUT << ", "; dump_func(std::move(tail)...); } #ifdef DEBUG_ #define DEB #define DUMP(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #define PRINTARR(x, y) \ cerr << #x << "=\n"; \ for (auto itr = x; itr != y; itr++) \ cerr << *itr << " "; \ cerr << endl; #define PRINTARR2(x, i0, i1) \ cerr << #x << "=\n"; \ for (int ii0 = 0; ii0 < i0; ii0++) { \ for (int ii1 = 0; ii1 < i1; ii1++) \ cerr << x[ii0][ii1] << " "; \ cerr << endl; \ } #else #define DEB if (false) #define DUMP(...) #define PRINTARR(x, y) #define PRINTARR2(x, i0, i1) #endif #define ALL(v) v.begin(), v.end() #define fst first #define snd second #define mp make_pair #define pb push_back #define epb emplace_back #define int long long #define pint pair<int, int> #define pdouble pair<double, double> #define ld long double using namespace std; 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; } template <class T> using vec = std::vector<T>; template <class T> void print(const T &x) { cout << x << "\n"; } const int MOD = 1000000007, INF0 = 1061109567, INF = INF0 * INF0; const double EPS = 1e-7, PI = acos(-1.0); const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; /* [&] { return; }();下のスラッシュを2つ追加しただけ.上のスラッシュを2つにすれば外れる. //*/ #define MAXN 1000100 #define MAXQ 1010 bool isPrime[(MAXQ + 1)]; int pList[(MAXQ + 1)]; int sizeP; // global void calcP() { sizeP = 0; fill(isPrime, isPrime + MAXQ + 1, true); isPrime[0] = isPrime[1] = false; for (int i = 2; i <= MAXQ; ++i) { if (isPrime[i]) { pList[sizeP++] = i; for (int j = i * 1LL * i; j <= MAXQ; j += i) { isPrime[j] = false; } } } } // 素因数分解 map<int, int> factorizeVal(int val) { map<int, int> ma; for (int i = 0; i < sizeP; i++) { int cnt = 0; int primeV = pList[i]; while (val % primeV == 0) { val /= primeV; cnt++; } if (cnt) { ma[primeV] += cnt; } if (val == 1) break; } if (val != 1) { ma[val]++; } return ma; } int a[MAXN]; signed main() { cin.tie(0), ios::sync_with_stdio(false); cout << fixed << setprecision(12); int N; cin >> N; REP(i, N) cin >> a[i]; calcP(); int ret = a[0]; REP(i, N - 1) { ret = __gcd(a[i + 1], ret); } map<int, int> ma2; REP(i, N) { map<int, int> ma = factorizeVal(a[i]); FORA(e, ma) { ma2[e.fst] += 1; DUMP(e.fst, e.snd); } } bool flg = true; FORA(e, ma2) { DUMP(e.fst, e.snd); flg = flg && e.snd == 1; } if (flg) { print("pairwise coprime"); } else { if (ret == 1) { print("setwise coprime"); } else { print("not coprime"); } } }
replace
128
129
128
129
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define INIT \ ios_base ::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); \ mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define mp make_pair #define pb push_back #define ft first #define sc second #define ll long long #define pii pair<int, int> #define count_bits __builtin_popcount #define int ll int t, n, m, k, a[300010], q, l, r; bool v[1000010]; int cnt[1000010]; int32_t main() { INIT cin >> n; int sgcd = 0; bool sw = false, pw = true; for (int i = 1; i <= n; i++) { cin >> a[i]; cnt[a[i]]++; sgcd = __gcd(sgcd, a[i]); } if (sgcd == 1) { sw = true; } for (int i = 2; i <= 1000000; i++) { if (!v[i]) { int c = 0; c += cnt[i]; for (int j = 2 * i; j <= 1000000; j += i) { v[j] = true; c += cnt[j]; } if (c > 1) { pw = false; break; } } } if (pw) { cout << "pairwise coprime"; } else { if (sw) { cout << "setwise coprime"; } else { cout << "not coprime"; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define INIT \ ios_base ::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); \ mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define mp make_pair #define pb push_back #define ft first #define sc second #define ll long long #define pii pair<int, int> #define count_bits __builtin_popcount #define int ll int t, n, m, k, a[1000010], q, l, r; bool v[1000010]; int cnt[1000010]; int32_t main() { INIT cin >> n; int sgcd = 0; bool sw = false, pw = true; for (int i = 1; i <= n; i++) { cin >> a[i]; cnt[a[i]]++; sgcd = __gcd(sgcd, a[i]); } if (sgcd == 1) { sw = true; } for (int i = 2; i <= 1000000; i++) { if (!v[i]) { int c = 0; c += cnt[i]; for (int j = 2 * i; j <= 1000000; j += i) { v[j] = true; c += cnt[j]; } if (c > 1) { pw = false; break; } } } if (pw) { cout << "pairwise coprime"; } else { if (sw) { cout << "setwise coprime"; } else { cout << "not coprime"; } } return 0; }
replace
16
17
16
17
0
p02574
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; bool br[2000000]; void siv() { memset(br, true, 2000000); int i, j; br[0] = false; br[1] = false; for (i = 2; i * i <= 2000000; i++) { if (br[i] == true) { for (j = i * i; j <= 2000000; j += i) { br[j] = false; } } } } int prime(int n) { int i, j; for (i = 2; i <= n; i++) { if (br[i] == true) { if (n % br[i] == 0) { return i; } } } } int main() { int n, i, j, gd; while (cin >> n) { siv(); vector<int> v; map<int, int> mp; int x, c = 0, z; for (i = 0; i < n; i++) { cin >> x; v.push_back(x); } gd = v[0]; for (i = 1; i < n; i++) { gd = __gcd(gd, v[i]); } if (gd != 1) { cout << "not coprime" << endl; } else { int p; int flag = 0; for (i = 0; i < n; i++) { p = v[i]; for (j = 2; j <= p; j++) { if (br[j] == true) { if (p % j == 0) { mp[j]++; } if (mp[j] > 1) { flag = 1; break; } } } } if (flag == 1) cout << "setwise coprime" << endl; else cout << "pairwise coprime" << endl; mp.clear(); } } }
#include <bits/stdc++.h> using namespace std; bool br[2000000]; void siv() { memset(br, true, 2000000); int i, j; br[0] = false; br[1] = false; for (i = 2; i * i <= 2000000; i++) { if (br[i] == true) { for (j = i * i; j <= 2000000; j += i) { br[j] = false; } } } } int prime(int n) { int i, j; for (i = 2; i <= n; i++) { if (br[i] == true) { if (n % br[i] == 0) { return i; } } } } int main() { int n, i, j, gd; while (cin >> n) { siv(); vector<int> v; map<int, int> mp; int x, c = 0, z; for (i = 0; i < n; i++) { cin >> x; v.push_back(x); } gd = v[0]; for (i = 1; i < n; i++) { gd = __gcd(gd, v[i]); } if (gd != 1) { cout << "not coprime" << endl; } else { int p; int flag = 0; for (i = 0; i < n; i++) { p = v[i]; if (br[p] == true) { mp[p]++; if (mp[p] > 1) { flag = 1; break; } } else { for (j = 2; j <= p; j++) { if (br[j] == true) { if (p % j == 0) { mp[j]++; } if (mp[j] > 1) { flag = 1; break; } } } } } if (flag == 1) cout << "setwise coprime" << endl; else cout << "pairwise coprime" << endl; mp.clear(); } } }
replace
49
58
49
65
TLE
p02574
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <numeric> #include <queue> #include <set> #include <string> #include <utility> #include <vector> typedef long long ll; using namespace std; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } struct Factorizer { int n; vector<int> minFactor; vector<bool> cnt; Factorizer(int max) { int i, j; n = max; minFactor.resize(n); cnt.resize(n, 0); iota(minFactor.begin(), minFactor.end(), 0); for (i = 2; i * i < n; i++) { if (minFactor[i] < i) continue; for (j = i * i; j < n; j += i) { if (minFactor[j] == j) minFactor[j] = i; } } } bool check(int x) { while (x > 1) { if (cnt[minFactor[x]]) return 1; else cnt[minFactor[x]] = 1; int t = minFactor[x]; while (x % t == 0) { x /= t; } } return 0; } }; int main(int argc, char *argv[]) { int n, i, s; cin >> n; Factorizer f(100001); vector<int> a(n); for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { if (f.check(a[i])) { break; } } if (i == n) { cout << "pairwise coprime" << endl; return 0; } int c = gcd(a[0], a[1]); for (i = 2; i < n; i++) { c = gcd(c, a[i]); if (c == 1) break; } if (c == 1) { cout << "setwise coprime" << endl; return 0; } cout << "not coprime" << endl; return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <numeric> #include <queue> #include <set> #include <string> #include <utility> #include <vector> typedef long long ll; using namespace std; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } struct Factorizer { int n; vector<int> minFactor; vector<bool> cnt; Factorizer(int max) { int i, j; n = max; minFactor.resize(n); cnt.resize(n, 0); iota(minFactor.begin(), minFactor.end(), 0); for (i = 2; i * i < n; i++) { if (minFactor[i] < i) continue; for (j = i * i; j < n; j += i) { if (minFactor[j] == j) minFactor[j] = i; } } } bool check(int x) { while (x > 1) { if (cnt[minFactor[x]]) return 1; else cnt[minFactor[x]] = 1; int t = minFactor[x]; while (x % t == 0) { x /= t; } } return 0; } }; int main(int argc, char *argv[]) { int n, i, s; cin >> n; Factorizer f(1000001); vector<int> a(n); for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { if (f.check(a[i])) { break; } } if (i == n) { cout << "pairwise coprime" << endl; return 0; } int c = gcd(a[0], a[1]); for (i = 2; i < n; i++) { c = gcd(c, a[i]); if (c == 1) break; } if (c == 1) { cout << "setwise coprime" << endl; return 0; } cout << "not coprime" << endl; return 0; }
replace
63
64
63
64
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define pb push_back #define mp make_pair #define ff first #define se second #define endl '\n' #define fd(n) fixed << setprecision(n) #define MAX 100000000000000000 #define MAXN 100050 #define mod 1000000007 #define pi 3.1415926535897932384626433 ll fun(ll x, ll y) { ll ans = 1; while (y > 0) { if (y % 2 == 1) { ans = ans * 1ll * x; ans = ans % mod; } y = y / 2; x = (x * 1ll * x) % mod; } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, i, flag = 0, j, x; ll prime[MAXN], prime1[MAXN]; memset(prime, 0, sizeof(prime)); memset(prime1, 0, sizeof(prime1)); for (i = 2; i < MAXN; i++) { if (prime[i] == 0) { for (j = i + i; j < MAXN; j += i) { prime[j] = 1; } } } cin >> n; ll a[n]; for (i = 0; i < n; i++) { cin >> a[i]; prime1[a[i]]++; } x = a[0]; for (i = 1; i < n; i++) { x = __gcd(x, a[i]); } if (x >= 2) { cout << "not coprime"; } else { ll count = 0; for (i = 2; i < MAXN; i++) { count = 0; for (j = i; j < MAXN; j += i) { count += prime1[j]; } if (count > 1) { flag = 1; } } if (flag == 0) { cout << "pairwise coprime"; } else { cout << "setwise coprime"; } } }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define pb push_back #define mp make_pair #define ff first #define se second #define endl '\n' #define fd(n) fixed << setprecision(n) #define MAX 100000000000000000 #define MAXN 1000050 #define mod 1000000007 #define pi 3.1415926535897932384626433 ll fun(ll x, ll y) { ll ans = 1; while (y > 0) { if (y % 2 == 1) { ans = ans * 1ll * x; ans = ans % mod; } y = y / 2; x = (x * 1ll * x) % mod; } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, i, flag = 0, j, x; ll prime[MAXN], prime1[MAXN]; memset(prime, 0, sizeof(prime)); memset(prime1, 0, sizeof(prime1)); for (i = 2; i < MAXN; i++) { if (prime[i] == 0) { for (j = i + i; j < MAXN; j += i) { prime[j] = 1; } } } cin >> n; ll a[n]; for (i = 0; i < n; i++) { cin >> a[i]; prime1[a[i]]++; } x = a[0]; for (i = 1; i < n; i++) { x = __gcd(x, a[i]); } if (x >= 2) { cout << "not coprime"; } else { ll count = 0; for (i = 2; i < MAXN; i++) { count = 0; for (j = i; j < MAXN; j += i) { count += prime1[j]; } if (count > 1) { flag = 1; } } if (flag == 0) { cout << "pairwise coprime"; } else { cout << "setwise coprime"; } } }
replace
12
13
12
13
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> /* #define int long long */ /* #define double long double */ #define rep(i, n) for (int i = 0; i < (int)n; i++) #define repa(i, s, n) for (int i = s; i < (int)n; i++) #define MOD 1000000007 using namespace std; using ll = long long; typedef vector<int> vi; typedef pair<int, int> P; #define rrep(i, a, b) for (int i = a; i >= b; i--) template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int A = 100005; signed main() { int n; cin >> n; vi a(n), c(A); rep(i, n) { cin >> a[i]; c[a[i]]++; } bool pc = true; for (int i = 2; i < A; i++) { int cnt = 0; for (int j = i; j < A; j += i) { cnt += c[j]; } if (cnt > 1) { pc = false; } } if (pc) { cout << "pairwise coprime" << endl; return 0; } int g = 0; rep(i, n) g = __gcd(g, a[i]); if (g == 1) { cout << "setwise coprime" << endl; return 0; } cout << "not coprime" << endl; }
#include <bits/stdc++.h> /* #define int long long */ /* #define double long double */ #define rep(i, n) for (int i = 0; i < (int)n; i++) #define repa(i, s, n) for (int i = s; i < (int)n; i++) #define MOD 1000000007 using namespace std; using ll = long long; typedef vector<int> vi; typedef pair<int, int> P; #define rrep(i, a, b) for (int i = a; i >= b; i--) template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int A = 1000005; signed main() { int n; cin >> n; vi a(n), c(A); rep(i, n) { cin >> a[i]; c[a[i]]++; } bool pc = true; for (int i = 2; i < A; i++) { int cnt = 0; for (int j = i; j < A; j += i) { cnt += c[j]; } if (cnt > 1) { pc = false; } } if (pc) { cout << "pairwise coprime" << endl; return 0; } int g = 0; rep(i, n) g = __gcd(g, a[i]); if (g == 1) { cout << "setwise coprime" << endl; return 0; } cout << "not coprime" << endl; }
replace
26
27
26
27
0
p02574
C++
Runtime Error
#include <algorithm> #include <cmath> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long const int mod = 1000000007; const int MOD = 998244353; const ll INF = 1000000000000000000; int A[1000010]; int cnt[1000010]; int gcd(int a, int b) { if (a < b) return gcd(b, a); if (b == 0) return a; else return gcd(b, a % b); } bool isPrime[1000010]; void set_prime() { for (int i = 1; i <= 1000000; i++) { isPrime[i] = true; } isPrime[0] = false; isPrime[1] = false; for (int i = 2; i * i <= 1000000; i++) { int j = 2; while (i * j <= 1000000) { isPrime[i * j] = false; j++; } } } int main() { set_prime(); vector<int> V; for (int i = 0; i < 1000010; i++) { if (isPrime[i]) V.push_back(i); } int N; // N = 10000000; cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } vector<int> B; for (int i = 0; i < N; i++) { if (A[i] != 1) B.push_back(A[i]); } bool pc = true; if (B.size() <= V.size()) { for (int i = 0; i < N; i++) { int tmp = B[i]; for (int j : V) { if (j * j > B[i]) break; bool first = true; while (tmp % j == 0) { if (first && cnt[j] >= 1) pc = false; cnt[j]++; first = false; tmp /= j; } } if (tmp > 1) { if (cnt[tmp] >= 1) pc = false; } cnt[tmp]++; } } else pc = false; if (pc) { cout << "pairwise coprime" << endl; return 0; } int GCD = A[0]; for (int i = 1; i < N; i++) { GCD = gcd(GCD, A[i]); } if (GCD == 1) cout << "setwise coprime" << endl; else cout << "not coprime" << endl; }
#include <algorithm> #include <cmath> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long const int mod = 1000000007; const int MOD = 998244353; const ll INF = 1000000000000000000; int A[1000010]; int cnt[1000010]; int gcd(int a, int b) { if (a < b) return gcd(b, a); if (b == 0) return a; else return gcd(b, a % b); } bool isPrime[1000010]; void set_prime() { for (int i = 1; i <= 1000000; i++) { isPrime[i] = true; } isPrime[0] = false; isPrime[1] = false; for (int i = 2; i * i <= 1000000; i++) { int j = 2; while (i * j <= 1000000) { isPrime[i * j] = false; j++; } } } int main() { set_prime(); vector<int> V; for (int i = 0; i < 1000010; i++) { if (isPrime[i]) V.push_back(i); } int N; // N = 10000000; cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } vector<int> B; for (int i = 0; i < N; i++) { if (A[i] != 1) B.push_back(A[i]); } bool pc = true; if (B.size() <= V.size()) { for (int i = 0; i < B.size(); i++) { int tmp = B[i]; for (int j : V) { if (j * j > B[i]) break; bool first = true; while (tmp % j == 0) { if (first && cnt[j] >= 1) pc = false; cnt[j]++; first = false; tmp /= j; } } if (tmp > 1) { if (cnt[tmp] >= 1) pc = false; } cnt[tmp]++; } } else pc = false; if (pc) { cout << "pairwise coprime" << endl; return 0; } int GCD = A[0]; for (int i = 1; i < N; i++) { GCD = gcd(GCD, A[i]); } if (GCD == 1) cout << "setwise coprime" << endl; else cout << "not coprime" << endl; }
replace
62
63
62
63
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define AC 0 int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, gcd = 0; cin >> n; vector<int> a(n), prime(n); bool p = 1; for (int i = 0; i < n; i++) { cin >> a[i]; int tmp = a[i]; for (int j = 2; 1ll * j * j <= tmp; j++) if (!(tmp % j)) { if (prime[j]) p = 0; prime[j] = 1; while (!(tmp % j)) tmp /= j; } if (tmp != 1) { if (prime[tmp]) p = 0; prime[tmp] = 1; } gcd = __gcd(gcd, a[i]); } if (p) cout << "pairwise coprime\n"; else if (gcd == 1) cout << "setwise coprime\n"; else cout << "not coprime\n"; return AC; }
#include <bits/stdc++.h> using namespace std; #define AC 0 int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, gcd = 0; cin >> n; vector<int> a(n), prime(1e6 + 1); bool p = 1; for (int i = 0; i < n; i++) { cin >> a[i]; int tmp = a[i]; for (int j = 2; 1ll * j * j <= tmp; j++) if (!(tmp % j)) { if (prime[j]) p = 0; prime[j] = 1; while (!(tmp % j)) tmp /= j; } if (tmp != 1) { if (prime[tmp]) p = 0; prime[tmp] = 1; } gcd = __gcd(gcd, a[i]); } if (p) cout << "pairwise coprime\n"; else if (gcd == 1) cout << "setwise coprime\n"; else cout << "not coprime\n"; return AC; }
replace
8
9
8
9
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> typedef long long ll; #define endl "\n" #define all(s) s.begin(), s.end() #define pb push_back #define uno unordered_map #define pi 3.1415926536 #define dig(a) fixed << setprecision(a) #define test(zz) \ int zz; \ cin >> zz; \ while (zz--) #define foreach(var, i) for (auto i = var.begin(); i != var.end(); i++) #define fast() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); ll power(ll a, ll n) { ll res = 1; while (n) { if (n % 2) { res *= a; } n >>= 1; a *= a; } return res; } ll powerm(ll a, ll n, ll m) { ll res = 1; while (n) { if (n % 2) { res = (res * a) % m; } n >>= 1; a = (a * a) % m; } return res; } using namespace std; const int M = 1e9 + 7; ll mod(ll x) { return ((x % M + M) % M); } ll add(ll a, ll b) { return mod(mod(a) + mod(b)); } ll mul(ll a, ll b) { return mod(mod(a) * mod(b)); } const int N = 100005; int main() { fast(); // test(t){} int n; cin >> n; vector<int> a(n), fact(N); for (int i = 0; i < n; i++) { cin >> a[i]; fact[a[i]]++; } bool f = true; for (int i = 2; i < N; i++) { int c = 0; for (int j = i; j < N; j += i) { c += fact[j]; } if (c > 1) { f = false; break; } } if (f) { cout << "pairwise coprime" << endl; return 0; } int g = 0; for (int i = 0; i < n; i++) { g = __gcd(g, a[i]); } if (g == 1) { cout << "setwise coprime" << endl; return 0; } cout << "not coprime" << endl; return 0; }
#include <bits/stdc++.h> typedef long long ll; #define endl "\n" #define all(s) s.begin(), s.end() #define pb push_back #define uno unordered_map #define pi 3.1415926536 #define dig(a) fixed << setprecision(a) #define test(zz) \ int zz; \ cin >> zz; \ while (zz--) #define foreach(var, i) for (auto i = var.begin(); i != var.end(); i++) #define fast() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); ll power(ll a, ll n) { ll res = 1; while (n) { if (n % 2) { res *= a; } n >>= 1; a *= a; } return res; } ll powerm(ll a, ll n, ll m) { ll res = 1; while (n) { if (n % 2) { res = (res * a) % m; } n >>= 1; a = (a * a) % m; } return res; } using namespace std; const int M = 1e9 + 7; ll mod(ll x) { return ((x % M + M) % M); } ll add(ll a, ll b) { return mod(mod(a) + mod(b)); } ll mul(ll a, ll b) { return mod(mod(a) * mod(b)); } const int N = 1000005; int main() { fast(); // test(t){} int n; cin >> n; vector<int> a(n), fact(N); for (int i = 0; i < n; i++) { cin >> a[i]; fact[a[i]]++; } bool f = true; for (int i = 2; i < N; i++) { int c = 0; for (int j = i; j < N; j += i) { c += fact[j]; } if (c > 1) { f = false; break; } } if (f) { cout << "pairwise coprime" << endl; return 0; } int g = 0; for (int i = 0; i < n; i++) { g = __gcd(g, a[i]); } if (g == 1) { cout << "setwise coprime" << endl; return 0; } cout << "not coprime" << endl; return 0; }
replace
44
45
44
45
0
p02574
C++
Runtime Error
#include <cstdio> #include <iostream> using namespace std; int sieve[1000002], cnt[1000002], a[1000002], n, m, i, j, g, t; int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } int main() { scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", a + i); if (a[i] > m) m = a[i]; if (g) g = gcd(g, a[i]); else g = a[0]; } if (g > 1) { printf("not coprime\n"); return 0; } for (i = 2; i <= m; i++) { if (sieve[i] == 0) { sieve[i] = i; for (j = i * i; j <= m; j += i) { if (sieve[j] == 0) sieve[j] = i; } } } for (i = 0; i < n; i++) { j = a[i]; while (j > 1) { t = sieve[j]; cnt[t]++; if (cnt[t] > 1) { printf("setwise coprime\n"); return 0; } while (j % t == 0) j /= t; } } printf("pairwise coprime\n"); return 0; }
#include <cstdio> #include <iostream> using namespace std; int sieve[1000002], cnt[1000002], a[1000002], n, m, i, j, g, t; int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } int main() { scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", a + i); if (a[i] > m) m = a[i]; if (g) g = gcd(g, a[i]); else g = a[0]; } if (g > 1) { printf("not coprime\n"); return 0; } for (i = 2; i <= m; i++) { if (sieve[i] == 0) { sieve[i] = i; if ((long long)i * i <= m) for (j = i * i; j <= m; j += i) { if (sieve[j] == 0) sieve[j] = i; } } } for (i = 0; i < n; i++) { j = a[i]; while (j > 1) { t = sieve[j]; cnt[t]++; if (cnt[t] > 1) { printf("setwise coprime\n"); return 0; } while (j % t == 0) j /= t; } } printf("pairwise coprime\n"); return 0; }
replace
27
31
27
32
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1e9 + 100; const int S = 1e3 + 5; vector<int> pr; vector<int> isp(S, 1); void sieve() { for (int p = 2; p < S; p++) { if (isp[p]) { pr.push_back(p); for (int j = p * 2; j < S; j += p) { isp[j] = 0; } } } } int n; vector<int> a; bool f1() { vector<int> occ(S, 0); for (auto it : a) { for (auto p : pr) { if (it % p == 0) { if (occ[p]) { return 0; } occ[p]++; while (it % p == 0) { it /= p; } } } if (it != 1) { if (occ[it]) { return 0; } occ[it]++; } } return 1; } bool f2() { int allGCD = a[0]; for (int i = 1; i < n; i++) { allGCD = __gcd(allGCD, a[i]); } return allGCD == 1; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); sieve(); // cout<<pr.size()<<'\n'; // for (int i = 0; i < 5; i++){ // cout<<pr[i]<<'\n'; // } cin >> n; a.resize(n); for (int i = 0; i < n; i++) { cin >> a[i]; } if (f1()) { cout << "pairwise coprime\n"; } else if (f2()) { cout << "setwise coprime\n"; } else { cout << "not coprime\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1e9 + 100; const int S = 1e3 + 5; vector<int> pr; vector<int> isp(S, 1); void sieve() { for (int p = 2; p < S; p++) { if (isp[p]) { pr.push_back(p); for (int j = p * 2; j < S; j += p) { isp[j] = 0; } } } } int n; vector<int> a; bool f1() { vector<int> occ(1e6 + 5, 0); for (auto it : a) { for (auto p : pr) { if (it % p == 0) { if (occ[p]) { return 0; } occ[p]++; while (it % p == 0) { it /= p; } } } if (it != 1) { if (occ[it]) { return 0; } occ[it]++; } } return 1; } bool f2() { int allGCD = a[0]; for (int i = 1; i < n; i++) { allGCD = __gcd(allGCD, a[i]); } return allGCD == 1; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); sieve(); // cout<<pr.size()<<'\n'; // for (int i = 0; i < 5; i++){ // cout<<pr[i]<<'\n'; // } cin >> n; a.resize(n); for (int i = 0; i < n; i++) { cin >> a[i]; } if (f1()) { cout << "pairwise coprime\n"; } else if (f2()) { cout << "setwise coprime\n"; } else { cout << "not coprime\n"; } return 0; }
replace
23
24
23
24
0
p02574
C++
Time Limit Exceeded
/// BISMILLAHIR RAHMANIR RAHEEM /// ALLAH IS WATCHING ME /// ALLAH save us from COVID-19.Amin. /// Every soul shall taste death. /// Tag :: #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> /// order_of_key return number of elements less than x. /// find_by_order return index. using namespace std; using namespace __gnu_pbds; #define MOHAMMAD \ ios::sync_with_stdio(0); \ cin.tie(0); #define all(x) (x).begin(), (x).end() #define AE cout << fixed << setprecision(2); /// faster. #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; // 8-direction....... int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; int dx4[] = {1, -1, 0, 0}; // 4-direction........... int dy4[] = {0, 0, 1, -1}; using ll = long long; const ll MOD = 1e9 + 7; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; // debug template <typename F, typename S> ostream &operator<<(ostream &os, const pair<F, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ", "; os << *it; } return os << "}"; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { os << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ","; os << *it; } return os << "]"; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) { os << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ", "; os << *it; } return os << "]"; } template <typename F, typename S> ostream &operator<<(ostream &os, const map<F, S> &v) { os << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ", "; os << it->first << " = " << it->second; } return os << "]"; } #define dbg(args...) \ do { \ cerr << #args << " : "; \ faltu(args); \ } while (0) void faltu() { cerr << endl; } template <typename T> void faltu(T a[], int n) { for (int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << endl; } template <typename T, typename... hello> void faltu(T arg, const hello &...rest) { cerr << arg << ' '; faltu(rest...); } // #else // #define dbg(args...) /// Modular arithmetic inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); } inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a * b) % MOD; } inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a + b) % MOD; } inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; } inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; } inline ll modInverse(ll a) { return modPow(a, MOD - 2); } /// When MOD is prime. inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); } //*********************************************** The END //********************************************************************************************************************************** const ll N = 1e6; const ll INF = 1e15; const ll limit = (1LL << 64) - 1; vector<ll> primes; bitset<N + 1> bs; void sieve() { bs.set(); bs[0] = bs[1] = 0; for (ll i = 2; i <= N; ++i) { if (bs[i]) { primes.push_back(i); for (ll j = i * i; j <= N; j += i) { bs[j] = 0; } } } } int main() { MOHAMMAD sieve(); ll n, sum = 0; cin >> n; ll arr[n], gcd = 0; for (ll i = 0; i < n; ++i) cin >> arr[i], gcd = __gcd(gcd, arr[i]); if (gcd > 1) { cout << "not coprime\n"; } else { bool all = false; map<ll, ll> mp; for (ll i = 0; i < n; ++i) { mp[arr[i]]++; if (mp[arr[i]] > 1 and arr[i] > 1) all = 1; } mp.clear(); for (ll i = 0; i < n; ++i) { if (arr[i] == 1) continue; ll x = arr[i]; for (auto p : primes) { if (p * p > x) break; if (x % p == 0) { mp[p]++; while (x % p == 0) x /= p; } if (mp[p] > 1) all = 1; } if (x > 1) mp[x]++; if (x > 1 and mp[x] > 1) all = 1; } if (all) { cout << "setwise coprime\n"; } else cout << "pairwise coprime\n"; } } /* Explanation: TODO : Alhamdulillah */
/// BISMILLAHIR RAHMANIR RAHEEM /// ALLAH IS WATCHING ME /// ALLAH save us from COVID-19.Amin. /// Every soul shall taste death. /// Tag :: #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> /// order_of_key return number of elements less than x. /// find_by_order return index. using namespace std; using namespace __gnu_pbds; #define MOHAMMAD \ ios::sync_with_stdio(0); \ cin.tie(0); #define all(x) (x).begin(), (x).end() #define AE cout << fixed << setprecision(2); /// faster. #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; // 8-direction....... int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; int dx4[] = {1, -1, 0, 0}; // 4-direction........... int dy4[] = {0, 0, 1, -1}; using ll = long long; const ll MOD = 1e9 + 7; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; // debug template <typename F, typename S> ostream &operator<<(ostream &os, const pair<F, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ", "; os << *it; } return os << "}"; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { os << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ","; os << *it; } return os << "]"; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) { os << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ", "; os << *it; } return os << "]"; } template <typename F, typename S> ostream &operator<<(ostream &os, const map<F, S> &v) { os << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ", "; os << it->first << " = " << it->second; } return os << "]"; } #define dbg(args...) \ do { \ cerr << #args << " : "; \ faltu(args); \ } while (0) void faltu() { cerr << endl; } template <typename T> void faltu(T a[], int n) { for (int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << endl; } template <typename T, typename... hello> void faltu(T arg, const hello &...rest) { cerr << arg << ' '; faltu(rest...); } // #else // #define dbg(args...) /// Modular arithmetic inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); } inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a * b) % MOD; } inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a + b) % MOD; } inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; } inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; } inline ll modInverse(ll a) { return modPow(a, MOD - 2); } /// When MOD is prime. inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); } //*********************************************** The END //********************************************************************************************************************************** const ll N = 1e3; const ll INF = 1e15; const ll limit = (1LL << 64) - 1; vector<ll> primes; bitset<N + 1> bs; void sieve() { bs.set(); bs[0] = bs[1] = 0; for (ll i = 2; i <= N; ++i) { if (bs[i]) { primes.push_back(i); for (ll j = i * i; j <= N; j += i) { bs[j] = 0; } } } } int main() { MOHAMMAD sieve(); ll n, sum = 0; cin >> n; ll arr[n], gcd = 0; for (ll i = 0; i < n; ++i) cin >> arr[i], gcd = __gcd(gcd, arr[i]); if (gcd > 1) { cout << "not coprime\n"; } else { bool all = false; map<ll, ll> mp; for (ll i = 0; i < n; ++i) { mp[arr[i]]++; if (mp[arr[i]] > 1 and arr[i] > 1) all = 1; } mp.clear(); for (ll i = 0; i < n; ++i) { if (arr[i] == 1) continue; ll x = arr[i]; for (auto p : primes) { if (p * p > x) break; if (x % p == 0) { mp[p]++; while (x % p == 0) x /= p; } if (mp[p] > 1) all = 1; } if (x > 1) mp[x]++; if (x > 1 and mp[x] > 1) all = 1; } if (all) { cout << "setwise coprime\n"; } else cout << "pairwise coprime\n"; } } /* Explanation: TODO : Alhamdulillah */
replace
142
143
142
143
TLE
p02574
C++
Time Limit Exceeded
// 😄😄😄😄😄😄😄😄😄😄😄😄😄 // Apno Swagat che// #include <bits/stdc++.h> using namespace std; #define ll long long #define vll vector<ll> #define vi vector<int> #define pi pair<int, int> #define vp vector<pi> #define pb push_back #define mp make_pair #define F first #define S second #define For(i, a, b) for (ll i = a; i < b; i++) #define endl "\n" #define debug(x) cout << "AA Baju Smit------> " << #x << " -> " << x << endl #define all(x) x.begin(), x.end() #define mint map<int, int> #define mod 10000007 #define ciN cin #define X INT_MAX #define N INT_MIN //////////////////////////////////////////////////////////////// // Ha Moj Ha/// //////////////////////////////////////////////////////////////// ////TEST CASES ATTACHED CHE BHULTO NAI....../////////////////// int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } vector<bool> Sieve(int n) { vector<bool> is_prime(n + 1, true); is_prime[0] = is_prime[1] = false; for (int i = 2; i <= n; i++) { if (is_prime[i] && 1LL * i * i <= n) { for (int j = i * i; j <= n; j += i) is_prime[j] = false; } } return is_prime; } void jabru() { vector<bool> p = Sieve(1000000); vi xx; for (int i = 1; i <= 1000000; i++) { if (p[i]) xx.pb(i); } int n; ciN >> n; vi v(n); For(i, 0, n) cin >> v[i]; int gcc = v[0]; mint has; bool is_pos = 1; For(i, 0, n) { gcc = gcd(gcc, v[i]); if (is_pos) { int h; if (v[i] > xx[xx.size() - 1]) h = xx.size() - 1; else { h = lower_bound(all(xx), v[i]) - xx.begin(); } for (int j = h; j > -1; j--) { if (v[i] % xx[j] == 0) { if (has[xx[j]]) { is_pos = 0; break; } else { has[xx[j]] = 1; } } } } } if (is_pos) { cout << "pairwise coprime" << endl; } else if (gcc == 1) { cout << "setwise coprime" << endl; } else { cout << "not coprime" << endl; } } //////////////////////////////////////////////////////////////// // Bas aabaju nai javanu/// //////////////////////////////////////////////////////////////// int main() { ios::sync_with_stdio(0); cin.tie(0); // int t; cin >> t; // while (t--) jabru(); return 0; } /////////////////////////////////////////////////////////////////////////////////////////// // Kai baju bhai???
// 😄😄😄😄😄😄😄😄😄😄😄😄😄 // Apno Swagat che// #include <bits/stdc++.h> using namespace std; #define ll long long #define vll vector<ll> #define vi vector<int> #define pi pair<int, int> #define vp vector<pi> #define pb push_back #define mp make_pair #define F first #define S second #define For(i, a, b) for (ll i = a; i < b; i++) #define endl "\n" #define debug(x) cout << "AA Baju Smit------> " << #x << " -> " << x << endl #define all(x) x.begin(), x.end() #define mint map<int, int> #define mod 10000007 #define ciN cin #define X INT_MAX #define N INT_MIN //////////////////////////////////////////////////////////////// // Ha Moj Ha/// //////////////////////////////////////////////////////////////// ////TEST CASES ATTACHED CHE BHULTO NAI....../////////////////// int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } vector<bool> Sieve(int n) { vector<bool> is_prime(n + 1, true); is_prime[0] = is_prime[1] = false; for (int i = 2; i <= n; i++) { if (is_prime[i] && 1LL * i * i <= n) { for (int j = i * i; j <= n; j += i) is_prime[j] = false; } } return is_prime; } void jabru() { vector<bool> p = Sieve(1000000); vi xx; for (int i = 1; i <= 1000000; i++) { if (p[i]) xx.pb(i); } int n; ciN >> n; vi v(n); For(i, 0, n) cin >> v[i]; int gcc = v[0]; mint has; bool is_pos = 1; For(i, 0, n) { gcc = gcd(gcc, v[i]); if (is_pos) { if (p[v[i]]) { if (has[v[i]] == 0) has[v[i]] = 1; else is_pos = 0; } else { int h = 0; if (v[i] > xx[xx.size() - 1]) h = xx.size() - 1; else { h = lower_bound(all(xx), v[i]) - xx.begin(); } for (int j = h; j > -1; j--) { if (v[i] % xx[j] == 0) { if (has[xx[j]]) { is_pos = 0; break; } else { has[xx[j]] = 1; } } } } } } if (is_pos) { cout << "pairwise coprime" << endl; } else if (gcc == 1) { cout << "setwise coprime" << endl; } else { cout << "not coprime" << endl; } } //////////////////////////////////////////////////////////////// // Bas aabaju nai javanu/// //////////////////////////////////////////////////////////////// int main() { ios::sync_with_stdio(0); cin.tie(0); // int t; cin >> t; // while (t--) jabru(); return 0; } /////////////////////////////////////////////////////////////////////////////////////////// // Kai baju bhai???
replace
61
74
61
82
TLE
p02574
C++
Runtime Error
#pragma GCC target("avx,avx2,fma") #pragma GCC optimization("Ofast") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; #define mod 1000000007 #define rep(i, a, b) for (ll i = a; i < b; i++) #define repc(i, a, b, c) \ for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c) // #define mp make_pair #define fi first #define si second #define pb push_back #define all(name) name.begin(), name.end() #define ral(name) name.rbegin(), name.rend() #define fact(n) rep(i, 1, n + 1) ft.pb((ft[i - 1] * i) % mod) #define mod_in(a) power(a, mod - 2) #define ncr(n, r) \ (n >= r ? ((ft[n] * mod_in((ft[r] * ft[(n) - (r)]) % mod)) % mod) : 0LL) #define deb(x) cerr << "[" << #x << " " << x << "]" << endl; #define endl '\n' #define int ll vector<ll> ft(1, 1LL); /*======================================================================*/ // ll power(ll x, ll y) { // ll res = 1;x %= mod; // while (y > 0) { // if (y & 1)res = (res*x) % mod; // y = y>>1; // x = (x*x) % mod; // } // return res%mod; // } const int faxsize = 1e6 + 5; vector<int> fax[faxsize]; // bool cmp(pair<int, int> a, pair<int, int> b){ // return (a.fi+a.si) > (b.fi+b.si); // } // void solve(){ // int n, s = 0; // cin >> n; // vector<pair<int, int> > v(n) ; // rep(i, 0, n)cin >> v[i].fi >> v[i].si, s += v[i].fi; // sort(all(v), cmp); // rep(i, 0, n){ // if(v[i].fi+v[i].si <= s){ // cout << "INDEFINITELY\n"; // return; // } // else s -= v[i].fi; // } // int mi, ans = s; // rep(i,0,n){ // if() // } // } void solve() { int arr[faxsize] = {0}; int n; cin >> n; int g = 0; rep(i, 0, n) { int a; cin >> a; g = __gcd(a, g); for (auto i : fax[a]) arr[i]++; } if (g != 1) cout << "not coprime\n"; else { rep(i, 0, faxsize) if (arr[i] > 1) { cout << "setwise coprime\n"; return; } cout << "pairwise coprime\n"; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // fact((2e6+10)); // //declare and global rep(i, 2, faxsize + 1) if (fax[i].size() == 0) repc(j, i, faxsize + 1, i) fax[j] .push_back(i); int t = 1; // cin >> t; rep(i, 0, t) { solve(); } }
#pragma GCC target("avx,avx2,fma") #pragma GCC optimization("Ofast") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; #define mod 1000000007 #define rep(i, a, b) for (ll i = a; i < b; i++) #define repc(i, a, b, c) \ for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c) // #define mp make_pair #define fi first #define si second #define pb push_back #define all(name) name.begin(), name.end() #define ral(name) name.rbegin(), name.rend() #define fact(n) rep(i, 1, n + 1) ft.pb((ft[i - 1] * i) % mod) #define mod_in(a) power(a, mod - 2) #define ncr(n, r) \ (n >= r ? ((ft[n] * mod_in((ft[r] * ft[(n) - (r)]) % mod)) % mod) : 0LL) #define deb(x) cerr << "[" << #x << " " << x << "]" << endl; #define endl '\n' #define int ll vector<ll> ft(1, 1LL); /*======================================================================*/ // ll power(ll x, ll y) { // ll res = 1;x %= mod; // while (y > 0) { // if (y & 1)res = (res*x) % mod; // y = y>>1; // x = (x*x) % mod; // } // return res%mod; // } const int faxsize = 1e6 + 5; vector<int> fax[faxsize]; // bool cmp(pair<int, int> a, pair<int, int> b){ // return (a.fi+a.si) > (b.fi+b.si); // } // void solve(){ // int n, s = 0; // cin >> n; // vector<pair<int, int> > v(n) ; // rep(i, 0, n)cin >> v[i].fi >> v[i].si, s += v[i].fi; // sort(all(v), cmp); // rep(i, 0, n){ // if(v[i].fi+v[i].si <= s){ // cout << "INDEFINITELY\n"; // return; // } // else s -= v[i].fi; // } // int mi, ans = s; // rep(i,0,n){ // if() // } // } void solve() { int arr[faxsize] = {0}; int n; cin >> n; int g = 0; rep(i, 0, n) { int a; cin >> a; g = __gcd(a, g); for (auto i : fax[a]) arr[i]++; } if (g != 1) cout << "not coprime\n"; else { rep(i, 0, faxsize) if (arr[i] > 1) { cout << "setwise coprime\n"; return; } cout << "pairwise coprime\n"; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // fact((2e6+10)); // //declare and global rep(i, 2, faxsize) if (fax[i].size() == 0) repc(j, i, faxsize, i) fax[j] .push_back(i); int t = 1; // cin >> t; rep(i, 0, t) { solve(); } }
replace
94
97
94
96
0
p02574
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <class S, class T> ostream &operator<<(ostream &out, const pair<S, T> &o) { out << "(" << o.first << "," << o.second << ")"; return out; } template <class T> ostream &operator<<(ostream &out, const vector<T> &V) { for (int i = 0; i < V.size(); i++) { out << V[i]; if (i != V.size() - 1) out << " "; } return out; } template <class T> ostream &operator<<(ostream &out, const vector<vector<T>> &Mat) { for (int i = 0; i < Mat.size(); i++) { if (i != 0) out << endl; out << Mat[i]; } return out; } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &mp) { out << "{ "; for (auto it = mp.begin(); it != mp.end(); it++) { out << it->first << ":" << it->second; if (mp.size() - 1 != distance(mp.begin(), it)) out << ", "; } out << " }"; return out; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } /* <url:> 問題文============================================================ ================================================================= 解説============================================================= ================================================================ */ /** * 素因数分解 3 * 与えられる値をその都度処理 * 戻り値 {素因数の連想配列(値と個数)} */ map<ll, ll> PrimeFact(ll n) { map<ll, ll> mp; while (n != 1) { if (n == 2 || n == 3) { mp[n]++; n /= n; continue; } bool prime_flag = false; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { mp[i]++; n /= i; prime_flag = true; break; } } if (!prime_flag) { mp[n]++; n /= n; } } } template <class Type> Type solve(Type res = Type()) { int N; cin >> N; vector<ll> A(N); for (auto &in : A) cin >> in; { // check pairwise bool prime[1000001] = {false}; bool ok = true; for (int i = N - 1; i >= 0; i--) { for (auto p : PrimeFact(A[i])) { if (prime[p.first]) { ok = false; break; } else { prime[p.first] = true; } } } if (ok) { return "pairwise coprime"; } } { // check setwise ll GCD = 0; for (auto a : A) GCD = gcd(GCD, a); if (GCD == 1) { return "setwise coprime"; } } return "not coprime"; return res; } int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); // solve(0); cout << fixed << setprecision(15) << solve<string>() << endl; return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <class S, class T> ostream &operator<<(ostream &out, const pair<S, T> &o) { out << "(" << o.first << "," << o.second << ")"; return out; } template <class T> ostream &operator<<(ostream &out, const vector<T> &V) { for (int i = 0; i < V.size(); i++) { out << V[i]; if (i != V.size() - 1) out << " "; } return out; } template <class T> ostream &operator<<(ostream &out, const vector<vector<T>> &Mat) { for (int i = 0; i < Mat.size(); i++) { if (i != 0) out << endl; out << Mat[i]; } return out; } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &mp) { out << "{ "; for (auto it = mp.begin(); it != mp.end(); it++) { out << it->first << ":" << it->second; if (mp.size() - 1 != distance(mp.begin(), it)) out << ", "; } out << " }"; return out; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } /* <url:> 問題文============================================================ ================================================================= 解説============================================================= ================================================================ */ /** * 素因数分解 3 * 与えられる値をその都度処理 * 戻り値 {素因数の連想配列(値と個数)} */ map<ll, ll> PrimeFact(ll n) { map<ll, ll> mp; while (n != 1) { if (n == 2 || n == 3) { mp[n]++; n /= n; continue; } bool prime_flag = false; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { mp[i]++; n /= i; prime_flag = true; break; } } if (!prime_flag) { mp[n]++; n /= n; } } return mp; } template <class Type> Type solve(Type res = Type()) { int N; cin >> N; vector<ll> A(N); for (auto &in : A) cin >> in; { // check pairwise bool prime[1000001] = {false}; bool ok = true; for (int i = N - 1; i >= 0; i--) { for (auto p : PrimeFact(A[i])) { if (prime[p.first]) { ok = false; break; } else { prime[p.first] = true; } } } if (ok) { return "pairwise coprime"; } } { // check setwise ll GCD = 0; for (auto a : A) GCD = gcd(GCD, a); if (GCD == 1) { return "setwise coprime"; } } return "not coprime"; return res; } int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); // solve(0); cout << fixed << setprecision(15) << solve<string>() << endl; return 0; }
insert
90
90
90
91
-11
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define F first #define S second #define pb push_back #define mp make_pair ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, i, j; cin >> n; ll a[i]; ll prime[1000003]; memset(prime, 0, sizeof(prime)); for (i = 2; i < 1000001; i++) { if (prime[i] == 0) { for (j = i; j < 1000001; j += i) { prime[j] = i; } } } for (i = 0; i < n; i++) cin >> a[i]; map<ll, ll> pf; for (i = 0; i < n; i++) { map<ll, ll> m; ll x = a[i]; while (x != 1) { if (m.find(prime[x]) == m.end()) { m.insert(mp(prime[x], 1)); } x /= prime[x]; } for (auto it : m) { if (pf.find(it.first) != pf.end()) pf.find(it.first)->second++; else pf.insert(mp(it.first, 1)); } } ll flag1 = 0, flag2 = 0; for (auto it : pf) { if (it.second != 1) flag1 = 1; if (it.second == n) flag2 = 1; } if (flag1 == 0) cout << "pairwise coprime\n"; else if (flag2 == 0) cout << "setwise coprime\n"; else cout << "not coprime\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define F first #define S second #define pb push_back #define mp make_pair ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, i, j; cin >> n; ll a[n]; ll prime[1000003]; memset(prime, 0, sizeof(prime)); for (i = 2; i < 1000001; i++) { if (prime[i] == 0) { for (j = i; j < 1000001; j += i) { prime[j] = i; } } } for (i = 0; i < n; i++) cin >> a[i]; map<ll, ll> pf; for (i = 0; i < n; i++) { map<ll, ll> m; ll x = a[i]; while (x != 1) { if (m.find(prime[x]) == m.end()) { m.insert(mp(prime[x], 1)); } x /= prime[x]; } for (auto it : m) { if (pf.find(it.first) != pf.end()) pf.find(it.first)->second++; else pf.insert(mp(it.first, 1)); } } ll flag1 = 0, flag2 = 0; for (auto it : pf) { if (it.second != 1) flag1 = 1; if (it.second == n) flag2 = 1; } if (flag1 == 0) cout << "pairwise coprime\n"; else if (flag2 == 0) cout << "setwise coprime\n"; else cout << "not coprime\n"; }
replace
25
26
25
26
-11
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long lint; #define rep(i, n) for (lint(i) = 0; (i) < (n); (i)++) #define repp(i, m, n) for (lint(i) = (m); (i) < (n); (i)++) #define repm(i, n) for (lint(i) = (n - 1); (i) >= 0; (i)--) #define INF (1ll << 60) #define all(x) (x).begin(), (x).end() const lint MOD = 1000000007; const lint MAX = 1000000; using Graph = vector<vector<lint>>; typedef pair<lint, lint> P; typedef map<lint, lint> M; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) lint fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (lint 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 COM(lint n, lint k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } lint primary(lint num) { if (num < 2) return 0; else if (num == 2) return 1; else if (num % 2 == 0) return 0; double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return 0; } } return 1; } 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; } lint lcm(lint a, lint b) { return a / __gcd(a, b) * b; } lint gcd(lint a, lint b) { return __gcd(a, b); } std::vector<int> sieve(int n) { std::vector<int> res(n); std::iota(res.begin(), res.end(), 0); for (int i = 2; i * i < n; ++i) { if (res[i] < i) continue; for (int j = i * i; j < n; j += i) if (res[j] == j) res[j] = i; } return res; } std::vector<int> factor(int n, const std::vector<int> &min_factor) { // min_factor は sieve() で得られたものとする std::vector<int> res; while (n > 1) { res.push_back(min_factor[n]); n /= min_factor[n]; // 割った後の値についても素因数を知っているので順次求まる } return res; } int main() { lint n; cin >> n; lint a[n]; rep(i, n) cin >> a[i]; lint gc = a[0]; rep(i, n - 1) gc = gcd(gc, a[i + 1]); vector<int> p; p = sieve(1000005); vector<int> x; x = factor(n, p); M m; rep(i, n) { x = factor(a[i], p); rep(i, x.size() - 1) { if (x[i] == x[i + 1]) x[i] = 0; } rep(i, x.size()) m[x[i]]++; } bool f = true; for (auto g : m) { if (g.first == 0) continue; if (g.second > 1) { f = false; break; } } if (f) cout << "pairwise coprime" << endl; else if (gc == 1) cout << "setwise coprime" << endl; else cout << "not coprime" << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long lint; #define rep(i, n) for (lint(i) = 0; (i) < (n); (i)++) #define repp(i, m, n) for (lint(i) = (m); (i) < (n); (i)++) #define repm(i, n) for (lint(i) = (n - 1); (i) >= 0; (i)--) #define INF (1ll << 60) #define all(x) (x).begin(), (x).end() const lint MOD = 1000000007; const lint MAX = 1000000; using Graph = vector<vector<lint>>; typedef pair<lint, lint> P; typedef map<lint, lint> M; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) lint fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (lint 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 COM(lint n, lint k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } lint primary(lint num) { if (num < 2) return 0; else if (num == 2) return 1; else if (num % 2 == 0) return 0; double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return 0; } } return 1; } 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; } lint lcm(lint a, lint b) { return a / __gcd(a, b) * b; } lint gcd(lint a, lint b) { return __gcd(a, b); } std::vector<int> sieve(int n) { std::vector<int> res(n); std::iota(res.begin(), res.end(), 0); for (int i = 2; i * i < n; ++i) { if (res[i] < i) continue; for (int j = i * i; j < n; j += i) if (res[j] == j) res[j] = i; } return res; } std::vector<int> factor(int n, const std::vector<int> &min_factor) { // min_factor は sieve() で得られたものとする std::vector<int> res; while (n > 1) { res.push_back(min_factor[n]); n /= min_factor[n]; // 割った後の値についても素因数を知っているので順次求まる } return res; } int main() { lint n; cin >> n; lint a[n]; rep(i, n) cin >> a[i]; lint gc = a[0]; rep(i, n - 1) gc = gcd(gc, a[i + 1]); vector<int> p; p = sieve(1000005); vector<int> x; x = factor(n, p); M m; rep(i, n) { if (a[i] == 1) continue; x = factor(a[i], p); rep(i, x.size() - 1) { if (x[i] == x[i + 1]) x[i] = 0; } rep(i, x.size()) m[x[i]]++; } bool f = true; for (auto g : m) { if (g.first == 0) continue; if (g.second > 1) { f = false; break; } } if (f) cout << "pairwise coprime" << endl; else if (gc == 1) cout << "setwise coprime" << endl; else cout << "not coprime" << endl; }
insert
102
102
102
104
0
p02574
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ALL(A) (A).begin(), (A).end() #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) 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; } int dx[] = {0, 1, -1, 0, 1, -1, 1, -1}; // i<4:4way i<8:8way int dy[] = {1, 0, 0, -1, 1, -1, -1, 1}; const ll mod = 1e9 + 7; const ll INF = -1 * ((1LL << 63) + 1); const int inf = -1 * ((1 << 31) + 1); ll cnt[1000006]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; ll allgcd = a[0]; rep(i, n) allgcd = __gcd(allgcd, a[i]); if (allgcd > 1) { cout << "not coprime" << endl; } else { // 与えられた数をそれぞれ素因数分解していく rep(i, n) { ll now = a[i]; for (ll j = 2; j * j <= a[i]; j++) { if (now % j == 0) { while (now % j == 0) now /= j; cnt[j]++; } } if (now > 1) cnt[now]++; } for (int i = 2; i <= 1e6; i++) { if (cnt[i] > 1) { cout << "setwise coprime" << endl; return 0; } } cout << "pairwise coprime" << endl; } }
#include <bits/stdc++.h> #define ALL(A) (A).begin(), (A).end() #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) 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; } int dx[] = {0, 1, -1, 0, 1, -1, 1, -1}; // i<4:4way i<8:8way int dy[] = {1, 0, 0, -1, 1, -1, -1, 1}; const ll mod = 1e9 + 7; const ll INF = -1 * ((1LL << 63) + 1); const int inf = -1 * ((1 << 31) + 1); ll cnt[1000006]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; ll allgcd = a[0]; rep(i, n) allgcd = __gcd(allgcd, a[i]); if (allgcd > 1) { cout << "not coprime" << endl; } else { // 与えられた数をそれぞれ素因数分解していく rep(i, n) { ll now = a[i]; for (ll j = 2; j * j <= now; j++) { if (now % j == 0) { while (now % j == 0) now /= j; cnt[j]++; } } if (now > 1) cnt[now]++; } for (int i = 2; i <= 1e6; i++) { if (cnt[i] > 1) { cout << "setwise coprime" << endl; return 0; } } cout << "pairwise coprime" << endl; } }
replace
46
47
46
47
TLE
p02574
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; #define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int arr[100001]; int main() { fast int n, z; cin >> n; int g; bool b = 1; for (int i = 0; i < n; i++) { cin >> z; if (i == 0) g = z; else g = __gcd(z, g); if (b) { int s = sqrt(z); for (int j = 2; j <= s; j++) { if (z % j == 0) { if (arr[j] != 0) b = 0; arr[j]++; while (z % j == 0) z /= j; } } if (z != 1) { if (arr[z] != 0) b = 0; arr[z]++; } } } if (b) cout << "pairwise coprime"; else if (g == 1) cout << "setwise coprime"; else cout << "not coprime"; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; #define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int arr[1000001]; int main() { fast int n, z; cin >> n; int g; bool b = 1; for (int i = 0; i < n; i++) { cin >> z; if (i == 0) g = z; else g = __gcd(z, g); if (b) { int s = sqrt(z); for (int j = 2; j <= s; j++) { if (z % j == 0) { if (arr[j] != 0) b = 0; arr[j]++; while (z % j == 0) z /= j; } } if (z != 1) { if (arr[z] != 0) b = 0; arr[z]++; } } } if (b) cout << "pairwise coprime"; else if (g == 1) cout << "setwise coprime"; else cout << "not coprime"; return 0; }
replace
5
6
5
6
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) \ for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) // NOLINT #define chmax(x, a) \ do { \ x = max(x, a); \ } while (0) #define chmin(x, a) \ do { \ x = min(x, a); \ } while (0) using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef pair<ll, ll> PLL; ll gcd(ll x, ll y) { if (y < x) swap(x, y); if (x == 0) return y; return gcd(y % x, x); } std::map<ll, ll> decomposePrime(ll n) { std::map<ll, ll> m; ll x = 2; while (x * x <= n) { if (n % x == 0) { m[x]++; n /= x; } else { x++; } } if (n > 1) m[n]++; return m; } void solve() { ll N; cin >> N; vector<ll> a(N); rep(i, N) cin >> a[i]; bool pw = true; vector<bool> appeared(N); for (auto e : decomposePrime(a[0])) { appeared[e.first] = true; } for (ll i = 1; i < N; i++) { for (auto e : decomposePrime(a[i])) { if (appeared[e.first]) pw = false; appeared[e.first] = true; } } if (pw) { cout << "pairwise coprime" << endl; return; } bool sw = true; ll t = a[0]; for (ll i = 1; i < N; i++) { t = gcd(t, a[i]); } if (t != 1) sw = false; if (sw) { cout << "setwise coprime" << endl; return; } cout << "not coprime" << endl; } int main() { // ll T; // cin >> T; // rep(_,T) solve(); return 0; }
#include <bits/stdc++.h> #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) \ for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) // NOLINT #define chmax(x, a) \ do { \ x = max(x, a); \ } while (0) #define chmin(x, a) \ do { \ x = min(x, a); \ } while (0) using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef pair<ll, ll> PLL; ll gcd(ll x, ll y) { if (y < x) swap(x, y); if (x == 0) return y; return gcd(y % x, x); } std::map<ll, ll> decomposePrime(ll n) { std::map<ll, ll> m; ll x = 2; while (x * x <= n) { if (n % x == 0) { m[x]++; n /= x; } else { x++; } } if (n > 1) m[n]++; return m; } void solve() { ll N; cin >> N; vector<ll> a(N); rep(i, N) cin >> a[i]; bool pw = true; vector<bool> appeared(2000000); for (auto e : decomposePrime(a[0])) { appeared[e.first] = true; } for (ll i = 1; i < N; i++) { for (auto e : decomposePrime(a[i])) { if (appeared[e.first]) pw = false; appeared[e.first] = true; } } if (pw) { cout << "pairwise coprime" << endl; return; } bool sw = true; ll t = a[0]; for (ll i = 1; i < N; i++) { t = gcd(t, a[i]); } if (t != 1) sw = false; if (sw) { cout << "setwise coprime" << endl; return; } cout << "not coprime" << endl; } int main() { // ll T; // cin >> T; // rep(_,T) solve(); return 0; }
replace
51
52
51
52
0
p02574
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define debug(n) cerr << #n << ':' << n << endl; #define dline cerr << __LINE__ << endl; using ll = long long; using ull = unsigned long long; template <class T, class U> using P = pair<T, U>; template <class T> using Heap = priority_queue<T>; template <class T> using heaP = priority_queue<T, vector<T>, greater<T>>; template <class T, class U> using umap = unordered_map<T, U>; template <class T> using uset = unordered_set<T>; template <class T> bool ChangeMax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <class T> bool ChangeMin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <class T, size_t N, class U> void Fill(T (&a)[N], const U &v) { fill((U *)a, (U *)(a + N), v); } template <class T, class U> istream &operator>>(istream &is, P<T, U> &p) { is >> p.first >> p.second; return is; } template <class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) { is >> e; } return is; } int main() { vector<int> plist; bitset<1000001> ppos; for (int i = 2; i <= 1000000; ++i) { bool f = true; for (auto e : plist) { if (i % e == 0) { f = false; break; } if (e * e > i) break; } if (f) { plist.push_back(i); ppos[i] = 1; } } int n; cin >> n; vector<int> v(n); cin >> v; map<int, int> mp; for (auto e : v) { for (auto plime : plist) { if (ppos[e]) { mp[e]++; break; } if (e % plime == 0) mp[plime]++; while (e % plime == 0) e /= plime; } } int cnt1 = 0, cnt0 = 0, maxn = 0; for (auto e : mp) { cnt1 += e.second == 1; maxn = max(maxn, e.second); cnt0 += e.second == 0; } if (cnt1 + cnt0 == (int)mp.size()) cout << "pairwise coprime" << endl; else if (maxn != n) cout << "setwise coprime" << endl; else cout << "not coprime" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define debug(n) cerr << #n << ':' << n << endl; #define dline cerr << __LINE__ << endl; using ll = long long; using ull = unsigned long long; template <class T, class U> using P = pair<T, U>; template <class T> using Heap = priority_queue<T>; template <class T> using heaP = priority_queue<T, vector<T>, greater<T>>; template <class T, class U> using umap = unordered_map<T, U>; template <class T> using uset = unordered_set<T>; template <class T> bool ChangeMax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <class T> bool ChangeMin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <class T, size_t N, class U> void Fill(T (&a)[N], const U &v) { fill((U *)a, (U *)(a + N), v); } template <class T, class U> istream &operator>>(istream &is, P<T, U> &p) { is >> p.first >> p.second; return is; } template <class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) { is >> e; } return is; } int main() { vector<int> plist; bitset<1000001> ppos; for (int i = 2; i <= 1000000; ++i) { bool f = true; for (auto e : plist) { if (i % e == 0) { f = false; break; } if (e * e > i) break; } if (f) { plist.push_back(i); ppos[i] = 1; } } int n; cin >> n; vector<int> v(n); cin >> v; map<int, int> mp; for (auto e : v) { for (auto plime : plist) { if (e == 1) break; if (ppos[e]) { mp[e]++; break; } if (e % plime == 0) mp[plime]++; while (e % plime == 0) e /= plime; } } int cnt1 = 0, cnt0 = 0, maxn = 0; for (auto e : mp) { cnt1 += e.second == 1; maxn = max(maxn, e.second); cnt0 += e.second == 0; } if (cnt1 + cnt0 == (int)mp.size()) cout << "pairwise coprime" << endl; else if (maxn != n) cout << "setwise coprime" << endl; else cout << "not coprime" << endl; return 0; }
insert
70
70
70
72
TLE
p02574
C++
Runtime Error
#include <algorithm> #include <bitset> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #define INF 0x3f3f3f3f #define MOD 1000000007 using namespace std; typedef long long ll; mt19937 mrand(random_device{}()); int rnd(int x) { return mrand() % x; } template <typename T> void read(T &x) { x = 0; char c = getchar(); T sig = 1; for (; !isdigit(c); c = getchar()) if (c == '-') sig = -1; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0'; x *= sig; } class Solution { public: void solve() { int n; read(n); vector<int> a(n); for (int i = 0; i < n; ++i) read(a[i]); vector<int> primes = {2, 3, 5, 7, 11, 13}; for (int i = 17; i < 1000; i += 2) { bool ok = true; for (int j = 0; primes[j] * primes[j] <= i; ++j) { if (i % primes[j] == 0) { ok = false; break; } } if (ok) primes.emplace_back(i); } map<int, int> cnt; for (int i : a) { int t = i; for (int j = 0; primes[j] * primes[j] <= t; ++j) { if (t % primes[j] == 0) cnt[primes[j]]++; while (t % primes[j] == 0) t /= primes[j]; } if (t != 1) cnt[t]++; } int hi = 0; for (auto p : cnt) hi = max(hi, p.second); if (hi <= 1) { printf("pairwise coprime"); return; } printf(hi < n ? "setwise coprime" : "not coprime"); } }; int main() { ios::sync_with_stdio(false); cin.tie(0); Solution solution = Solution(); solution.solve(); }
#include <algorithm> #include <bitset> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #define INF 0x3f3f3f3f #define MOD 1000000007 using namespace std; typedef long long ll; mt19937 mrand(random_device{}()); int rnd(int x) { return mrand() % x; } template <typename T> void read(T &x) { x = 0; char c = getchar(); T sig = 1; for (; !isdigit(c); c = getchar()) if (c == '-') sig = -1; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0'; x *= sig; } class Solution { public: void solve() { int n; read(n); vector<int> a(n); for (int i = 0; i < n; ++i) read(a[i]); vector<int> primes = {2, 3, 5, 7, 11, 13}; for (int i = 17; i < 2000; i += 2) { bool ok = true; for (int j = 0; primes[j] * primes[j] <= i; ++j) { if (i % primes[j] == 0) { ok = false; break; } } if (ok) primes.emplace_back(i); } map<int, int> cnt; for (int i : a) { int t = i; for (int j = 0; primes[j] * primes[j] <= t; ++j) { if (t % primes[j] == 0) cnt[primes[j]]++; while (t % primes[j] == 0) t /= primes[j]; } if (t != 1) cnt[t]++; } int hi = 0; for (auto p : cnt) hi = max(hi, p.second); if (hi <= 1) { printf("pairwise coprime"); return; } printf(hi < n ? "setwise coprime" : "not coprime"); } }; int main() { ios::sync_with_stdio(false); cin.tie(0); Solution solution = Solution(); solution.solve(); }
replace
54
55
54
55
0
p02574
C++
Runtime Error
#include <cmath> #include <iostream> #include <string> using namespace std; int is_prime(int n) { int i; i = 2; if (n == 1) { return 0; } else if (n == 2) { return 1; } else { while (1) { if (n % i == 0) { return 0; } else if (n < i * i) { return 1; } else { i++; } } } return 0; } int gcd(int m, int n) { if (m % n == 0) { return n; } else { return gcd(n, m % n); } } int is_set(int b[1145140], int n) { int i; i = 2; if (n == 1) return 0; if (is_prime(n) == 1) { if (b[n] == 1) { return 1; } else { b[n] = 1; } } else { while (n % i > 0) { i++; } if (b[i] == 1) { return 1; } else { b[i] = 1; while (n % i == 0) { n /= i; } return is_set(b, n); } } return 0; } int main() { int i, N, GCD, D, set; cin >> N; int a[N]; int b[100000]; for (i = 0; i < N; i++) { cin >> a[i]; } for (i = 0; i < 100; i++) { b[i] = 0; } for (i = 0; i < N; i++) { if (i == 0) { GCD = a[i]; } else { D = gcd(GCD, a[i]); GCD = D; } if (GCD == 1) break; } if (GCD > 1) { cout << "not coprime\n"; return 0; } for (i = 0; i < N; i++) { set = is_set(b, a[i]); if (set == 1) { cout << "setwise coprime\n"; return 0; } } cout << "pairwise coprime\n"; return 0; }
#include <cmath> #include <iostream> #include <string> using namespace std; int is_prime(int n) { int i; i = 2; if (n == 1) { return 0; } else if (n == 2) { return 1; } else { while (1) { if (n % i == 0) { return 0; } else if (n < i * i) { return 1; } else { i++; } } } return 0; } int gcd(int m, int n) { if (m % n == 0) { return n; } else { return gcd(n, m % n); } } int is_set(int b[1145140], int n) { int i; i = 2; if (n == 1) return 0; if (is_prime(n) == 1) { if (b[n] == 1) { return 1; } else { b[n] = 1; } } else { while (n % i > 0) { i++; } if (b[i] == 1) { return 1; } else { b[i] = 1; while (n % i == 0) { n /= i; } return is_set(b, n); } } return 0; } int main() { int i, N, GCD, D, set; cin >> N; int a[N]; int b[1145140]; for (i = 0; i < N; i++) { cin >> a[i]; } for (i = 0; i < 100; i++) { b[i] = 0; } for (i = 0; i < N; i++) { if (i == 0) { GCD = a[i]; } else { D = gcd(GCD, a[i]); GCD = D; } if (GCD == 1) break; } if (GCD > 1) { cout << "not coprime\n"; return 0; } for (i = 0; i < N; i++) { set = is_set(b, a[i]); if (set == 1) { cout << "setwise coprime\n"; return 0; } } cout << "pairwise coprime\n"; return 0; }
replace
85
86
85
86
0
p02574
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define pb push_back #define fo(i, n) for (int i = 0; i < n; i++) #define ll long long #define int long long #define Mod 1000000007 #define MAX 4294967296 // 2^32 const int M = 1e9 + 7; #define ip pair<int, int> #define test(t) \ ll t; \ cin >> t; \ while (t--) using namespace std; long long gcd(int x, int y) { if (y > x) swap(x, y); if (y == 0) return x; return gcd(y, x % y); } void solve() { int n; cin >> n; int a[n]; int count = 0; fo(i, n) { cin >> a[i]; } int ans = a[0]; for (int i = 1; i < n; i++) { if (a[i] == 1 || ans == 1) break; ans = gcd(ans, a[i]); } if (ans > 1) { cout << "not coprime"; return; } map<int, int> mp; fo(i, n) { int t = a[i]; if (t == 1) { continue; } if (t % 2 == 0) { mp[2]++; while (t % 2 == 0 && t != 1) t /= 2; } for (int j = 3; j <= sqrt(a[i]); j += 2) { if (t % j == 0) { mp[j]++; while (t % j == 0 && t != 1) t /= j; if (t == 1) break; } } if (t > 2) mp[t]++; } for (auto it = mp.begin(); it != mp.end(); it++) { if (it->second > (int)1) { cout << "setwise coprime"; return; } } cout << "pairwise coprime"; } signed main() { // std::string binary = std::bitset<8>(n).to_string(); ios::sync_with_stdio(0); cin.tie(0); solve(); }
#include <bits/stdc++.h> #define pb push_back #define fo(i, n) for (int i = 0; i < n; i++) #define ll long long #define int long long #define Mod 1000000007 #define MAX 4294967296 // 2^32 const int M = 1e9 + 7; #define ip pair<int, int> #define test(t) \ ll t; \ cin >> t; \ while (t--) using namespace std; long long gcd(int x, int y) { if (y > x) swap(x, y); if (y == 0) return x; return gcd(y, x % y); } void solve() { int n; cin >> n; int a[n]; int count = 0; fo(i, n) { cin >> a[i]; } int ans = a[0]; for (int i = 1; i < n; i++) { if (a[i] == 1 || ans == 1) break; ans = gcd(ans, a[i]); } if (ans > 1) { cout << "not coprime"; return; } map<int, int> mp; fo(i, n) { int t = a[i]; if (t == 1) { continue; } if (t % 2 == 0) { mp[2]++; while (t % 2 == 0 && t != 1) t /= 2; } for (int j = 3; j <= sqrt(t); j += 2) { if (t % j == 0) { mp[j]++; while (t % j == 0 && t != 1) t /= j; if (t == 1) break; } } if (t > 2) mp[t]++; } for (auto it = mp.begin(); it != mp.end(); it++) { if (it->second > (int)1) { cout << "setwise coprime"; return; } } cout << "pairwise coprime"; } signed main() { // std::string binary = std::bitset<8>(n).to_string(); ios::sync_with_stdio(0); cin.tie(0); solve(); }
replace
56
57
56
57
TLE
p02574
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define all(x) (x).begin(), (x).end() int main() { ll i, j, n, m; cin >> n; vector<ll> a(n); for (i = 0; i < n; i++) cin >> a[i]; map<ll, bool> mp; for (i = 0; i < n; i++) { ll cur = a[i]; ll pr = 0; while (cur % 2 == 0) { cur /= 2; pr = 1; } if (pr == 1) { if (mp.find(2) == mp.end()) { mp[2] = 1; } else { ll gcd = 0; for (ll k = 0; k < n; k++) gcd = __gcd(gcd, a[k]); if (gcd == 1) cout << "setwise coprime\n"; else cout << "not coprime\n"; return 0; } } for (j = 3; j <= cur; j += 2) { ll pr = 0; while (cur % j == 0) { cur /= j; pr = 1; } if (pr == 1) { if (mp.find(j) == mp.end()) { mp[j] = 1; } else { ll gcd = 0; for (ll k = 0; k < n; k++) gcd = __gcd(gcd, a[k]); if (gcd == 1) cout << "setwise coprime\n"; else cout << "not coprime\n"; return 0; } } } if (cur != 1) { if (mp.find(cur) == mp.end()) mp[cur] = 1; else { ll gcd = 0; for (ll k = 0; k < n; k++) gcd = __gcd(gcd, a[k]); if (gcd == 1) cout << "setwise coprime\n"; else cout << "not coprime\n"; return 0; } } } cout << "pairwise coprime\n"; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define all(x) (x).begin(), (x).end() int main() { ll i, j, n, m; cin >> n; vector<ll> a(n); for (i = 0; i < n; i++) cin >> a[i]; map<ll, bool> mp; for (i = 0; i < n; i++) { ll cur = a[i]; ll pr = 0; while (cur % 2 == 0) { cur /= 2; pr = 1; } if (pr == 1) { if (mp.find(2) == mp.end()) { mp[2] = 1; } else { ll gcd = 0; for (ll k = 0; k < n; k++) gcd = __gcd(gcd, a[k]); if (gcd == 1) cout << "setwise coprime\n"; else cout << "not coprime\n"; return 0; } } for (j = 3; j * j <= cur; j += 2) { ll pr = 0; while (cur % j == 0) { cur /= j; pr = 1; } if (pr == 1) { if (mp.find(j) == mp.end()) { mp[j] = 1; } else { ll gcd = 0; for (ll k = 0; k < n; k++) gcd = __gcd(gcd, a[k]); if (gcd == 1) cout << "setwise coprime\n"; else cout << "not coprime\n"; return 0; } } } if (cur != 1) { if (mp.find(cur) == mp.end()) mp[cur] = 1; else { ll gcd = 0; for (ll k = 0; k < n; k++) gcd = __gcd(gcd, a[k]); if (gcd == 1) cout << "setwise coprime\n"; else cout << "not coprime\n"; return 0; } } } cout << "pairwise coprime\n"; }
replace
34
35
34
35
TLE
p02574
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define mp make_pair #define pb push_back #define pii pair<int, int> #define pll pair<long long, long long> #define fastio() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define endl "\n" #define Debug(x) cout << (#x) << " >> " << (x) << endl using namespace std; ll fastpow(ll angka, ll pangkat, ll MOD) { ll res = 1; while (pangkat) { if (pangkat & 1) res = (res * angka) % MOD; angka = (angka * angka) % MOD; pangkat = pangkat >> 1; } return res; } ll fastpow(ll angka, ll pangkat) { ll res = 1; while (pangkat) { if (pangkat & 1) res = (res * angka); angka = (angka * angka); pangkat = pangkat >> 1; } return res; } ll gcd(ll angka1, ll angka2) { while (angka2) { swap(angka1, angka2); angka2 = angka2 % angka1; } return angka1; } ll lcm(ll angka1, ll angka2) { return (angka1 / gcd(angka1, angka2)) * angka2; } const ll mod = 1000000007; vector<int> spf; void precompute_spf() { const int n = 2000000; spf.resize(n); int batas = sqrt(n); for (int i = 2; i < n; i++) spf[i] = i; for (int i = 2; i < n; i++) { if (spf[i] == i) { int j = i * i; while (j < n) { if (spf[j] == j) spf[j] = i; j += i; } } } // for(int i=0;i<30;i++) cout<<i<<" "<<spf[i]<<endl; } void solve() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; bool isPairWise = true; unordered_map<int, int> um; for (auto x : v) { unordered_set<int> st; int val = x; while (val > 1) { st.insert(spf[val]); val = val / spf[val]; } for (auto x : st) { um[x]++; if (um[x] > 1) { isPairWise = false; break; } } if (!isPairWise) break; } if (isPairWise) { cout << "pairwise coprime" << endl; return; } int cur = v[0]; for (int i = 0; i < n; i++) { cur = gcd(cur, v[i]); // cout<<cur<<endl; } if (cur == 1) cout << "setwise coprime" << endl; else cout << "not coprime" << endl; } int main() { fastio(); precompute_spf(); int t = 1; // cin>>t; for (int tt = 0; tt < t; tt++) { // cout<<"Case "<<tt+1<<":\n";solve(); solve(); } return 0; }
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define mp make_pair #define pb push_back #define pii pair<int, int> #define pll pair<long long, long long> #define fastio() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define endl "\n" #define Debug(x) cout << (#x) << " >> " << (x) << endl using namespace std; ll fastpow(ll angka, ll pangkat, ll MOD) { ll res = 1; while (pangkat) { if (pangkat & 1) res = (res * angka) % MOD; angka = (angka * angka) % MOD; pangkat = pangkat >> 1; } return res; } ll fastpow(ll angka, ll pangkat) { ll res = 1; while (pangkat) { if (pangkat & 1) res = (res * angka); angka = (angka * angka); pangkat = pangkat >> 1; } return res; } ll gcd(ll angka1, ll angka2) { while (angka2) { swap(angka1, angka2); angka2 = angka2 % angka1; } return angka1; } ll lcm(ll angka1, ll angka2) { return (angka1 / gcd(angka1, angka2)) * angka2; } const ll mod = 1000000007; vector<int> spf; void precompute_spf() { const int n = 2000000; spf.resize(n); int batas = sqrt(n); for (int i = 2; i < n; i++) spf[i] = i; for (int i = 2; i <= batas; i++) { if (spf[i] == i) { int j = i * i; while (j < n) { if (spf[j] == j) spf[j] = i; j += i; } } } // for(int i=0;i<30;i++) cout<<i<<" "<<spf[i]<<endl; } void solve() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; bool isPairWise = true; unordered_map<int, int> um; for (auto x : v) { unordered_set<int> st; int val = x; while (val > 1) { st.insert(spf[val]); val = val / spf[val]; } for (auto x : st) { um[x]++; if (um[x] > 1) { isPairWise = false; break; } } if (!isPairWise) break; } if (isPairWise) { cout << "pairwise coprime" << endl; return; } int cur = v[0]; for (int i = 0; i < n; i++) { cur = gcd(cur, v[i]); // cout<<cur<<endl; } if (cur == 1) cout << "setwise coprime" << endl; else cout << "not coprime" << endl; } int main() { fastio(); precompute_spf(); int t = 1; // cin>>t; for (int tt = 0; tt < t; tt++) { // cout<<"Case "<<tt+1<<":\n";solve(); solve(); } return 0; }
replace
62
63
62
63
-11
p02574
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <fstream> #define ll long long #define ld long double // #define int long long #define MOD 1000000007 #define mod 1000000007 #define ff first #define ss second #define pb push_back #define vi vector<int> #define pii pair<int, int> #define vii vector<pii> #define vvi vector<vi> #define mp make_pair #define endl "\n" using namespace std; int gcd(int a, int b) { // Everything divides 0 if (a == 0) return b; if (b == 0) return a; // base case if (a == b) return a; // a is greater if (a > b) return gcd(a - b, b); return gcd(a, b - a); } bool allprime[1000001] = {0}; vector<int> sieve_of_primes_upto_10e6() { int n = 1000007; vector<int> set_of_primes; set_of_primes.push_back(2); int p; for (p = 3; p * p <= n; p += 2) { if (allprime[p] == 0) { set_of_primes.push_back(p); for (int i = p * p; i <= n; i += p) { allprime[i] = 1; } } } for (p; p <= n; p += 2) { if (allprime[p] == 0) { set_of_primes.push_back(p); } } return set_of_primes; } void solve1(); void solve() { int T; cin >> T; for (int z = 1; z <= T; z++) { solve1(); } } signed main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve1(); return 0; } int vis[1000007] = {0}; void solve1() { int n; cin >> n; int arr[n]; cin >> arr[0]; int c = arr[0]; for (int i = 1; i < n; i++) { cin >> arr[i]; c = gcd(c, arr[i]); } if (c > 1) { cout << "not coprime" << endl; return; } vi vec = sieve_of_primes_upto_10e6(); for (int i = 0; i < n; i++) { if (arr[i] != 1 && vis[arr[i]] > 0) { cout << "setwise coprime" << endl; return; } int j = 0; while (arr[i] >= vec[j] * vec[j]) { if (vis[vec[j]] == 0) { while (arr[i] % vec[j] == 0) { arr[i] /= vec[j]; vis[vec[j]]++; } } else if (arr[i] % vec[j] == 0) { cout << "setwise coprime" << endl; return; } j++; } if (vis[arr[i]] == 0) vis[arr[i]]++; else if (arr[i] != 1) { cout << "setwise coprime" << endl; return; } } /*for(int i=0;i<10;i++) { cout<<vis[i]<<" "; }*/ cout << "pairwise coprime" << endl; }
#include <bits/stdc++.h> #include <fstream> #define ll long long #define ld long double // #define int long long #define MOD 1000000007 #define mod 1000000007 #define ff first #define ss second #define pb push_back #define vi vector<int> #define pii pair<int, int> #define vii vector<pii> #define vvi vector<vi> #define mp make_pair #define endl "\n" using namespace std; int gcd(int a, int b) { // Everything divides 0 if (a == 0) return b; if (b == 0) return a; // base case if (a == b) return a; // a is greater if (a > b) return gcd(a - b, b); return gcd(a, b - a); } bool allprime[1000001] = {0}; vector<int> sieve_of_primes_upto_10e6() { int n = 1000007; vector<int> set_of_primes; set_of_primes.push_back(2); int p; for (p = 3; p * p <= n; p += 2) { if (allprime[p] == 0) { set_of_primes.push_back(p); for (int i = p * p; i <= n; i += p) { allprime[i] = 1; } } } for (p; p <= n; p += 2) { if (allprime[p] == 0) { set_of_primes.push_back(p); } } return set_of_primes; } void solve1(); void solve() { int T; cin >> T; for (int z = 1; z <= T; z++) { solve1(); } } signed main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve1(); return 0; } int vis[1000007] = {0}; void solve1() { int n; cin >> n; int arr[n]; cin >> arr[0]; int c = arr[0]; for (int i = 1; i < n; i++) { cin >> arr[i]; c = __gcd(c, arr[i]); } if (c > 1) { cout << "not coprime" << endl; return; } vi vec = sieve_of_primes_upto_10e6(); for (int i = 0; i < n; i++) { if (arr[i] != 1 && vis[arr[i]] > 0) { cout << "setwise coprime" << endl; return; } int j = 0; while (arr[i] >= vec[j] * vec[j]) { if (vis[vec[j]] == 0) { while (arr[i] % vec[j] == 0) { arr[i] /= vec[j]; vis[vec[j]]++; } } else if (arr[i] % vec[j] == 0) { cout << "setwise coprime" << endl; return; } j++; } if (vis[arr[i]] == 0) vis[arr[i]]++; else if (arr[i] != 1) { cout << "setwise coprime" << endl; return; } } /*for(int i=0;i<10;i++) { cout<<vis[i]<<" "; }*/ cout << "pairwise coprime" << endl; }
replace
79
80
79
80
TLE
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define ull unsigned long long #define pii pair<int, int> #define pll pair<ll, ll> #define _h cout << "here" << endl; #define fill(a, v) memset(a, v, sizeof(a)); #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < n; i += 1) #define prd(a, n) \ rep(i, n) cout << a[i] << " \n"[i == n - 1]; // printf("%s\n"," " ); #define ff first #define ss second #define pu push_back const int inf = 1e9 + 10; const ll INF = 2e18 + 10; const int Mod = 1e9 + 7; const int MAXN = 1000010; const int N = 1e6 + 10; const int M = 210; const int M1 = 1e9 + 7; const int M2 = 1e9 + 9; const int base = 131; int n, cnt[N], g = 0; vector<int> a; int main() { ios::sync_with_stdio(0), cin.tie(0); cout.tie(0); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); cin >> n; for (int i = 1; i <= n; i++) { int x; cin >> x; g = __gcd(g, x); if (x == 1) continue; a.push_back(x); cnt[x]++; } int flag = 0; for (int i = 2; i < N; i++) { if (cnt[i] > 1) { flag = 1; break; } } if (flag) { if (g == 1) cout << "setwise coprime" << endl; else cout << "not coprime" << endl; } else { set<int> s; for (int i = 0; i < a.size(); i++) s.insert(a[i]); auto it1 = s.end(); it1--; int mx = (*it1); for (int i = 2; i <= mx; i++) { int cnt = 0; for (int j = i; j <= mx; j += i) { auto it = s.find(j); if (it != s.end()) { cnt++; } if (cnt > 1) { if (g == 1) cout << "setwise coprime" << endl; else cout << "not coprime" << endl; return 0; } } } cout << "pairwise coprime" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define ull unsigned long long #define pii pair<int, int> #define pll pair<ll, ll> #define _h cout << "here" << endl; #define fill(a, v) memset(a, v, sizeof(a)); #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < n; i += 1) #define prd(a, n) \ rep(i, n) cout << a[i] << " \n"[i == n - 1]; // printf("%s\n"," " ); #define ff first #define ss second #define pu push_back const int inf = 1e9 + 10; const ll INF = 2e18 + 10; const int Mod = 1e9 + 7; const int MAXN = 1000010; const int N = 1e6 + 10; const int M = 210; const int M1 = 1e9 + 7; const int M2 = 1e9 + 9; const int base = 131; int n, cnt[N], g = 0; vector<int> a; int main() { ios::sync_with_stdio(0), cin.tie(0); cout.tie(0); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); cin >> n; for (int i = 1; i <= n; i++) { int x; cin >> x; g = __gcd(g, x); if (x == 1) continue; a.push_back(x); cnt[x]++; } if (a.size() == 0) { cout << "pairwise coprime" << endl; return 0; } int flag = 0; for (int i = 2; i < N; i++) { if (cnt[i] > 1) { flag = 1; break; } } if (flag) { if (g == 1) cout << "setwise coprime" << endl; else cout << "not coprime" << endl; } else { set<int> s; for (int i = 0; i < a.size(); i++) s.insert(a[i]); auto it1 = s.end(); it1--; int mx = (*it1); for (int i = 2; i <= mx; i++) { int cnt = 0; for (int j = i; j <= mx; j += i) { auto it = s.find(j); if (it != s.end()) { cnt++; } if (cnt > 1) { if (g == 1) cout << "setwise coprime" << endl; else cout << "not coprime" << endl; return 0; } } } cout << "pairwise coprime" << endl; } return 0; }
insert
42
42
42
46
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define rep(i, n, m) for (int i = (n); i < (m); i++) #define rep_d(i, n, m) for (int i = (n)-1; i >= (m); i--) #define sort_asc(X) sort((X).begin(), (X).end()) #define sort_desc(X) sort((X).begin(), (X).end(), greater<>()) #define endl "\n" template <class T> bool chmax(T &a, T b); template <class T> bool chmin(T &a, T b); int *eratosthenes(int N); bool bit_search(int pattern, int N); void initialize(void); const ll INF = 1LL << 60; const int k_mod = 1e9 + 7; template <typename T, typename K> struct P { T a; K b; }; typedef struct { vector<int> to; int cost; } edge; vector<int> prime_factorize(ll N) { vector<int> vec; int lim = sqrt(N) + 1; rep(i, 2, N + 1) { if (i >= lim) { vec.push_back(N); break; } if (N % i == 0) { vec.push_back(i); while (N % i == 0) N /= i; } } return vec; } int main(void) { // initialize(); int N; cin >> N; vector<int> inputs(N), vec(N - 1); rep(i, 0, N) scanf("%d", &inputs[i]); int GCD = __gcd(inputs[0], inputs[1]); vec[0] = GCD; rep(i, 2, N) { GCD = __gcd(GCD, inputs[i]); vec[i - 1]; } if (GCD != 1) { printf("not coprime\n"); return 0; } vector<bool> used(N + 5, false); for (auto input : inputs) { const auto &vec = prime_factorize(input); for (auto v : vec) { if (used[v]) { printf("setwise coprime\n"); return 0; } used[v] = true; } } printf("pairwise coprime\n"); } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int *eratosthenes(int N) { int *prime_array = new int[N + 1]; int lim = N; prime_array[0] = 0; prime_array[1] = 0; rep(i, 2, N + 1) { prime_array[i] = 1; } rep(i, 2, lim) { if (prime_array[i] == 0) continue; lim = N / i; for (int j = i * 2; j < N + 1; j += i) { prime_array[j] = 0; } } return prime_array; } bool bit_search(int pattern, int N) { int cnt = 0; rep(bit, 0, N) { if (pattern & (1 << bit)) { cnt++; } } return true; } void initialize(void) { cout << fixed << setprecision(10); }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define rep(i, n, m) for (int i = (n); i < (m); i++) #define rep_d(i, n, m) for (int i = (n)-1; i >= (m); i--) #define sort_asc(X) sort((X).begin(), (X).end()) #define sort_desc(X) sort((X).begin(), (X).end(), greater<>()) #define endl "\n" template <class T> bool chmax(T &a, T b); template <class T> bool chmin(T &a, T b); int *eratosthenes(int N); bool bit_search(int pattern, int N); void initialize(void); const ll INF = 1LL << 60; const int k_mod = 1e9 + 7; template <typename T, typename K> struct P { T a; K b; }; typedef struct { vector<int> to; int cost; } edge; vector<int> prime_factorize(ll N) { vector<int> vec; int lim = sqrt(N) + 1; rep(i, 2, N + 1) { if (i >= lim) { vec.push_back(N); break; } if (N % i == 0) { vec.push_back(i); while (N % i == 0) N /= i; } } return vec; } int main(void) { // initialize(); int N; cin >> N; vector<int> inputs(N), vec(N - 1); rep(i, 0, N) scanf("%d", &inputs[i]); int GCD = __gcd(inputs[0], inputs[1]); vec[0] = GCD; rep(i, 2, N) { GCD = __gcd(GCD, inputs[i]); vec[i - 1]; } if (GCD != 1) { printf("not coprime\n"); return 0; } vector<bool> used((int)(1e6 + 5), false); for (auto input : inputs) { const auto &vec = prime_factorize(input); for (auto v : vec) { if (used[v]) { printf("setwise coprime\n"); return 0; } used[v] = true; } } printf("pairwise coprime\n"); } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int *eratosthenes(int N) { int *prime_array = new int[N + 1]; int lim = N; prime_array[0] = 0; prime_array[1] = 0; rep(i, 2, N + 1) { prime_array[i] = 1; } rep(i, 2, lim) { if (prime_array[i] == 0) continue; lim = N / i; for (int j = i * 2; j < N + 1; j += i) { prime_array[j] = 0; } } return prime_array; } bool bit_search(int pattern, int N) { int cnt = 0; rep(bit, 0, N) { if (pattern & (1 << bit)) { cnt++; } } return true; } void initialize(void) { cout << fixed << setprecision(10); }
replace
59
60
59
60
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using pll = pair<ll, ll>; #define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i) #define all(x) (x).begin(), (x).end() template <class T1, class T2> inline void chmax(T1 &a, const T2 &b) { if (a < b) a = b; } template <class T1, class T2> inline void chmin(T1 &a, const T2 &b) { if (a > b) a = b; } constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL; constexpr ll mod = 1000000007; int main() { int N; cin >> N; int max_num = 0; vector<int> A(N); rep(i, N) { cin >> A[i]; chmax(max_num, A[i]); } vector<int> prime(max_num + 1, 0); for (int i = 2; i < max_num + 1; ++i) { if (prime[i] == 0) { for (int j = i; j <= max_num + 1; j += i) { if (prime[j] == 0) { prime[j] = i; } } } } vector<int> s(N + 1, 0); for (int i = 0; i < N; ++i) { int num = A[i]; set<int> tmp; while (num != 1) { tmp.emplace(prime[num]); num /= prime[num]; } for (auto x : tmp) { ++s[x]; } } bool is_pairwise = true; for (auto x : s) { if (x == N) { cout << "not coprime" << endl; return 0; } else if (x > 1) { is_pairwise = false; } } if (is_pairwise) { cout << "pairwise coprime" << endl; } else { cout << "setwise coprime" << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using pll = pair<ll, ll>; #define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i) #define all(x) (x).begin(), (x).end() template <class T1, class T2> inline void chmax(T1 &a, const T2 &b) { if (a < b) a = b; } template <class T1, class T2> inline void chmin(T1 &a, const T2 &b) { if (a > b) a = b; } constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL; constexpr ll mod = 1000000007; int main() { int N; cin >> N; int max_num = 0; vector<int> A(N); rep(i, N) { cin >> A[i]; chmax(max_num, A[i]); } vector<int> prime(max_num + 1, 0); for (int i = 2; i < max_num + 1; ++i) { if (prime[i] == 0) { for (int j = i; j <= max_num + 1; j += i) { if (prime[j] == 0) { prime[j] = i; } } } } vector<int> s(max_num + 1, 0); for (int i = 0; i < N; ++i) { int num = A[i]; set<int> tmp; while (num != 1) { tmp.emplace(prime[num]); num /= prime[num]; } for (auto x : tmp) { ++s[x]; } } bool is_pairwise = true; for (auto x : s) { if (x == N) { cout << "not coprime" << endl; return 0; } else if (x > 1) { is_pairwise = false; } } if (is_pairwise) { cout << "pairwise coprime" << endl; } else { cout << "setwise coprime" << endl; } }
replace
46
47
46
47
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (n); i++) using namespace std; typedef long long ll; const int MX = 100003; int main() { ll n; cin >> n; vector<ll> a(n), c(MX, 0); rep(i, n) cin >> a[i], c[a[i]]++; ll g = 0; rep(i, n) g = __gcd(g, a[i]); if (g != 1) { cout << "not coprime" << endl; return 0; } bool pairwise = true; for (int i = 2; i < MX; ++i) { ll cnt = 0; for (int j = i; j < MX; j += i) cnt += c[j]; if (cnt > 1) pairwise = false; } cout << (pairwise ? "pairwise coprime" : "setwise coprime") << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (n); i++) using namespace std; typedef long long ll; const int MX = 1000003; int main() { ll n; cin >> n; vector<ll> a(n), c(MX, 0); rep(i, n) cin >> a[i], c[a[i]]++; ll g = 0; rep(i, n) g = __gcd(g, a[i]); if (g != 1) { cout << "not coprime" << endl; return 0; } bool pairwise = true; for (int i = 2; i < MX; ++i) { ll cnt = 0; for (int j = i; j < MX; j += i) cnt += c[j]; if (cnt > 1) pairwise = false; } cout << (pairwise ? "pairwise coprime" : "setwise coprime") << endl; return 0; }
replace
6
7
6
7
0
p02574
C++
Runtime Error
// abc177_e #include <bits/stdc++.h> #ifdef LOCAL #include "../cxx-prettyprint/prettyprint.hpp" #endif using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; #define REP(i, n) for (int(i) = 0; (i) < (int)(n); ++(i)) #define REPN(i, m, n) for (int(i) = m; (i) < (int)(n); ++(i)) #define REP_REV(i, n) for (int(i) = (int)(n)-1; (i) >= 0; --(i)) #define REPN_REV(i, m, n) for (int(i) = (int)(n)-1; (i) >= m; --(i)) #define ALL(x) x.begin(), x.end() #define INF (ll)(1e9) #define MOD (1000000007) #define print2D(h, w, arr) \ REP(i, h) { \ REP(j, w) cout << arr[i][j] << " "; \ cout << endl; \ } #define print_line(vec, n) \ { \ for (int idx = 0; idx < (n - 1); idx++) \ cout << (vec)[idx] << " "; \ cout << (vec)[(n)-1] << endl; \ } template <class T> void print(const T &x) { cout << x << "\n"; } template <class T, class... A> void print(const T &first, const A &...rest) { cout << first << " "; print(rest...); } struct PreMain { PreMain() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } premain; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { #ifdef LOCAL ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf()); #endif int N; cin >> N; vector<int> A(N); REP(i, N) cin >> A[i]; bool pairwise = true; vector<int> res(1e4); REP(i, N) { ll tmp = A[i]; for (ll a = 2; a * a <= A[i]; a++) { int cnt = 0; while (tmp % a == 0) { cnt++; tmp /= a; } if (cnt > 0) { if (res[a] > 0) { pairwise = false; break; } res[a]++; } } if (tmp > 1) { if (res[tmp] > 0) { pairwise = false; break; } res[tmp]++; } if (pairwise == false) break; } // print(res); // for (auto e: res){ // if (e.second >= 2){ // pairwise = false; // break; // } // } if (pairwise) { print("pairwise coprime"); return 0; } int d = 0; REP(i, N) { d = gcd(A[i], d); } // print(d); if (d == 1) { print("setwise coprime"); } else { print("not coprime"); } return 0; }
// abc177_e #include <bits/stdc++.h> #ifdef LOCAL #include "../cxx-prettyprint/prettyprint.hpp" #endif using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; #define REP(i, n) for (int(i) = 0; (i) < (int)(n); ++(i)) #define REPN(i, m, n) for (int(i) = m; (i) < (int)(n); ++(i)) #define REP_REV(i, n) for (int(i) = (int)(n)-1; (i) >= 0; --(i)) #define REPN_REV(i, m, n) for (int(i) = (int)(n)-1; (i) >= m; --(i)) #define ALL(x) x.begin(), x.end() #define INF (ll)(1e9) #define MOD (1000000007) #define print2D(h, w, arr) \ REP(i, h) { \ REP(j, w) cout << arr[i][j] << " "; \ cout << endl; \ } #define print_line(vec, n) \ { \ for (int idx = 0; idx < (n - 1); idx++) \ cout << (vec)[idx] << " "; \ cout << (vec)[(n)-1] << endl; \ } template <class T> void print(const T &x) { cout << x << "\n"; } template <class T, class... A> void print(const T &first, const A &...rest) { cout << first << " "; print(rest...); } struct PreMain { PreMain() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } premain; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { #ifdef LOCAL ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf()); #endif int N; cin >> N; vector<int> A(N); REP(i, N) cin >> A[i]; bool pairwise = true; vector<int> res(1e6 + 1); REP(i, N) { ll tmp = A[i]; for (ll a = 2; a * a <= A[i]; a++) { int cnt = 0; while (tmp % a == 0) { cnt++; tmp /= a; } if (cnt > 0) { if (res[a] > 0) { pairwise = false; break; } res[a]++; } } if (tmp > 1) { if (res[tmp] > 0) { pairwise = false; break; } res[tmp]++; } if (pairwise == false) break; } // print(res); // for (auto e: res){ // if (e.second >= 2){ // pairwise = false; // break; // } // } if (pairwise) { print("pairwise coprime"); return 0; } int d = 0; REP(i, N) { d = gcd(A[i], d); } // print(d); if (d == 1) { print("setwise coprime"); } else { print("not coprime"); } return 0; }
replace
60
61
60
61
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define fi first #define se second #define pb push_back #define mp make_pair #define fo(i, n) for (i = 0; i < n; i++) #define fo1(i, n) for (i = 1; i <= n; i++) #define foab(i, a, b) for (i = a; i <= b; i++) #define of(i, n) for (i = n - 1; i >= 0; i--) #define of1(i, n) for (i = n; i >= 1; i--) #define ofab(i, a, b) for (i = a; i >= b; i--) #define sq(a) (a) * (a) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sortall(x) sort(all(x)) #define sortrall(x) sort(rall(x)) #define clr(x) memset(x, 0, sizeof(x)) #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define pii pair<int, int> #define mk(arr, n, type) type *arr = new type[n]; #define vi vector<int> #define vpii vector<pii> #define si set<int> #define spii set<pii> #define usi unordered_set<int> #define uspii unordered_set<pii> #define mii map<int, int> #define umii unordered_map<int, int> #define pqmx priority_queue<int> #define pqmn priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define trailzrobits(x) __builtin_ctzll(x) #define leadzrobits(x) __builtin_clzll(x) #define paritybits(x) __builtin_parityll(x) #define gcd __gcd #define lcm(x, y) (x * y) / gcd(x, y) #define endl '\n' #define sz(s) (int)s.size() #define sp(x, y) fixed << setprecision(y) << x const int mod = 1000000007; const int inf = 1000000000000000000; const ld PI = 3.1415926535897932384626; const ld eps = 1e-12; void __print(int32_t x) { cout << x; } void __print(int x) { cout << x; } void __print(double x) { cout << x; } void __print(ld x) { cout << x; } void __print(float x) { cout << x; } void __print(bool x) { cout << (x ? "true" : "false"); } void __print(char x) { cout << '\'' << x << '\''; } void __print(const char *x) { cout << '\"' << x << '\"'; } void __print(const string &x) { cout << '\"' << x << '\"'; } template <typename T, typename V> void __print(const pair<T, V> &x) { cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}'; } template <typename T> void __print(const T &x) { int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}"; } void _print() { cout << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cout << ", "; _print(v...); } // #ifndef ONLINE_JUDGE #define dbg(x...) \ cout << "[" << #x << "]=["; \ _print(x) // #else // #define dbg(x...) // #endif int powerMod(int base, int exp) { int res = 1; base %= mod; while (exp > 0) { if (exp & 1) res = (res * base) % mod; base = (base * base) % mod; exp = exp >> 1; } return res; } int power(int base, int exp) { int res = 1; while (exp > 0) { if (exp & 1) res = res * base; base = base * base; exp = exp >> 1; } return res; } int inv(int x) { return powerMod(x, mod - 2) % mod; } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ const int N = 1e2 + 6, M = N; vi spf(N, 1); void seive() { for (int i = 2; i < (N); i++) { if (spf[i] == 1) { spf[i] = i; for (int j = 2 * i; j < N; j += i) { spf[j] = i; } } } } vi hash1(N); void getFactorization(int x) { int temp; while (x != 1) { temp = spf[x]; if (x % temp == 0) { hash1[temp]++; x = x / temp; } while (x % temp == 0) x = x / temp; } } bool check(int x) { int temp; while (x != 1) { temp = spf[x]; if (x % temp == 0 and hash1[temp] > 1) return 1; while (x % temp == 0) x = x / temp; } return 0; } void solve() { int i, j, k; int n; cin >> n; vi a(n); fo(i, n) cin >> a[i]; int g = a[0]; fo(i, n) g = gcd(g, a[i]); if (g != 1) { cout << "not coprime\n"; return; } seive(); fo(i, n) getFactorization(a[i]); bool f = 0; fo(i, n) if (check(a[i])) f = 1; cout << (f ? "setwise coprime" : "pairwise coprime") << endl; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t, T = 1; // cin>>T; fo1(t, T) { // cout<<"Case #"<<t<<": "; solve(); } // cout<<endl<<"Times Elapsed:"<<1.0*clock()/CLOCKS_PER_SEC<<"sec"; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define fi first #define se second #define pb push_back #define mp make_pair #define fo(i, n) for (i = 0; i < n; i++) #define fo1(i, n) for (i = 1; i <= n; i++) #define foab(i, a, b) for (i = a; i <= b; i++) #define of(i, n) for (i = n - 1; i >= 0; i--) #define of1(i, n) for (i = n; i >= 1; i--) #define ofab(i, a, b) for (i = a; i >= b; i--) #define sq(a) (a) * (a) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sortall(x) sort(all(x)) #define sortrall(x) sort(rall(x)) #define clr(x) memset(x, 0, sizeof(x)) #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define pii pair<int, int> #define mk(arr, n, type) type *arr = new type[n]; #define vi vector<int> #define vpii vector<pii> #define si set<int> #define spii set<pii> #define usi unordered_set<int> #define uspii unordered_set<pii> #define mii map<int, int> #define umii unordered_map<int, int> #define pqmx priority_queue<int> #define pqmn priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define trailzrobits(x) __builtin_ctzll(x) #define leadzrobits(x) __builtin_clzll(x) #define paritybits(x) __builtin_parityll(x) #define gcd __gcd #define lcm(x, y) (x * y) / gcd(x, y) #define endl '\n' #define sz(s) (int)s.size() #define sp(x, y) fixed << setprecision(y) << x const int mod = 1000000007; const int inf = 1000000000000000000; const ld PI = 3.1415926535897932384626; const ld eps = 1e-12; void __print(int32_t x) { cout << x; } void __print(int x) { cout << x; } void __print(double x) { cout << x; } void __print(ld x) { cout << x; } void __print(float x) { cout << x; } void __print(bool x) { cout << (x ? "true" : "false"); } void __print(char x) { cout << '\'' << x << '\''; } void __print(const char *x) { cout << '\"' << x << '\"'; } void __print(const string &x) { cout << '\"' << x << '\"'; } template <typename T, typename V> void __print(const pair<T, V> &x) { cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}'; } template <typename T> void __print(const T &x) { int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}"; } void _print() { cout << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cout << ", "; _print(v...); } // #ifndef ONLINE_JUDGE #define dbg(x...) \ cout << "[" << #x << "]=["; \ _print(x) // #else // #define dbg(x...) // #endif int powerMod(int base, int exp) { int res = 1; base %= mod; while (exp > 0) { if (exp & 1) res = (res * base) % mod; base = (base * base) % mod; exp = exp >> 1; } return res; } int power(int base, int exp) { int res = 1; while (exp > 0) { if (exp & 1) res = res * base; base = base * base; exp = exp >> 1; } return res; } int inv(int x) { return powerMod(x, mod - 2) % mod; } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ const int N = 1e6 + 6, M = N; vi spf(N, 1); void seive() { for (int i = 2; i < (N); i++) { if (spf[i] == 1) { spf[i] = i; for (int j = 2 * i; j < N; j += i) { spf[j] = i; } } } } vi hash1(N); void getFactorization(int x) { int temp; while (x != 1) { temp = spf[x]; if (x % temp == 0) { hash1[temp]++; x = x / temp; } while (x % temp == 0) x = x / temp; } } bool check(int x) { int temp; while (x != 1) { temp = spf[x]; if (x % temp == 0 and hash1[temp] > 1) return 1; while (x % temp == 0) x = x / temp; } return 0; } void solve() { int i, j, k; int n; cin >> n; vi a(n); fo(i, n) cin >> a[i]; int g = a[0]; fo(i, n) g = gcd(g, a[i]); if (g != 1) { cout << "not coprime\n"; return; } seive(); fo(i, n) getFactorization(a[i]); bool f = 0; fo(i, n) if (check(a[i])) f = 1; cout << (f ? "setwise coprime" : "pairwise coprime") << endl; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t, T = 1; // cin>>T; fo1(t, T) { // cout<<"Case #"<<t<<": "; solve(); } // cout<<endl<<"Times Elapsed:"<<1.0*clock()/CLOCKS_PER_SEC<<"sec"; return 0; }
replace
108
109
108
109
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define F first #define S second #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define ppb pop_back #define vll vector<ll> #define vi vector<int> #define endl "\n" const ll INF = 1000000007; /* const int max_size = 100001; int parent[max_size]; int Size[max_size]; int root(int x){ while(x!=parent[x]){ parent[x] = parent[parent[x]]; x = parent[x]; } return x; } void sunion(int x,int y){ int rx = root(x); int ry = root(y); if(rx != ry){ if(Size[rx] > Size[ry]){ parent[ry] = parent[rx]; Size[rx] += Size[ry]; } else{ parent[rx] = parent[ry]; Size[ry] += Size[rx]; } } } */ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc = 1; // cin >> tc; const int N = 1000; int lp[N + 1]; vector<int> pr; for (int i = 2; i <= N; ++i) { if (lp[i] == 0) { lp[i] = i; pr.push_back(i); } for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j) lp[i * pr[j]] = pr[j]; } while (tc--) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; map<int, int> c; for (auto x : a) { int t = x; for (int j = 0; pr[j] * pr[j] <= t; j++) { if (t % pr[j] == 0) c[pr[j]]++; while (t % pr[j] == 0) t /= pr[j]; } if (t != 1) c[t]++; } bool ok = true; for (auto x : c) { if (x.second >= 2) { ok = false; break; } } if (ok) cout << "pairwise coprime\n"; else { int g = a[0]; for (int i = 0; i < n; i++) g = __gcd(g, a[i]); if (g == 1) cout << "setwise coprime\n"; else cout << "not coprime\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define F first #define S second #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define ppb pop_back #define vll vector<ll> #define vi vector<int> #define endl "\n" const ll INF = 1000000007; /* const int max_size = 100001; int parent[max_size]; int Size[max_size]; int root(int x){ while(x!=parent[x]){ parent[x] = parent[parent[x]]; x = parent[x]; } return x; } void sunion(int x,int y){ int rx = root(x); int ry = root(y); if(rx != ry){ if(Size[rx] > Size[ry]){ parent[ry] = parent[rx]; Size[rx] += Size[ry]; } else{ parent[rx] = parent[ry]; Size[ry] += Size[rx]; } } } */ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc = 1; // cin >> tc; const int N = 1000; int lp[N + 1]; vector<int> pr; for (int i = 2; i <= N; ++i) { if (lp[i] == 0) { lp[i] = i; pr.push_back(i); } for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j) lp[i * pr[j]] = pr[j]; } while (tc--) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; map<int, int> c; for (auto x : a) { int t = x; for (int j = 0; j < (int)pr.size() && pr[j] * pr[j] <= t; j++) { if (t % pr[j] == 0) c[pr[j]]++; while (t % pr[j] == 0) t /= pr[j]; } if (t != 1) c[t]++; } bool ok = true; for (auto x : c) { if (x.second >= 2) { ok = false; break; } } if (ok) cout << "pairwise coprime\n"; else { int g = a[0]; for (int i = 0; i < n; i++) g = __gcd(g, a[i]); if (g == 1) cout << "setwise coprime\n"; else cout << "not coprime\n"; } } return 0; }
replace
72
73
72
73
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> #define all(X) (X).begin(), (X).end() #define ll long long #define linf (1ll << 60) using namespace std; // -------- FUNCS -------- // vector<string> SPLIT(string str, char ch) { vector<string> res; stringstream ss(str); string s; while (getline(ss, s, ch)) res.push_back(s); return res; } ll STOI(string str, int base) { ll res = 0; for (auto c : str) { res *= base; res += c - '0'; } return res; } string ITOS(ll val, int base) { string res; while (val > 0) { res += '0' + (val % base); val /= base; } reverse(all(res)); return res; } // Sieve of Eratosthenes // (*this)[i] = (divisor of i, greater than 1) // Example: [0, 1, 2, 3, 2, 5, 3, 7, 2, 3, 2, 11, ...] // Complexity: Space O(MAXN), Time (construction) O(MAXNloglogMAXN) struct SieveOfEratosthenes : std::vector<int> { std::vector<int> primes; SieveOfEratosthenes(int MAXN) : std::vector<int>(MAXN + 1) { std::iota(begin(), end(), 0); for (int i = 2; i <= MAXN; i++) { if ((*this)[i] == i) { primes.push_back(i); for (int j = i; j <= MAXN; j += i) (*this)[j] = i; } } } using T = long long int; // Prime factorization for x <= MAXN^2 // Complexity: O(log x) (x <= MAXN) // O(MAXN / logMAXN) (MAXN < x <= MAXN^2) std::map<T, int> Factorize(T x) { assert(x <= 1LL * (int(size()) - 1) * (int(size()) - 1)); std::map<T, int> ret; if (x < int(size())) { while (x > 1) { ret[(*this)[x]]++; x /= (*this)[x]; } } else { for (auto p : primes) { while (!(x % p)) x /= p, ret[p]++; if (x == 1) break; } if (x > 1) ret[x]++; } return ret; } std::vector<T> Divisors(T x) { std::vector<T> ret{1}; for (auto p : Factorize(x)) { int n = ret.size(); for (int i = 0; i < n; i++) { for (T a = 1, d = 1; d <= p.second; d++) { a *= p.first; ret.push_back(ret[i] * a); } } } return ret; // Not sorted } // Moebius function Table // return: [0=>0, 1=>1, 2=>-1, 3=>-1, 4=>0, 5=>-1, 6=>1, 7=>-1, 8=>0, ...] std::vector<int> GenerateMoebiusFunctionTable() { std::vector<int> ret(size()); for (int i = 1; i < int(size()); i++) { if (i == 1) ret[i] = 1; else if ((i / (*this)[i]) % (*this)[i] == 0) ret[i] = 0; else ret[i] = -ret[i / (*this)[i]]; } return ret; } }; // -------- Main Code -------- // const ll maxN = 100005; SieveOfEratosthenes sieve(maxN); int n; vector<int> arr; void runcase() { cin >> n; arr.resize(n); for (auto &u : arr) cin >> u; // cnt vector<int> cnt(maxN, 0); for (auto u : arr) { for (auto p : sieve.Factorize(u)) { cnt[p.first]++; } } // calc int res = 1; for (auto u : cnt) if (u >= 2) res = 2; if (res == 2) for (auto u : cnt) if (u == n) res = 3; // verdict if (res == 1) cout << "pairwise coprime\n"; else if (res == 2) cout << "setwise coprime\n"; else cout << "not coprime\n"; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // int t; // cin >> t; // while (t-- > 0) runcase(); return 0; }
#include <bits/stdc++.h> #define all(X) (X).begin(), (X).end() #define ll long long #define linf (1ll << 60) using namespace std; // -------- FUNCS -------- // vector<string> SPLIT(string str, char ch) { vector<string> res; stringstream ss(str); string s; while (getline(ss, s, ch)) res.push_back(s); return res; } ll STOI(string str, int base) { ll res = 0; for (auto c : str) { res *= base; res += c - '0'; } return res; } string ITOS(ll val, int base) { string res; while (val > 0) { res += '0' + (val % base); val /= base; } reverse(all(res)); return res; } // Sieve of Eratosthenes // (*this)[i] = (divisor of i, greater than 1) // Example: [0, 1, 2, 3, 2, 5, 3, 7, 2, 3, 2, 11, ...] // Complexity: Space O(MAXN), Time (construction) O(MAXNloglogMAXN) struct SieveOfEratosthenes : std::vector<int> { std::vector<int> primes; SieveOfEratosthenes(int MAXN) : std::vector<int>(MAXN + 1) { std::iota(begin(), end(), 0); for (int i = 2; i <= MAXN; i++) { if ((*this)[i] == i) { primes.push_back(i); for (int j = i; j <= MAXN; j += i) (*this)[j] = i; } } } using T = long long int; // Prime factorization for x <= MAXN^2 // Complexity: O(log x) (x <= MAXN) // O(MAXN / logMAXN) (MAXN < x <= MAXN^2) std::map<T, int> Factorize(T x) { assert(x <= 1LL * (int(size()) - 1) * (int(size()) - 1)); std::map<T, int> ret; if (x < int(size())) { while (x > 1) { ret[(*this)[x]]++; x /= (*this)[x]; } } else { for (auto p : primes) { while (!(x % p)) x /= p, ret[p]++; if (x == 1) break; } if (x > 1) ret[x]++; } return ret; } std::vector<T> Divisors(T x) { std::vector<T> ret{1}; for (auto p : Factorize(x)) { int n = ret.size(); for (int i = 0; i < n; i++) { for (T a = 1, d = 1; d <= p.second; d++) { a *= p.first; ret.push_back(ret[i] * a); } } } return ret; // Not sorted } // Moebius function Table // return: [0=>0, 1=>1, 2=>-1, 3=>-1, 4=>0, 5=>-1, 6=>1, 7=>-1, 8=>0, ...] std::vector<int> GenerateMoebiusFunctionTable() { std::vector<int> ret(size()); for (int i = 1; i < int(size()); i++) { if (i == 1) ret[i] = 1; else if ((i / (*this)[i]) % (*this)[i] == 0) ret[i] = 0; else ret[i] = -ret[i / (*this)[i]]; } return ret; } }; // -------- Main Code -------- // const ll maxN = 1000005; SieveOfEratosthenes sieve(maxN); int n; vector<int> arr; void runcase() { cin >> n; arr.resize(n); for (auto &u : arr) cin >> u; // cnt vector<int> cnt(maxN, 0); for (auto u : arr) { for (auto p : sieve.Factorize(u)) { cnt[p.first]++; } } // calc int res = 1; for (auto u : cnt) if (u >= 2) res = 2; if (res == 2) for (auto u : cnt) if (u == n) res = 3; // verdict if (res == 1) cout << "pairwise coprime\n"; else if (res == 2) cout << "setwise coprime\n"; else cout << "not coprime\n"; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // int t; // cin >> t; // while (t-- > 0) runcase(); return 0; }
replace
105
106
105
106
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; /* typedef */ typedef long long ll; typedef pair<int, int> pii; /* constant */ const int INF = 1 << 30; const int MAX = 1000005; const int mod = 1000000007; /* global variables */ // vector<int> cnt(MAX, 0); vector<int> cnt(20, 0); vector<int> p(MAX); vector<int> a; int N; /* function */ int gcd(int a, int b) { return (a % b) ? gcd(b, a % b) : b; } void sieve() { // O(Nlog(logN)) // p[i] = iの持つ最小の素因数を格納 // ex) p[5] = 5, p[10] = 2 for (int i = 0; i < MAX; i++) p[i] = i; for (int i = 2; i * i < MAX; i++) { if (p[i] == i) { for (int j = i + i; j < MAX; j += i) { if (p[j] == j) p[j] = i; } } } } map<int, int> factrization(int x) { // 前処理sieveを行っておく -> O(logx) map<int, int> ret; while (x != 1) { ret[p[x]]++; x /= p[x]; } return ret; } bool isPc1() { for (int i = 0; i < N; i++) { cnt[a[i]]++; } vector<bool> isPrime(MAX, true); isPrime[0] = isPrime[1] = false; for (int i = 2; i < MAX; i++) { int num = cnt[i]; if (isPrime[i]) { for (int j = i + i; j < MAX; j += i) { isPrime[j] = false; num += cnt[j]; } } if (num >= 2) return false; } return true; } bool isPc2() { // fast prime factrization sieve(); for (int i = 0; i < N; i++) { for (auto q : factrization(a[i])) { cnt[q.first]++; } } for (int i = 2; i < MAX; i++) if (cnt[i] > 1) return false; return true; } bool isSc() { int ret = 0; for (int i = 0; i < N; i++) { ret = gcd(ret, a[i]); } if (ret == 1) return true; else return false; } /* main */ int main() { cin >> N; a.resize(N); for (int i = 0; i < N; i++) cin >> a[i]; // if (isPc1()) { cout << "pairwise coprime" << '\n'; } if (isPc2()) { cout << "pairwise coprime" << '\n'; } else if (isSc()) { cout << "setwise coprime" << '\n'; } else { cout << "not coprime" << '\n'; } }
#include <bits/stdc++.h> using namespace std; /* typedef */ typedef long long ll; typedef pair<int, int> pii; /* constant */ const int INF = 1 << 30; const int MAX = 1000005; const int mod = 1000000007; /* global variables */ // vector<int> cnt(MAX, 0); vector<int> cnt(MAX, 0); vector<int> p(MAX); vector<int> a; int N; /* function */ int gcd(int a, int b) { return (a % b) ? gcd(b, a % b) : b; } void sieve() { // O(Nlog(logN)) // p[i] = iの持つ最小の素因数を格納 // ex) p[5] = 5, p[10] = 2 for (int i = 0; i < MAX; i++) p[i] = i; for (int i = 2; i * i < MAX; i++) { if (p[i] == i) { for (int j = i + i; j < MAX; j += i) { if (p[j] == j) p[j] = i; } } } } map<int, int> factrization(int x) { // 前処理sieveを行っておく -> O(logx) map<int, int> ret; while (x != 1) { ret[p[x]]++; x /= p[x]; } return ret; } bool isPc1() { for (int i = 0; i < N; i++) { cnt[a[i]]++; } vector<bool> isPrime(MAX, true); isPrime[0] = isPrime[1] = false; for (int i = 2; i < MAX; i++) { int num = cnt[i]; if (isPrime[i]) { for (int j = i + i; j < MAX; j += i) { isPrime[j] = false; num += cnt[j]; } } if (num >= 2) return false; } return true; } bool isPc2() { // fast prime factrization sieve(); for (int i = 0; i < N; i++) { for (auto q : factrization(a[i])) { cnt[q.first]++; } } for (int i = 2; i < MAX; i++) if (cnt[i] > 1) return false; return true; } bool isSc() { int ret = 0; for (int i = 0; i < N; i++) { ret = gcd(ret, a[i]); } if (ret == 1) return true; else return false; } /* main */ int main() { cin >> N; a.resize(N); for (int i = 0; i < N; i++) cin >> a[i]; // if (isPc1()) { cout << "pairwise coprime" << '\n'; } if (isPc2()) { cout << "pairwise coprime" << '\n'; } else if (isSc()) { cout << "setwise coprime" << '\n'; } else { cout << "not coprime" << '\n'; } }
replace
11
12
11
12
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; /* typedef */ typedef long long ll; typedef pair<int, int> pii; /* constant */ const int INF = 1 << 30; // const int MAX = 1000005; const int MAX = 60; const int mod = 1000000007; /* global variables */ vector<int> cnt(MAX, 0); vector<int> a; int N; /* function */ int gcd(int a, int b) { return (a % b) ? gcd(b, a % b) : b; } bool isPc1() { for (int i = 0; i < N; i++) { cnt[a[i]]++; } vector<bool> isPrime(MAX, true); isPrime[0] = isPrime[1] = false; for (int i = 2; i < MAX; i++) { int num = cnt[i]; if (isPrime[i]) { for (int j = i + i; j < MAX; j += i) { isPrime[j] = false; num += cnt[j]; } } if (num >= 2) return false; } return true; } bool isSc() { int ret = 0; for (int i = 0; i < N; i++) { ret = gcd(ret, a[i]); } if (ret == 1) return true; else return false; } /* main */ int main() { cin >> N; a.resize(N); for (int i = 0; i < N; i++) cin >> a[i]; if (isPc1()) { cout << "pairwise coprime" << '\n'; } else if (isSc()) { cout << "setwise coprime" << '\n'; } else { cout << "not coprime" << '\n'; } }
#include <bits/stdc++.h> using namespace std; /* typedef */ typedef long long ll; typedef pair<int, int> pii; /* constant */ const int INF = 1 << 30; const int MAX = 1000005; const int mod = 1000000007; /* global variables */ vector<int> cnt(MAX, 0); vector<int> a; int N; /* function */ int gcd(int a, int b) { return (a % b) ? gcd(b, a % b) : b; } bool isPc1() { for (int i = 0; i < N; i++) { cnt[a[i]]++; } vector<bool> isPrime(MAX, true); isPrime[0] = isPrime[1] = false; for (int i = 2; i < MAX; i++) { int num = cnt[i]; if (isPrime[i]) { for (int j = i + i; j < MAX; j += i) { isPrime[j] = false; num += cnt[j]; } } if (num >= 2) return false; } return true; } bool isSc() { int ret = 0; for (int i = 0; i < N; i++) { ret = gcd(ret, a[i]); } if (ret == 1) return true; else return false; } /* main */ int main() { cin >> N; a.resize(N); for (int i = 0; i < N; i++) cin >> a[i]; if (isPc1()) { cout << "pairwise coprime" << '\n'; } else if (isSc()) { cout << "setwise coprime" << '\n'; } else { cout << "not coprime" << '\n'; } }
replace
7
9
7
8
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep_lr(i, l, r) for (int i = (l); i < (r); i++) #define all(x) (x).begin(), (x).end() #define V vector typedef V<int> vi; typedef V<vi> vvi; typedef long long ll; typedef pair<ll, ll> P; typedef tuple<int, int, int> T; constexpr int INF = INT_MAX >> 1; constexpr ll LINF = 5000000000000000LL; constexpr int MOD = 1000000007; ll gcd(ll i, ll j) { return i % j ? gcd(j, i % j) : j; } vi prime, mnpf; void preprime(int n) { prime.resize(0); mnpf.assign(n + 1, 1); rep(i, n + 1) { if (i < 2) continue; if (mnpf[i] != 1) continue; prime.push_back(i); mnpf[i] = i; int ii = i; while (ii <= n) { if (mnpf[ii] == 1) mnpf[ii] = i; ii += i; } } } int main() { int n; cin >> n; vi a(n); rep(i, n) cin >> a[i]; int g = a[0]; rep(i, n) g = gcd(g, a[i]); if (g > 1) { cout << "not coprime" << endl; return 0; } preprime(n + 1000); map<int, int> pri; rep(i, n) { int k = a[i]; while (k > 1) { pri[mnpf[k]]++; int memo = mnpf[k]; while (mnpf[k] == memo) k /= mnpf[k]; } } bool pairwise = true; for (auto x : pri) { if (x.second > 1) pairwise = false; } if (pairwise) cout << "pairwise coprime" << endl; else cout << "setwise coprime" << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep_lr(i, l, r) for (int i = (l); i < (r); i++) #define all(x) (x).begin(), (x).end() #define V vector typedef V<int> vi; typedef V<vi> vvi; typedef long long ll; typedef pair<ll, ll> P; typedef tuple<int, int, int> T; constexpr int INF = INT_MAX >> 1; constexpr ll LINF = 5000000000000000LL; constexpr int MOD = 1000000007; ll gcd(ll i, ll j) { return i % j ? gcd(j, i % j) : j; } vi prime, mnpf; void preprime(int n) { prime.resize(0); mnpf.assign(n + 1, 1); rep(i, n + 1) { if (i < 2) continue; if (mnpf[i] != 1) continue; prime.push_back(i); mnpf[i] = i; int ii = i; while (ii <= n) { if (mnpf[ii] == 1) mnpf[ii] = i; ii += i; } } } int main() { int n; cin >> n; vi a(n); rep(i, n) cin >> a[i]; int g = a[0]; rep(i, n) g = gcd(g, a[i]); if (g > 1) { cout << "not coprime" << endl; return 0; } preprime(1010100); map<int, int> pri; rep(i, n) { int k = a[i]; while (k > 1) { pri[mnpf[k]]++; int memo = mnpf[k]; while (mnpf[k] == memo) k /= mnpf[k]; } } bool pairwise = true; for (auto x : pri) { if (x.second > 1) pairwise = false; } if (pairwise) cout << "pairwise coprime" << endl; else cout << "setwise coprime" << endl; }
replace
53
54
53
54
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rp(i, k, n) for (int i = k; i < n; i++) typedef long long ll; typedef double ld; template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } const ll INF = 1ll << 60; const ll MOD = 1e9 + 7ll; const double PI = 3.14159265358979323846; ll gcd(ll n, ll m) { // 最大公約数を求めるプログラム // nとmの最大公約数を返す関数 if (m > n) { ll c = n; n = m; m = c; } if (n % m == 0ll) return m; else return gcd(m, n % m); } vector<ll> fpf_prepare(ll a) { // fpfの前処理 O(alog(loga)) vector<ll> res; rp(i, 2, a + 1) { if (res[i] == 0) { for (int k = 1; i * k <= a; k++) { res[i * k] = i; } } } return res; } int main() { int n; cin >> n; vector<ll> A(n); auto D = fpf_prepare(1000010); vector<bool> p(1000010, false); bool flag = false; rp(i, 0, n) { ll a; scanf("%lld", &a); A.at(i) = a; ll m = 1000000ll; while (a > 1ll) { // cout << "a = " << a << " D[a] = " << D[a] << endl; if (D[a] < m && p[D[a]]) flag = true; p[D[a]] = true; m = D[a]; a /= D[a]; } } if (!flag) { cout << "pairwise coprime" << endl; return 0; } ll g = A[0]; rp(i, 1, n) { g = gcd(g, A[i]); if (g == 1) { cout << "setwise coprime" << endl; return 0; } } cout << "not coprime" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rp(i, k, n) for (int i = k; i < n; i++) typedef long long ll; typedef double ld; template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } const ll INF = 1ll << 60; const ll MOD = 1e9 + 7ll; const double PI = 3.14159265358979323846; ll gcd(ll n, ll m) { // 最大公約数を求めるプログラム // nとmの最大公約数を返す関数 if (m > n) { ll c = n; n = m; m = c; } if (n % m == 0ll) return m; else return gcd(m, n % m); } vector<ll> fpf_prepare(ll a) { // fpfの前処理 O(alog(loga)) vector<ll> res(a + 1); rp(i, 2, a + 1) { if (res[i] == 0) { for (int k = 1; i * k <= a; k++) { res[i * k] = i; } } } return res; } int main() { int n; cin >> n; vector<ll> A(n); auto D = fpf_prepare(1000010); vector<bool> p(1000010, false); bool flag = false; rp(i, 0, n) { ll a; scanf("%lld", &a); A.at(i) = a; ll m = 1000000ll; while (a > 1ll) { // cout << "a = " << a << " D[a] = " << D[a] << endl; if (D[a] < m && p[D[a]]) flag = true; p[D[a]] = true; m = D[a]; a /= D[a]; } } if (!flag) { cout << "pairwise coprime" << endl; return 0; } ll g = A[0]; rp(i, 1, n) { g = gcd(g, A[i]); if (g == 1) { cout << "setwise coprime" << endl; return 0; } } cout << "not coprime" << endl; return 0; }
replace
39
40
39
40
-11
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long const int nax = 2e5 + 7; int lpf[nax], mobius[nax]; void least_prime_factor() { for (int i = 2; i < nax; i++) { if (!lpf[i]) { for (int j = i; j < nax; j += i) { if (!lpf[j]) { lpf[j] = i; } } } } return; } void mob() { for (int i = 1; i < nax; i++) { if (i == 1) { mobius[i] = 1; } else { if (lpf[i / lpf[i]] == lpf[i]) { mobius[i] = 0; } else { mobius[i] = -1 * mobius[i / lpf[i]]; } } } return; } int gp(int a[], int n) { int maxi = 0; int fre[nax] = {0}; for (int i = 0; i < n; i++) { fre[a[i]]++; maxi = max(a[i], maxi); } least_prime_factor(); mob(); int ans = 0; for (int i = 1; i <= maxi; i++) { if (!mobius[i]) { continue; } int temp = 0; for (int j = i; j <= maxi; j += i) { temp += fre[j]; } ans += temp * (temp - 1) / 2 * mobius[i]; } return ans; } signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int gcd = 0; for (int i = 0; i < n; i++) { gcd = __gcd(gcd, a[i]); } int pairs = gp(a, n); if (pairs == (n * (n - 1)) / 2) { cout << "pairwise coprime\n"; return 0; } if (gcd == 1) { cout << "setwise coprime\n"; return 0; } cout << "not coprime\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long const int nax = 1e6 + 7; int lpf[nax], mobius[nax]; void least_prime_factor() { for (int i = 2; i < nax; i++) { if (!lpf[i]) { for (int j = i; j < nax; j += i) { if (!lpf[j]) { lpf[j] = i; } } } } return; } void mob() { for (int i = 1; i < nax; i++) { if (i == 1) { mobius[i] = 1; } else { if (lpf[i / lpf[i]] == lpf[i]) { mobius[i] = 0; } else { mobius[i] = -1 * mobius[i / lpf[i]]; } } } return; } int gp(int a[], int n) { int maxi = 0; int fre[nax] = {0}; for (int i = 0; i < n; i++) { fre[a[i]]++; maxi = max(a[i], maxi); } least_prime_factor(); mob(); int ans = 0; for (int i = 1; i <= maxi; i++) { if (!mobius[i]) { continue; } int temp = 0; for (int j = i; j <= maxi; j += i) { temp += fre[j]; } ans += temp * (temp - 1) / 2 * mobius[i]; } return ans; } signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int gcd = 0; for (int i = 0; i < n; i++) { gcd = __gcd(gcd, a[i]); } int pairs = gp(a, n); if (pairs == (n * (n - 1)) / 2) { cout << "pairwise coprime\n"; return 0; } if (gcd == 1) { cout << "setwise coprime\n"; return 0; } cout << "not coprime\n"; return 0; }
replace
4
5
4
5
0
p02574
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> using namespace std; #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define endl "\n" #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define F first #define S second #define bitcnt(v) __builtin_popcount(v) #define all(v) v.begin(), v.end() void solution() { int n; cin >> n; vector<int> A(n); for (int &x : A) cin >> x; int g = A[0]; map<int, int> c; for (int x : A) { g = __gcd((unsigned)g, (unsigned)x); c[x]++; } if (g > 1) { cout << "not coprime" << endl; return; } int m = *max_element(all(A)); for (int i = 2; i <= m; i++) { int cur = 0; for (int j = i; j <= m; j += i) { cur += c[j]; } if (cur > 1) { cout << "setwise coprime" << endl; return; } } cout << "pairwise coprime" << endl; return; } int main() { fio; int t; t = 1; // cin >> t; for (int i = 1; i <= t; i++) { // cout << "Case #" << i << ": "; solution(); } return 0; }
#include <algorithm> #include <bits/stdc++.h> using namespace std; #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define endl "\n" #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define F first #define S second #define bitcnt(v) __builtin_popcount(v) #define all(v) v.begin(), v.end() void solution() { int n; cin >> n; vector<int> A(n); for (int &x : A) cin >> x; int g = A[0]; unordered_map<int, int> c; for (int x : A) { g = __gcd((unsigned)g, (unsigned)x); c[x]++; } if (g > 1) { cout << "not coprime" << endl; return; } int m = *max_element(all(A)); for (int i = 2; i <= m; i++) { int cur = 0; for (int j = i; j <= m; j += i) { cur += c[j]; } if (cur > 1) { cout << "setwise coprime" << endl; return; } } cout << "pairwise coprime" << endl; return; } int main() { fio; int t; t = 1; // cin >> t; for (int i = 1; i <= t; i++) { // cout << "Case #" << i << ": "; solution(); } return 0; }
replace
23
24
23
24
TLE
p02574
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <cmath> #include <string> using namespace std; #define ll long long int #define ld long double #define loop(i, n) for (int i = 0; i < n; i++) #define loops(i, s, n) for (int i = s; i < n; i++) #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() #define sz(x) ((int)(x).size()) #define fi first #define se second #define deb(x) cout << #x << '=' << x << endl #define MOD 1000000007 const int N = 1e6 + 5; ll cnt[N]; ll gcd(ll a, ll b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; ll a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } ll gc = a[0]; for (int i = 1; i < n; i++) { gc = gcd(gc, a[i]); } if (gc > 1) { cout << "not coprime"; return 0; } for (int i = 0; i < n; i++) { ll t = a[i]; for (int j = 2; j * j <= a[i]; j++) { if (t % j == 0) { while (t % j == 0) { t /= j; } cnt[j]++; } } if (t > 1) { cnt[t]++; } } bool flag = 1; for (auto it : cnt) { if (it > 1) { flag = 0; break; } } if (flag) { cout << "pairwise coprime"; } else { cout << "setwise coprime"; } }
#include <bits/stdc++.h> #include <cmath> #include <string> using namespace std; #define ll long long int #define ld long double #define loop(i, n) for (int i = 0; i < n; i++) #define loops(i, s, n) for (int i = s; i < n; i++) #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() #define sz(x) ((int)(x).size()) #define fi first #define se second #define deb(x) cout << #x << '=' << x << endl #define MOD 1000000007 const int N = 1e6 + 5; ll cnt[N]; ll gcd(ll a, ll b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; ll a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } ll gc = a[0]; for (int i = 1; i < n; i++) { gc = gcd(gc, a[i]); } if (gc > 1) { cout << "not coprime"; return 0; } for (int i = 0; i < n; i++) { ll t = a[i]; for (int j = 2; j * j <= t; j++) { if (t % j == 0) { while (t % j == 0) { t /= j; } cnt[j]++; } } if (t > 1) { cnt[t]++; } } bool flag = 1; for (auto it : cnt) { if (it > 1) { flag = 0; break; } } if (flag) { cout << "pairwise coprime"; } else { cout << "setwise coprime"; } }
replace
47
48
47
48
TLE
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define pld pair<long double, int> #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define ff first #define ss second #define SZ(x) ((int)(x).size()) #define ld long double mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MAXN = 1e6 + 100; int N, a[MAXN], smallest[MAXN]; bool prime[MAXN]; string ans1 = "pairwise coprime"; string ans2 = "setwise coprime"; string ans3 = "not coprime"; void read() { cin >> N; for (int i = 0; i < N; i++) cin >> a[i]; } void sieve() { memset(prime, true, sizeof(prime)); prime[0] = prime[1] = false; smallest[0] = 0, smallest[1] = 1; for (int i = 2; i * i < MAXN; i++) { if (prime[i]) { smallest[i] = i; for (int j = 2 * i; j < MAXN; j += i) prime[j] = false, smallest[j] = i; } } } void solve() { read(); sieve(); vector<int> cnt(MAXN, 0); int d = a[0]; for (int i = 0; i < N; i++) { d = __gcd(d, a[i]); int n = a[i]; while (n != 1) { cnt[smallest[n]]++; n /= smallest[n]; } } bool a2 = (d == 1); for (int i = 0; i < N; i++) { int n = a[i]; while (n != 1) { int cnt2 = 0, div = smallest[n]; while (n != 1 && (n % div == 0)) { n /= div; cnt2++; } if (cnt[div] > cnt2) { if (a2 == true) cout << ans2; else cout << ans3; return; } } } cout << ans1; return; } int main() { ios_base::sync_with_stdio(false); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pld pair<long double, int> #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define ff first #define ss second #define SZ(x) ((int)(x).size()) #define ld long double mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MAXN = 1e6 + 100; int N, a[MAXN], smallest[MAXN]; bool prime[MAXN]; string ans1 = "pairwise coprime"; string ans2 = "setwise coprime"; string ans3 = "not coprime"; void read() { cin >> N; for (int i = 0; i < N; i++) cin >> a[i]; } void sieve() { memset(prime, true, sizeof(prime)); prime[0] = prime[1] = false; iota(smallest, smallest + MAXN, 0); for (int i = 2; i * i < MAXN; i++) { if (prime[i]) { smallest[i] = i; for (int j = 2 * i; j < MAXN; j += i) prime[j] = false, smallest[j] = i; } } } void solve() { read(); sieve(); vector<int> cnt(MAXN, 0); int d = a[0]; for (int i = 0; i < N; i++) { d = __gcd(d, a[i]); int n = a[i]; while (n != 1) { cnt[smallest[n]]++; n /= smallest[n]; } } bool a2 = (d == 1); for (int i = 0; i < N; i++) { int n = a[i]; while (n != 1) { int cnt2 = 0, div = smallest[n]; while (n != 1 && (n % div == 0)) { n /= div; cnt2++; } if (cnt[div] > cnt2) { if (a2 == true) cout << ans2; else cout << ans3; return; } } } cout << ans1; return; } int main() { ios_base::sync_with_stdio(false); solve(); return 0; }
replace
29
30
29
30
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define d(x) cerr << #x ":" << x << endl; #define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl #define rep(i, n) for (int i = (int)(0); i < (int)(n); i++) #define all(v) v.begin(), v.end() #define dump(v) \ cerr << #v ":[ "; \ for (auto macro_vi : v) { \ cerr << macro_vi << " "; \ } \ cerr << "]" << endl; #define ddump(v) \ cerr << #v ":" << endl; \ for (auto macro_row : v) { \ cerr << "["; \ for (auto macro__vi : macro_row) { \ cerr << macro__vi << " "; \ } \ cerr << "]" << endl; \ } using lint = long long; const int INF = 1e9; const lint LINF = 1e18; const double EPS = 1e-10; int main() { lint N; cin >> N; vector<lint> A(N); rep(i, N) cin >> A[i]; const lint M = 20; vector<vector<lint>> primes(M + 1, vector<lint>(0)); for (int p = 2; p <= M; p++) { if (primes[p].size() != 0) continue; for (int pk = p; pk <= M; pk += p) { primes[pk].push_back(p); } } lint G = 0; rep(i, N) G = __gcd(G, A[i]); if (G != 1) { cout << "not coprime" << endl; return 0; } set<lint> used; for (int i = 0; i < N; i++) { for (auto p : primes[A[i]]) { if (used.count(p) == 1) { cout << "setwise coprime" << endl; return 0; } else { used.insert(p); } } } cout << "pairwise coprime" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define d(x) cerr << #x ":" << x << endl; #define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl #define rep(i, n) for (int i = (int)(0); i < (int)(n); i++) #define all(v) v.begin(), v.end() #define dump(v) \ cerr << #v ":[ "; \ for (auto macro_vi : v) { \ cerr << macro_vi << " "; \ } \ cerr << "]" << endl; #define ddump(v) \ cerr << #v ":" << endl; \ for (auto macro_row : v) { \ cerr << "["; \ for (auto macro__vi : macro_row) { \ cerr << macro__vi << " "; \ } \ cerr << "]" << endl; \ } using lint = long long; const int INF = 1e9; const lint LINF = 1e18; const double EPS = 1e-10; int main() { lint N; cin >> N; vector<lint> A(N); rep(i, N) cin >> A[i]; const lint M = 1001000; vector<vector<lint>> primes(M + 1, vector<lint>(0)); for (int p = 2; p <= M; p++) { if (primes[p].size() != 0) continue; for (int pk = p; pk <= M; pk += p) { primes[pk].push_back(p); } } lint G = 0; rep(i, N) G = __gcd(G, A[i]); if (G != 1) { cout << "not coprime" << endl; return 0; } set<lint> used; for (int i = 0; i < N; i++) { for (auto p : primes[A[i]]) { if (used.count(p) == 1) { cout << "setwise coprime" << endl; return 0; } else { used.insert(p); } } } cout << "pairwise coprime" << endl; return 0; }
replace
33
34
33
34
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<string> vs; typedef vector<bool> vb; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() int N = 100010; vector<int> prime; // i番目の素数 bool is_prime[100011]; // is_prime[i] がTrueならiは素数 int sieve(int n) { int p = 0; for (int i = 0; i <= n; i++) is_prime[i] = true; is_prime[0] = is_prime[1] = false; for (int i = 2; i <= n; i++) { if (is_prime[i]) { prime.emplace_back(i); for (int j = 2 * i; j <= n; j += i) is_prime[j] = false; } } return p; // pは素数の数 } int main() { sieve(N); int n; cin >> n; vector<int> a(n); vector<int> c(N); rep(i, n) { cin >> a[i]; c[a[i]]++; } bool flag = true; for (int i : prime) { int cnt = 0; for (int j = i; j <= N; j += i) { cnt += c[j]; } if (cnt > 1) { flag = false; break; } } int gcd = a[0]; rep(i, n - 1) { gcd = __gcd(a[i + 1], gcd); } if (flag) cout << "pairwise coprime" << endl; else if (gcd == 1) cout << "setwise coprime" << endl; else cout << "not coprime" << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<string> vs; typedef vector<bool> vb; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() int N = 1000100; vector<int> prime; // i番目の素数 bool is_prime[1000100]; // is_prime[i] がTrueならiは素数 int sieve(int n) { int p = 0; for (int i = 0; i <= n; i++) is_prime[i] = true; is_prime[0] = is_prime[1] = false; for (int i = 2; i <= n; i++) { if (is_prime[i]) { prime.emplace_back(i); for (int j = 2 * i; j <= n; j += i) is_prime[j] = false; } } return p; // pは素数の数 } int main() { sieve(N); int n; cin >> n; vector<int> a(n); vector<int> c(N); rep(i, n) { cin >> a[i]; c[a[i]]++; } bool flag = true; for (int i : prime) { int cnt = 0; for (int j = i; j <= N; j += i) { cnt += c[j]; } if (cnt > 1) { flag = false; break; } } int gcd = a[0]; rep(i, n - 1) { gcd = __gcd(a[i + 1], gcd); } if (flag) cout << "pairwise coprime" << endl; else if (gcd == 1) cout << "setwise coprime" << endl; else cout << "not coprime" << endl; }
replace
16
19
16
19
0
p02574
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define INF 1e9 + 7 typedef long long int ll; const int maxn = 1000000; ll mod = INF; int d[maxn + 1]; int n; int a[maxn]; int cnt[maxn + 1]; int used[maxn + 1]; int ans = 0; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i <= maxn; i++) d[i] = INF; d[0] = d[1] = 1; sort(a, a + n); for (int div = 2; div <= a[n - 1]; div++) { for (int bediv = 2; bediv <= a[n - 1]; bediv++) { if (d[bediv] == INF) { if (bediv % div == 0) { d[bediv] = div; } } } } for (int i = 0; i < n; i++) { int bediv = a[i]; set<int> s; while (bediv > 1) { s.insert(d[bediv]); bediv = bediv / d[bediv]; } for (auto ite = s.begin(); ite != s.end(); ite++) { used[*ite]++; if (used[*ite] > 1) { ans = 1; break; } } if (ans == 1) break; } set<int> t; int temp = a[0]; while (temp > 1) { t.insert(d[temp]); temp = temp / d[temp]; } for (auto ite = t.begin(); ite != t.end(); ite++) { for (int i = 0; i < n; i++) { if (a[i] % *ite != 0) break; if (i == n - 1) ans = 2; } if (ans == 2) break; } if (ans == 0) { cout << "pairwise coprime" << endl; } else if (ans == 1) { cout << "setwise coprime" << endl; } else { cout << "not coprime" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 1e9 + 7 typedef long long int ll; const int maxn = 1000000; ll mod = INF; int d[maxn + 1]; int n; int a[maxn]; int cnt[maxn + 1]; int used[maxn + 1]; int ans = 0; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i <= maxn; i++) d[i] = INF; d[0] = d[1] = 1; sort(a, a + n); for (int div = 2; div <= a[n - 1]; div++) { if (d[div] != INF) continue; for (int bediv = div; bediv <= a[n - 1]; bediv += div) { d[bediv] = div; } } for (int i = 0; i < n; i++) { int bediv = a[i]; set<int> s; while (bediv > 1) { s.insert(d[bediv]); bediv = bediv / d[bediv]; } for (auto ite = s.begin(); ite != s.end(); ite++) { used[*ite]++; if (used[*ite] > 1) { ans = 1; break; } } if (ans == 1) break; } set<int> t; int temp = a[0]; while (temp > 1) { t.insert(d[temp]); temp = temp / d[temp]; } for (auto ite = t.begin(); ite != t.end(); ite++) { for (int i = 0; i < n; i++) { if (a[i] % *ite != 0) break; if (i == n - 1) ans = 2; } if (ans == 2) break; } if (ans == 0) { cout << "pairwise coprime" << endl; } else if (ans == 1) { cout << "setwise coprime" << endl; } else { cout << "not coprime" << endl; } return 0; }
replace
23
29
23
27
TLE
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); } const int MAX = 1e6; vector<int> prime(MAX + 1, -1); void settable() { for (int i = 2; i <= MAX; i++) { if (prime[i] == -1) { prime[i] = i; for (int j = i + i; j <= MAX; j += i) { prime[j] = i; } } } } int main() { settable(); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<bool> ok(MAX + 1, false); bool ok1 = true, ok2 = true; for (int i = 0; i < n; i++) { int nn = a[i]; set<int> s; do { int d = prime[nn]; s.insert(d); nn /= d; } while (nn > 1); for (auto dd : s) { if (ok[dd]) ok1 = false; ok[dd] = true; } } int G = 0; for (int i = 0; i < n; i++) { G = gcd(a[i], G); } ok2 = (G == 1); if (ok1) { cout << "pairwise coprime" << endl; } else if (ok2) { cout << "setwise coprime" << endl; } else { cout << "not coprime" << endl; } }
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); } const int MAX = 1e6; vector<int> prime(MAX + 1, -1); void settable() { for (int i = 2; i <= MAX; i++) { if (prime[i] == -1) { prime[i] = i; for (int j = i + i; j <= MAX; j += i) { prime[j] = i; } } } } int main() { settable(); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<bool> ok(MAX + 1, false); bool ok1 = true, ok2 = true; for (int i = 0; i < n; i++) { int nn = a[i]; if (nn == 1) continue; set<int> s; do { int d = prime[nn]; s.insert(d); nn /= d; } while (nn > 1); for (auto dd : s) { if (ok[dd]) ok1 = false; ok[dd] = true; } } int G = 0; for (int i = 0; i < n; i++) { G = gcd(a[i], G); } ok2 = (G == 1); if (ok1) { cout << "pairwise coprime" << endl; } else if (ok2) { cout << "setwise coprime" << endl; } else { cout << "not coprime" << endl; } }
insert
31
31
31
33
0
p02574
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef vector<bool> VB; typedef vector<VB> VVB; typedef vector<double> VD; typedef vector<VD> VVD; typedef vector<string> VS; typedef vector<VS> VVS; typedef vector<char> VC; typedef vector<VC> VVC; typedef vector<PII> VPII; typedef vector<PLL> VPLL; typedef priority_queue<int> PQGI; // 大きい順 typedef priority_queue<int, VI, greater<int>> PQLI; typedef priority_queue<PII> PQGP; typedef priority_queue<PII, VPII, greater<int>> PQLP; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EB emplace_back #define EF emplace_front #define PB push_back #define PF push_front #define POB pop_back #define POF pop_front #define MP make_pair #define SZ(a) int((a).size()) #define SQ(a) ((a) * (a)) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) #define SORTR(c) sort((c).rbegin(), (c).rend()) #define LB lower_bound #define UB upper_bound #define NEXP next_permutation #define FI first #define SE second #define Vmin(a) *min_element((a).begin(), (a).end()) #define Vmax(a) *max_element((a).begin(), (a).end()) // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define FORR(i, a, b) for (int i = (b - 1); i >= (a); i--) #define REPR(i, n) FORR(i, 0, n) #define CFOR(i, a, b) for (int i = (a); i <= (b); ++i) #define CREP(i, n) CFOR(i, 0, n) #define CFORR(i, a, b) for (int i = (b); i >= (a); i--) #define CREPR(i, n) CFORR(i, 0, n) #define BFOR(bit, a, b) for (int bit = (a); bit < (1 << (b)); ++bit) #define BREP(bit, n) BFOR(bit, 0, n) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = INT_MAX / 2; const LL LINF = LLONG_MAX / 3; const int RINF = INT_MIN / 2; const LL RLINF = LLONG_MIN / 3; const LL MOD = 1e9 + 7; const LL MODD = 998244353; const int MAX = 510000; inline bool Eq(double a, double b) { return fabs(b - a) < EPS; } // other //------------------------------------------- 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; } #define COUT(x) cout << (x) << endl #define COUT2(x, y) cout << (x) << " " << (y) << endl #define COUT3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl #define PR(x) cout << (x) #define ENDL cout << endl #define SPACE cout << " " #define BC(x) __builtin_popcountll(x) VI dx = {1, 0, -1, 0, 1, 1, -1, -1}; VI dy = {0, 1, 0, -1, 1, -1, 1, -1}; LL Gcd(LL a, LL b) { return __gcd(a, b); } LL Lcm(LL a, LL b) { return a / Gcd(a, b) * b; } LL ModPow(LL A, LL N, LL M) { LL res = 1; while (N > 0) { if (N & 1) res = res * A % M; A = A * A % M; N >>= 1; } return res; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << " " << p.second; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } VI Erat(int x) { VI a(x, 1); VI res; for (int i = 2; i < sqrt(x); i++) { if (a.at(i)) { for (int j = 0; i * (j + 2) < (x); j++) { a.at(i * (j + 2)) = 0; } } } for (int i = 2; i < (x); i++) { if (a.at(i)) { res.PB(i); } } return res; } map<int, int> Factoring(int A, VI &prime) { map<int, int> mp; int N = SZ(prime); int i = 0; while (i < N && (LL)prime.at(i) * prime.at(i) < A) { while (A % prime.at(i) == 0) { A %= prime.at(i); mp[prime.at(i)]++; } i++; } if (A > 1) mp[A]++; return mp; } int main() { // cin.tie(0); // ios::sync_with_stdio(false); cout << fixed << setprecision(12); int N; cin >> N; VI A(N); cin >> A; int sum = 0; REP(i, N) sum = Gcd(sum, A.at(i)); if (sum != 1) { COUT("not coprime"); return 0; } set<int> s; VI prime = Erat(2000000); REP(i, N) { map<int, int> mp = Factoring(A.at(i), prime); for (auto p : mp) { if (s.count(p.FI)) { COUT("setwise coprime"); return 0; } s.insert(p.FI); } } COUT("pairwise coprime"); return 0; }
#include <bits/stdc++.h> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef vector<bool> VB; typedef vector<VB> VVB; typedef vector<double> VD; typedef vector<VD> VVD; typedef vector<string> VS; typedef vector<VS> VVS; typedef vector<char> VC; typedef vector<VC> VVC; typedef vector<PII> VPII; typedef vector<PLL> VPLL; typedef priority_queue<int> PQGI; // 大きい順 typedef priority_queue<int, VI, greater<int>> PQLI; typedef priority_queue<PII> PQGP; typedef priority_queue<PII, VPII, greater<int>> PQLP; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EB emplace_back #define EF emplace_front #define PB push_back #define PF push_front #define POB pop_back #define POF pop_front #define MP make_pair #define SZ(a) int((a).size()) #define SQ(a) ((a) * (a)) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) #define SORTR(c) sort((c).rbegin(), (c).rend()) #define LB lower_bound #define UB upper_bound #define NEXP next_permutation #define FI first #define SE second #define Vmin(a) *min_element((a).begin(), (a).end()) #define Vmax(a) *max_element((a).begin(), (a).end()) // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define FORR(i, a, b) for (int i = (b - 1); i >= (a); i--) #define REPR(i, n) FORR(i, 0, n) #define CFOR(i, a, b) for (int i = (a); i <= (b); ++i) #define CREP(i, n) CFOR(i, 0, n) #define CFORR(i, a, b) for (int i = (b); i >= (a); i--) #define CREPR(i, n) CFORR(i, 0, n) #define BFOR(bit, a, b) for (int bit = (a); bit < (1 << (b)); ++bit) #define BREP(bit, n) BFOR(bit, 0, n) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = INT_MAX / 2; const LL LINF = LLONG_MAX / 3; const int RINF = INT_MIN / 2; const LL RLINF = LLONG_MIN / 3; const LL MOD = 1e9 + 7; const LL MODD = 998244353; const int MAX = 510000; inline bool Eq(double a, double b) { return fabs(b - a) < EPS; } // other //------------------------------------------- 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; } #define COUT(x) cout << (x) << endl #define COUT2(x, y) cout << (x) << " " << (y) << endl #define COUT3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl #define PR(x) cout << (x) #define ENDL cout << endl #define SPACE cout << " " #define BC(x) __builtin_popcountll(x) VI dx = {1, 0, -1, 0, 1, 1, -1, -1}; VI dy = {0, 1, 0, -1, 1, -1, 1, -1}; LL Gcd(LL a, LL b) { return __gcd(a, b); } LL Lcm(LL a, LL b) { return a / Gcd(a, b) * b; } LL ModPow(LL A, LL N, LL M) { LL res = 1; while (N > 0) { if (N & 1) res = res * A % M; A = A * A % M; N >>= 1; } return res; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << " " << p.second; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } VI Erat(int x) { VI a(x, 1); VI res; for (int i = 2; i < sqrt(x); i++) { if (a.at(i)) { for (int j = 0; i * (j + 2) < (x); j++) { a.at(i * (j + 2)) = 0; } } } for (int i = 2; i < (x); i++) { if (a.at(i)) { res.PB(i); } } return res; } map<int, int> Factoring(int A, VI &prime) { map<int, int> mp; int N = SZ(prime); int i = 0; while (i < N && (LL)prime.at(i) * prime.at(i) < A) { while (A % prime.at(i) == 0) { A /= prime.at(i); mp[prime.at(i)]++; } i++; } if (A > 1) mp[A]++; return mp; } int main() { // cin.tie(0); // ios::sync_with_stdio(false); cout << fixed << setprecision(12); int N; cin >> N; VI A(N); cin >> A; int sum = 0; REP(i, N) sum = Gcd(sum, A.at(i)); if (sum != 1) { COUT("not coprime"); return 0; } set<int> s; VI prime = Erat(2000000); REP(i, N) { map<int, int> mp = Factoring(A.at(i), prime); for (auto p : mp) { if (s.count(p.FI)) { COUT("setwise coprime"); return 0; } s.insert(p.FI); } } COUT("pairwise coprime"); return 0; }
replace
200
201
200
201
TLE
p02574
C++
Runtime Error
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author */ #include <fstream> #include <iostream> #include "bits/stdc++.h" #include <iostream> using namespace std; typedef unsigned long long ll; typedef int integer; #define int long long #define ii pair<int, int> #define vii vector<pair<int, int>> #define vi vector<int> #define vvi vector<vector<int>> #define f(a, b, c) for (int a = (b); a < (c); a++) #define s(x) in >> x #define s2(x, y) in >> x >> y #define s3(x, y, z) in >> x >> y >> z #define s4(x, y, z, w) in >> x >> y >> z >> w #define p(x) out << (x) << endl #define p2(x, y) out << (x) << " " << (y) << endl #define pl(x) out << (x) #define p2l(x, y) out << (x) << " " << (y) #define p1d(a, n) \ for (int ix = 0; ix < (n); ix++) \ out << a[ix] << " "; \ out << endl #define p2d(a, n, m) \ for (int ix = 0; ix < (n); ix++) { \ for (int jx = 0; jx < (m); jx++) \ out << a[ix][jx] << " "; \ out << endl; \ } #define range(v) v.begin(), v.end() #define w(x) while (x--) #define rst(x) memset(x, -1, sizeof(x)) #define MAXN 100001 int spf[MAXN]; // Calculating SPF (Smallest Prime Factor) for every // number till MAXN. // Time Complexity : O(nloglogn) void sieve() { spf[1] = 1; for (int i = 2; i < MAXN; i++) // marking smallest prime factor for every // number to be itself. spf[i] = i; // separately marking spf for every even // number as 2 for (int i = 4; i < MAXN; i += 2) spf[i] = 2; for (int i = 3; i * i < MAXN; i++) { // checking if i is prime if (spf[i] == i) { // marking SPF for all numbers divisible by i for (int j = i * i; j < MAXN; j += i) // marking spf[j] if it is not // previously marked if (spf[j] == j) spf[j] = i; } } } // A O(log n) function returning primefactorization // by dividing by smallest prime factor at every step set<int> getFactorization(int x) { set<int> ret; while (x != 1) { ret.insert(spf[x]); x = x / spf[x]; } return ret; } void ssolve(std::istream &in, std::ostream &out) { int n; s(n); vi a(n); f(i, 0, n) s(a[i]); int gc = __gcd(a[0], a[1]); f(i, 0, n) gc = __gcd(gc, a[i]); if (gc > 1) { out << "not coprime" << endl; return; } sieve(); map<int, int> dist; f(i, 0, n) { auto primes = getFactorization(a[i]); for (auto x : primes) { dist[x]++; } } bool pairwise = true; for (auto k : dist) { if (k.second > 1) { pairwise = false; } } out << (pairwise ? "pairwise coprime" : "setwise coprime") << endl; } class ECoprime { public: void solve(std::istream &in, std::ostream &out) { ios_base::sync_with_stdio(false); in.tie(0); out.tie(0); int t; int READ = 0; if (READ) s(t); else t = 1; while (t--) { ssolve(in, out); } } }; integer main() { ECoprime solver; std::istream &in(std::cin); std::ostream &out(std::cout); solver.solve(in, out); }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author */ #include <fstream> #include <iostream> #include "bits/stdc++.h" #include <iostream> using namespace std; typedef unsigned long long ll; typedef int integer; #define int long long #define ii pair<int, int> #define vii vector<pair<int, int>> #define vi vector<int> #define vvi vector<vector<int>> #define f(a, b, c) for (int a = (b); a < (c); a++) #define s(x) in >> x #define s2(x, y) in >> x >> y #define s3(x, y, z) in >> x >> y >> z #define s4(x, y, z, w) in >> x >> y >> z >> w #define p(x) out << (x) << endl #define p2(x, y) out << (x) << " " << (y) << endl #define pl(x) out << (x) #define p2l(x, y) out << (x) << " " << (y) #define p1d(a, n) \ for (int ix = 0; ix < (n); ix++) \ out << a[ix] << " "; \ out << endl #define p2d(a, n, m) \ for (int ix = 0; ix < (n); ix++) { \ for (int jx = 0; jx < (m); jx++) \ out << a[ix][jx] << " "; \ out << endl; \ } #define range(v) v.begin(), v.end() #define w(x) while (x--) #define rst(x) memset(x, -1, sizeof(x)) #define MAXN 2000001 int spf[MAXN]; // Calculating SPF (Smallest Prime Factor) for every // number till MAXN. // Time Complexity : O(nloglogn) void sieve() { spf[1] = 1; for (int i = 2; i < MAXN; i++) // marking smallest prime factor for every // number to be itself. spf[i] = i; // separately marking spf for every even // number as 2 for (int i = 4; i < MAXN; i += 2) spf[i] = 2; for (int i = 3; i * i < MAXN; i++) { // checking if i is prime if (spf[i] == i) { // marking SPF for all numbers divisible by i for (int j = i * i; j < MAXN; j += i) // marking spf[j] if it is not // previously marked if (spf[j] == j) spf[j] = i; } } } // A O(log n) function returning primefactorization // by dividing by smallest prime factor at every step set<int> getFactorization(int x) { set<int> ret; while (x != 1) { ret.insert(spf[x]); x = x / spf[x]; } return ret; } void ssolve(std::istream &in, std::ostream &out) { int n; s(n); vi a(n); f(i, 0, n) s(a[i]); int gc = __gcd(a[0], a[1]); f(i, 0, n) gc = __gcd(gc, a[i]); if (gc > 1) { out << "not coprime" << endl; return; } sieve(); map<int, int> dist; f(i, 0, n) { auto primes = getFactorization(a[i]); for (auto x : primes) { dist[x]++; } } bool pairwise = true; for (auto k : dist) { if (k.second > 1) { pairwise = false; } } out << (pairwise ? "pairwise coprime" : "setwise coprime") << endl; } class ECoprime { public: void solve(std::istream &in, std::ostream &out) { ios_base::sync_with_stdio(false); in.tie(0); out.tie(0); int t; int READ = 0; if (READ) s(t); else t = 1; while (t--) { ssolve(in, out); } } }; integer main() { ECoprime solver; std::istream &in(std::cin); std::ostream &out(std::cout); solver.solve(in, out); }
replace
44
45
44
45
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define rep(A, B, C) for (A = B; A < C; ++A) #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define all(A) A.begin(), A.end() using namespace std; ///////////////////////////////////////////////////// #define MOD (ll)(1e9 + 7) #define vv vector ll gcd(ll p, ll q) { if (q == 0) { return p; } return gcd(q, p % q); } ll N, A[202020]; ll i, j, k; int main() { scanf("%lld", &N); rep(i, 0, N) { scanf("%lld", &A[i]); } j = A[0]; rep(i, 1, N) { j = gcd(j, A[i]); } if (j != 1) { printf("not coprime\n"); return 0; } const ll Amx = 1010101; vv<ll> mk(Amx + 10), mk2(Amx + 10); rep(i, 0, N) { ++mk2[A[i]]; } rep(i, 2, Amx) { if (mk[i]) { continue; } ll a = 0; for (j = i; j < Amx; j += i) { ++mk[j]; a += mk2[j]; } if (a >= 2) break; } if (i == Amx) { printf("pairwise coprime\n"); } else { printf("setwise coprime\n"); } return 0; }
#include <bits/stdc++.h> #define ll long long #define rep(A, B, C) for (A = B; A < C; ++A) #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define all(A) A.begin(), A.end() using namespace std; ///////////////////////////////////////////////////// #define MOD (ll)(1e9 + 7) #define vv vector ll gcd(ll p, ll q) { if (q == 0) { return p; } return gcd(q, p % q); } ll N, A[1010101]; ll i, j, k; int main() { scanf("%lld", &N); rep(i, 0, N) { scanf("%lld", &A[i]); } j = A[0]; rep(i, 1, N) { j = gcd(j, A[i]); } if (j != 1) { printf("not coprime\n"); return 0; } const ll Amx = 1010101; vv<ll> mk(Amx + 10), mk2(Amx + 10); rep(i, 0, N) { ++mk2[A[i]]; } rep(i, 2, Amx) { if (mk[i]) { continue; } ll a = 0; for (j = i; j < Amx; j += i) { ++mk[j]; a += mk2[j]; } if (a >= 2) break; } if (i == Amx) { printf("pairwise coprime\n"); } else { printf("setwise coprime\n"); } return 0; }
replace
24
25
24
25
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1000000007 #define MAXN 100001 // stores smallest prime factor for every number int spf[MAXN]; // Calculating SPF (Smallest Prime Factor) for every // number till MAXN. // Time Complexity : O(nloglogn) void sieve() { spf[1] = 1; for (int i = 2; i < MAXN; i++) // marking smallest prime factor for every // number to be itself. spf[i] = i; // separately marking spf for every even // number as 2 for (int i = 4; i < MAXN; i += 2) spf[i] = 2; for (int i = 3; i * i < MAXN; i++) { // checking if i is prime if (spf[i] == i) { // marking SPF for all numbers divisible by i for (int j = i * i; j < MAXN; j += i) // marking spf[j] if it is not // previously marked if (spf[j] == j) spf[j] = i; } } } // A O(log n) function returning primefactorization // by dividing by smallest prime factor at every step set<int> getFactorization(int x) { set<int> ret; while (x != 1) { ret.insert(spf[x]); x = x / spf[x]; } return ret; } class Graph { int V; vector<list<int>> edges; public: Graph(int nodes) { V = nodes; edges.resize(nodes + 1); } void addEdge(int from, int to) { edges[from].push_back(to); } int min_dist(int &fin, int i, map<int, bool> &special, vector<bool> &check) { check[i] = true; multiset<int> ms; int k; for (auto it = edges[i].begin(); it != edges[i].end(); it++) { if (check[*it] == true) continue; k = min_dist(fin, *it, special, check); if (k != 0) ms.insert(k); } for (auto it = ms.begin(); it != ms.end(); it++) { fin += (*it); // cout << *it << " "; } // cout << endl; if (ms.size() % 2 == 0) { if (special[i]) return 1; return 0; } else { if (special[i]) return 0; auto it = ms.begin(); fin -= (*it); return (*it) + 1; } } int max_comp() { int mx = INT_MIN; vector<bool> check(V + 1, false); for (int i = 1; i <= V; i++) { if (!check[i]) { int count = 0; DFS_util(check, i, count); if (count > mx) { mx = count; } } } return mx; } void DFS_util(vector<bool> &check, int i, int &count) { check[i] = true; count++; for (auto it = edges[i].begin(); it != edges[i].end(); it++) { if (!check[*it]) { DFS_util(check, *it, count); } } return; } }; int main() { sieve(); int t = 1; // cin >> t; while (t--) { int n; cin >> n; vector<int> arr; int temp; for (int i = 0; i < n; i++) { cin >> temp; arr.push_back(temp); } map<int, int> mp; set<int> s = getFactorization(arr[0]); for (auto it = s.begin(); it != s.end(); it++) { mp[*it]++; } int f = 0; for (int i = 1; i < n; i++) { set<int> temp = getFactorization(arr[i]); for (auto it = temp.begin(); it != temp.end(); it++) { mp[*it]++; if (f == 0 && s.count(*it)) { f = 1; } else { s.insert(*it); } } } if (f == 0) { cout << "pairwise coprime" << endl; } else { for (auto it = mp.begin(); it != mp.end(); it++) { if (it->second >= n) { cout << "not coprime" << endl; return 0; } } cout << "setwise coprime" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1000000007 #define MAXN 1000001 // stores smallest prime factor for every number int spf[MAXN]; // Calculating SPF (Smallest Prime Factor) for every // number till MAXN. // Time Complexity : O(nloglogn) void sieve() { spf[1] = 1; for (int i = 2; i < MAXN; i++) // marking smallest prime factor for every // number to be itself. spf[i] = i; // separately marking spf for every even // number as 2 for (int i = 4; i < MAXN; i += 2) spf[i] = 2; for (int i = 3; i * i < MAXN; i++) { // checking if i is prime if (spf[i] == i) { // marking SPF for all numbers divisible by i for (int j = i * i; j < MAXN; j += i) // marking spf[j] if it is not // previously marked if (spf[j] == j) spf[j] = i; } } } // A O(log n) function returning primefactorization // by dividing by smallest prime factor at every step set<int> getFactorization(int x) { set<int> ret; while (x != 1) { ret.insert(spf[x]); x = x / spf[x]; } return ret; } class Graph { int V; vector<list<int>> edges; public: Graph(int nodes) { V = nodes; edges.resize(nodes + 1); } void addEdge(int from, int to) { edges[from].push_back(to); } int min_dist(int &fin, int i, map<int, bool> &special, vector<bool> &check) { check[i] = true; multiset<int> ms; int k; for (auto it = edges[i].begin(); it != edges[i].end(); it++) { if (check[*it] == true) continue; k = min_dist(fin, *it, special, check); if (k != 0) ms.insert(k); } for (auto it = ms.begin(); it != ms.end(); it++) { fin += (*it); // cout << *it << " "; } // cout << endl; if (ms.size() % 2 == 0) { if (special[i]) return 1; return 0; } else { if (special[i]) return 0; auto it = ms.begin(); fin -= (*it); return (*it) + 1; } } int max_comp() { int mx = INT_MIN; vector<bool> check(V + 1, false); for (int i = 1; i <= V; i++) { if (!check[i]) { int count = 0; DFS_util(check, i, count); if (count > mx) { mx = count; } } } return mx; } void DFS_util(vector<bool> &check, int i, int &count) { check[i] = true; count++; for (auto it = edges[i].begin(); it != edges[i].end(); it++) { if (!check[*it]) { DFS_util(check, *it, count); } } return; } }; int main() { sieve(); int t = 1; // cin >> t; while (t--) { int n; cin >> n; vector<int> arr; int temp; for (int i = 0; i < n; i++) { cin >> temp; arr.push_back(temp); } map<int, int> mp; set<int> s = getFactorization(arr[0]); for (auto it = s.begin(); it != s.end(); it++) { mp[*it]++; } int f = 0; for (int i = 1; i < n; i++) { set<int> temp = getFactorization(arr[i]); for (auto it = temp.begin(); it != temp.end(); it++) { mp[*it]++; if (f == 0 && s.count(*it)) { f = 1; } else { s.insert(*it); } } } if (f == 0) { cout << "pairwise coprime" << endl; } else { for (auto it = mp.begin(); it != mp.end(); it++) { if (it->second >= n) { cout << "not coprime" << endl; return 0; } } cout << "setwise coprime" << endl; } } return 0; }
replace
4
5
4
5
0
p02574
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL << 62 #define inf 1000000007 ll dep(ll a, ll b) { if (b == 0) { return a; } return dep(b, a % b); } int main() { ll n; cin >> n; ll ch[1000010]; for (ll i = 0; i < n; i++) { cin >> ch[i]; } ll ch2[1000010] = {}; for (ll i = 2; i < 1000010; i++) { if (ch2[i] != 0) { continue; } for (ll j = 1; i * j < 100010; j++) { ll now = i * j; if (ch2[now] == 0) { ch2[i * j] = i; } } } // for(ll i=0;i<1000010;i++){ // cout << i<< " "<<ch2[i]<<endl; //} ll ch3[1000010] = {}; bool ans1 = true; // cout <<ans1<<endl; for (ll i = 0; i < n; i++) { ll now = ch[i]; while (now != 1) { ll next = ch2[now]; if (ch3[next] == 1) { ans1 = false; break; } ch3[next] = 1; while (now % next == 0) { now /= next; } } if (ans1 == false) { break; } } if (ans1) { cout << "pairwise coprime"; return 0; } ll gcd = ch[0]; for (ll i = 1; i < n; i++) { gcd = dep(max(gcd, ch[i]), min(gcd, ch[i])); } if (gcd == 1) { cout << "setwise coprime"; } else { cout << "not coprime"; } // your code goes here return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL << 62 #define inf 1000000007 ll dep(ll a, ll b) { if (b == 0) { return a; } return dep(b, a % b); } int main() { ll n; cin >> n; ll ch[1000010]; for (ll i = 0; i < n; i++) { cin >> ch[i]; } ll ch2[1000010] = {}; for (ll i = 2; i < 1000010; i++) { if (ch2[i] != 0) { continue; } for (ll j = 1; i * j < 1000010; j++) { ll now = i * j; if (ch2[now] == 0) { ch2[i * j] = i; } } } // for(ll i=0;i<1000010;i++){ // cout << i<< " "<<ch2[i]<<endl; //} ll ch3[1000010] = {}; bool ans1 = true; // cout <<ans1<<endl; for (ll i = 0; i < n; i++) { ll now = ch[i]; while (now != 1) { ll next = ch2[now]; if (ch3[next] == 1) { ans1 = false; break; } ch3[next] = 1; while (now % next == 0) { now /= next; } } if (ans1 == false) { break; } } if (ans1) { cout << "pairwise coprime"; return 0; } ll gcd = ch[0]; for (ll i = 1; i < n; i++) { gcd = dep(max(gcd, ch[i]), min(gcd, ch[i])); } if (gcd == 1) { cout << "setwise coprime"; } else { cout << "not coprime"; } // your code goes here return 0; }
replace
23
24
23
24
-11
p02574
C++
Time Limit Exceeded
/****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <bits/stdc++.h> using namespace std; void st() { cout << "setwise coprime"; } void pr() { cout << "pairwise coprime"; } void no() { cout << "not coprime"; } bool primechk[1000007]; map<long long, long long> mp; int main() { long long n, i, x, cnt, j, bb = 0; // preprocess(1000004); cin >> n; long long arr[n + 5]; for (i = 0; i < n; i++) { cin >> arr[i]; } for (i = 0; i < n; i++) { x = arr[i]; for (j = 2; j * j <= x; j++) { if (x % j == 0) { mp[j]++; if (mp[j] == n) { no(); return 0; } else if (mp[j] > 1) { bb = 1; } while (x % j == 0) { x /= j; } } } if (x >= 2) { mp[x]++; if (mp[x] == n) { no(); return 0; } else if (mp[x] > 1) { bb = 1; } } } if (bb) { st(); } else { pr(); } return 0; }
/****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <bits/stdc++.h> using namespace std; void st() { cout << "setwise coprime"; } void pr() { cout << "pairwise coprime"; } void no() { cout << "not coprime"; } bool primechk[1000007]; map<long long, long long> mp; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, i, x, cnt, j, bb = 0; // preprocess(1000004); cin >> n; long long arr[n + 5]; for (i = 0; i < n; i++) { cin >> arr[i]; } for (i = 0; i < n; i++) { x = arr[i]; for (j = 2; j * j <= x; j++) { if (x % j == 0) { mp[j]++; if (mp[j] == n) { no(); return 0; } else if (mp[j] > 1) { bb = 1; } while (x % j == 0) { x /= j; } } } if (x >= 2) { mp[x]++; if (mp[x] == n) { no(); return 0; } else if (mp[x] > 1) { bb = 1; } } } if (bb) { st(); } else { pr(); } return 0; }
insert
21
21
21
23
TLE