pb_jiang

CF2154C1 WA

Oct 19th, 2025
1,355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. // Problem: C1. No Cost Too Great (Easy Version)
  2. // Contest: Codeforces - Codeforces Round 1060 (Div. 2)
  3. // URL: https://codeforces.com/contest/2154/problem/C1
  4. // Memory Limit: 256 MB
  5. // Time Limit: 3000 ms
  6. //
  7. // Powered by CP Editor (https://cpeditor.org)
  8.  
  9. #include <assert.h>
  10. #include <bits/stdc++.h>
  11. using namespace std;
  12. #ifndef __DEBUG__
  13. #define dbg(...) 42
  14. #endif
  15. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  16.  
  17. namespace rngs = std::ranges;
  18. using ll = long long;
  19. using a2l = array<ll, 2>;
  20. using vl = vector<ll>;
  21.  
  22. void solve2()
  23. {
  24.     ll n;
  25.     cin >> n;
  26.     vl a(n), b(n);
  27.     for (auto &x : a)
  28.         cin >> x;
  29.     for (auto &x : b)
  30.         cin >> x;
  31. }
  32.  
  33. vl ps;
  34.  
  35. void solve()
  36. {
  37.     ll n, ecnt = 0;
  38.     cin >> n;
  39.     vl a(n), b(n);
  40.     map<ll, ll> pcnt, p1cnt;
  41.     for (auto &x : a)
  42.         cin >> x;
  43.     for (auto &x : b)
  44.         cin >> x;
  45.  
  46.     for (auto x : a) {
  47.         for (auto f : ps) {
  48.             if (f * f > x) {
  49.                 if (std::binary_search(ps.begin(), ps.end(), x))
  50.                     pcnt[x] += 1;
  51.                 if (std::binary_search(ps.begin(), ps.end(), x + 1))
  52.                     p1cnt[x + 1] += 1;
  53.                 break;
  54.             }
  55.  
  56.             if (x % f == 0)
  57.                 pcnt[f] += 1;
  58.             if ((x + 1) % f == 0)
  59.                 p1cnt[f] += 1;
  60.         }
  61.     }
  62.  
  63.     ll val = 2;
  64.     for (auto [k, v] : pcnt) {
  65.         if (v >= 2)
  66.             dbg(k, v, val), val = 0;
  67.         if (v == 1 && p1cnt.count(k))
  68.             val = min(val, 1ll);
  69.         if (p1cnt.count(k) && p1cnt[k] >= 2)
  70.             val = min(val, 2ll);
  71.         // val = min(val, 2 - min(v, 2ll));
  72.     }
  73.  
  74.     cout << val << '\n';
  75. }
  76.  
  77. int main(int argc, char **argv)
  78. {
  79.     std::ios::sync_with_stdio(false);
  80.     std::cin.tie(nullptr);
  81.  
  82.     for (ll i = 2; i < 2e5 + 3; ++i) {
  83.         bool is_prime = true;
  84.         for (ll j = 2; j * j <= i && is_prime; ++j)
  85.             if (i % j == 0)
  86.                 is_prime = false;
  87.         if (is_prime)
  88.             ps.push_back(i);
  89.     }
  90.  
  91.     ll t = 1;
  92.     cin >> t;
  93.     while (t--)
  94.         solve();
  95.  
  96.     return 0;
  97. };
  98.  
Advertisement
Add Comment
Please, Sign In to add comment