Advertisement
Kevin_Zhang

Untitled

Jan 6th, 2021
955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define pb emplace_back
  3. #define AI(i) begin(i), end(i)
  4. using namespace std;
  5. using ll = long long;
  6. template<class T>
  7. bool chmax(T &val, T nv) { return val < nv ? (val = nv, true) : false; }
  8. template<class T>
  9. bool chmin(T &val, T nv) { return nv < val ? (val = nv, true) : false; }
  10. #ifdef KEV
  11. #define DE(args...) kout("[ " + string(#args) + " ] = ", args)
  12. void kout() {cerr << endl;}
  13. template<class T1, class ...T2>
  14. void kout (T1 v, T2 ...e) { cerr << v << ' ', kout(e...); }
  15. template<class T>
  16. void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
  17. #else
  18. #define DE(...) 0
  19. #define debug(...) 0
  20. #endif
  21. // What I should check
  22. // 1. overflow
  23. // 2. corner cases
  24. // Enjoy the problem instead of hurrying to AC
  25. // Good luck !
  26. const int MAX_N = 10000010;
  27.  
  28. int pn[MAX_N], pl, minp[MAX_N], cnt[MAX_N];
  29.  
  30. int n, k, a[MAX_N], mxa;
  31.  
  32. vector<int> getfac(int v) {
  33.     vector<int> res;
  34.     while (v > 1) {
  35.         res.pb(minp[v]);
  36.         while (minp[v] == res.back())
  37.             v /= minp[v];
  38.     }
  39.     return res;
  40. }
  41. // return how many x such that gcd(x, v) > 1
  42. // 不互θ³ͺ
  43. vector<int> getallfac(const vector<int> &fac) {
  44.     int m = fac.size();
  45.     vector<int> dp(1<<m, 1);
  46.     for (int s = 1;s < 1<<m;++s)
  47.         dp[s] = dp[s ^ (1<<__lg(s))] * fac[__lg(s)];
  48.     return dp;
  49. }
  50. int qry(int v) {
  51.     ll res = 0;
  52.     auto pfac = getfac(v);
  53.     auto allfac = getallfac(pfac);
  54.     int m = pfac.size();
  55.     for (int s = 1;s < 1<<m;++s)
  56.         res += cnt[allfac[s]] * (__builtin_popcount(s) & 1 ? 1 : -1);
  57.     return res;
  58. }
  59. int32_t main() {
  60.     ios_base::sync_with_stdio(0), cin.tie(0);
  61.     cin >> n >> k;
  62.     for (int i = 0;i < n;++i)
  63.         cin >> a[i];
  64.  
  65.     mxa = *max_element(a, a+n);
  66.  
  67.     for (int i = 2;i <= mxa;++i) {
  68.         if (minp[i] == 0)
  69.             minp[i] = i, pn[pl++] = i;
  70.         for (int j : minp) {
  71.             if (j == 0 || i * j > mxa) break;
  72.             minp[i * j] = j;
  73.             if (i % j == 0) break;
  74.         }
  75.     }
  76.  
  77.     for (int i = 0;i < n;++i) {
  78.         auto allfac = getallfac(getfac(a[i]));
  79.         for (int f : allfac)
  80.             ++cnt[f];
  81.     }
  82.  
  83.     // prime numbers and cnt is done
  84.    
  85.     int midpoint = -1;
  86.     for (int i = 0;i < n;++i) if (qry(a[i]) >= 3) {
  87.         midpoint = i; break;
  88.     }
  89.  
  90.     if (midpoint == -1) {
  91.  
  92.     }
  93.    
  94.  
  95.  
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement