結果
問題 | No.1059 素敵な集合 |
ユーザー | warabi0906 |
提出日時 | 2023-02-15 17:56:12 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 12 ms / 2,000 ms |
コード長 | 4,694 bytes |
コンパイル時間 | 3,554 ms |
コンパイル使用メモリ | 234,688 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-18 02:19:44 |
合計ジャッジ時間 | 4,462 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 12 ms
5,376 KB |
testcase_02 | AC | 3 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 3 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 4 ms
5,376 KB |
testcase_11 | AC | 3 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 4 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 6 ms
5,376 KB |
testcase_16 | AC | 3 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 12 ms
5,376 KB |
testcase_20 | AC | 11 ms
5,376 KB |
testcase_21 | AC | 6 ms
5,376 KB |
コンパイルメッセージ
main.cpp:19:26: warning: overflow in conversion from 'long long int' to 'int' changes value from '-9223372036854775808' to '0' [-Woverflow] 19 | constexpr int INF = (1LL << 63); | ~~~~~^~~~~~
ソースコード
#include <bits/stdc++.h> #include "atcoder/all" #define debug cout << "OK" << endl; template<typename T> inline bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; } template<typename T> inline bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; } inline int Code(char c) { if ('A' <= c and c <= 'Z')return (int)(c - 'A'); if ('a' <= c and c <= 'z')return (int)(c - 'a'); if ('0' <= c and c <= '9')return (int)(c - '0'); assert(false); } using namespace std; using namespace atcoder; using minit = modint1000000007; constexpr int MOD = 1000000007; constexpr int MOD2 = 998244353; constexpr int INF = (1LL << 63); template<typename T> ostream& operator << (ostream& st, const vector<T>& v) { for (const T value : v) { st << value << " "; } return st; } template<typename T> istream& operator >> (istream& st, vector<T>& v) { for (T& value : v) { st >> value; } return st; } int pow_(const int a, const int b, const int m = INF) { int res = 1; int base = a; for (int i = 0; i < 64; i++) { if (b & (1ll << i))res *= base; res %= m; base = base * base; base %= m; } return res; } inline int gcd(const int a, const int b) { return (b == 0 ? a : gcd(b, a % b)); } inline int lcm(const int a, const int b) { return a * b / gcd(a, b); } // class nCk { public: const int m; const int MAXIMUM = 1000000; vector<int> fac, facinv, inv; nCk(int m_); ~nCk(); int com(int n, int k)const; }; nCk::nCk(int m_):m(m_) { fac.resize(MAXIMUM + 3); facinv.resize(MAXIMUM + 3); inv.resize(MAXIMUM + 3); fac[0] = fac[1] = 1; facinv[0] = facinv[1] = 1; inv[1] = 1; for (int i = 2; i < MAXIMUM + 2; i++) { fac[i] = fac[i - 1] * i % m; inv[i] = m - inv[m % i] * (m / i) % m; facinv[i] = facinv[i - 1] * inv[i] % m; } } nCk::~nCk(){} int nCk::com(int n, int k)const { if (n < k)return 0; assert(!(n < 0 || k < 0)); return fac[n] * (facinv[k] * facinv[n - k] % m) % m; } template<typename T> vector<long long> press(const vector<T>& arr) { vector<T> X = arr; sort(X.begin(), X.end()); X.erase(unique(X.begin(), X.end()), X.end()); vector<long long> ans(arr.size()); for (int i = 0; i < arr.size(); i++) { ans[i] = lower_bound(X.begin(), X.end(), arr[i]) - X.begin(); } return ans; } class LCA { public: vector<vector<long long>> parent; vector<long long> dist; vector<vector<long long>> G; LCA(const vector<vector<long long>>& gr) { init(gr); } void dfs(long long v, long long p, long long d) { parent[0][v] = p; dist[v] = d; for (long long next : G[v]) { if (next == p)continue; dfs(next, v, d + 1); } return; } void init(const vector<vector<long long>>& gr) { G = gr; parent.assign(33, vector<long long>(G.size(), -1LL)); dist.assign(G.size(), -1LL); dfs(0LL, -1LL, 0LL); for (int i = 0; i < 32; i++) { for (int j = 0; j < G.size(); j++) { if (parent[i][j] < 0LL) { parent[i + 1][j] = -1LL; } else { parent[i + 1][j] = parent[i][parent[i][j]]; } } } return; } long long lca(long long u, long long v) { if (u == -1 and v == -1)return -1; else if (u == -1)return v; else if (v == -1)return u; if (dist[u] < dist[v])swap(u, v); long long between = dist[u] - dist[v]; for (int i = 0; i < 33; i++) { if (between & (1LL << i)) { u = parent[i][u]; } } if (u == v)return u; for (int i = 32; i >= 0; i--) { if (parent[i][u] != parent[i][v]) { u = parent[i][u]; v = parent[i][v]; } } assert(parent[0][u] == parent[0][v]); return parent[0][u]; } long long get_dist(long long u, long long v) { return dist[u] + dist[v] - 2 * dist[lca(u, v)]; } bool on_path(long long u, long long v, long long a) { return get_dist(u, v) == get_dist(u, a) + get_dist(v, a); } }; // class Solver { public: int T; Solver() :T(1) {} ~Solver(){} void ios()const; void multi(); void solve() const; void sp(int x)const; void ft()const; // // }; void Solver::ios() const { cin.tie(nullptr); ios_base::sync_with_stdio(false); return; } void Solver::multi() { cin >> T; return; } void Solver::sp(const int x)const { cout << fixed << setprecision(x) << endl; return; } void Solver::ft() const { } void Solver::solve() const { int L, R; cin >> L >> R; dsu d(R + 1); int cnt = 0; for (int e = L; e <= R; e++) { for (int f = e * 2; f <= R; f += e) { if (!d.same(e, f)) { d.merge(e, f); cnt++; } } } cout << (R - L - cnt) << endl; } signed main() { Solver solver; solver.ios(); //solver.ft(); //solver.multi(); //solver.sp(); for (int i = 0; i < solver.T; i++) solver.solve(); return 0; } /* * わらびのコードこーどすぺーす (σ・∀・)σゲッツ!! */