Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define pb emplace_back
- #define AI(i) begin(i), end(i)
- using namespace std;
- using ll = long long;
- template<class T>
- bool chmax(T &val, T nv) { return val < nv ? (val = nv, true) : false; }
- template<class T>
- bool chmin(T &val, T nv) { return nv < val ? (val = nv, true) : false; }
- #ifdef KEV
- #define DE(args...) kout("[ " + string(#args) + " ] = ", args)
- void kout() {cerr << endl;}
- template<class T1, class ...T2>
- void kout (T1 v, T2 ...e) { cerr << v << ' ', kout(e...); }
- template<class T>
- void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
- #else
- #define DE(...) 0
- #define debug(...) 0
- #endif
- // What I should check
- // 1. overflow
- // 2. corner cases
- // Enjoy the problem instead of hurrying to AC
- // Good luck !
- const int MAX_N = 10000010;
- int pn[MAX_N], pl, minp[MAX_N], cnt[MAX_N];
- int n, k, a[MAX_N], mxa;
- vector<int> getfac(int v) {
- vector<int> res;
- while (v > 1) {
- res.pb(minp[v]);
- while (minp[v] == res.back())
- v /= minp[v];
- }
- return res;
- }
- // return how many x such that gcd(x, v) > 1
- // δΈδΊθ³ͺ
- vector<int> getallfac(const vector<int> &fac) {
- int m = fac.size();
- vector<int> dp(1<<m, 1);
- for (int s = 1;s < 1<<m;++s)
- dp[s] = dp[s ^ (1<<__lg(s))] * fac[__lg(s)];
- return dp;
- }
- int qry(int v) {
- ll res = 0;
- auto pfac = getfac(v);
- auto allfac = getallfac(pfac);
- int m = pfac.size();
- for (int s = 1;s < 1<<m;++s)
- res += cnt[allfac[s]] * (__builtin_popcount(s) & 1 ? 1 : -1);
- return res;
- }
- int32_t main() {
- ios_base::sync_with_stdio(0), cin.tie(0);
- cin >> n >> k;
- for (int i = 0;i < n;++i)
- cin >> a[i];
- mxa = *max_element(a, a+n);
- for (int i = 2;i <= mxa;++i) {
- if (minp[i] == 0)
- minp[i] = i, pn[pl++] = i;
- for (int j : minp) {
- if (j == 0 || i * j > mxa) break;
- minp[i * j] = j;
- if (i % j == 0) break;
- }
- }
- for (int i = 0;i < n;++i) {
- auto allfac = getallfac(getfac(a[i]));
- for (int f : allfac)
- ++cnt[f];
- }
- // prime numbers and cnt is done
- int midpoint = -1;
- for (int i = 0;i < n;++i) if (qry(a[i]) >= 3) {
- midpoint = i; break;
- }
- if (midpoint == -1) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement