Kevin_Zhang

G

Sep 18th, 2021
794
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. #define pb emplace_back
  5. #define AI(i) begin(i), end(i)
  6. template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
  7. template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
  8. #ifdef KEV
  9. #define DE(args...) kout(__LINE__, "[ " + string(#args) + " ] ", args)
  10. void kout() { cerr << endl; }
  11. template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
  12. template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
  13. #else
  14. #define DE(...) 0
  15. #define debug(...) 0
  16. #endif
  17.  
  18. const int MAX_N = 300010, p = 998'244'353;
  19.  
  20. int n, per[MAX_N], cnt[MAX_N], vis[MAX_N];
  21. vector<int> pfac[MAX_N];
  22.  
  23. int32_t main() {
  24.     ios_base::sync_with_stdio(0), cin.tie(0);
  25.  
  26.     cin >> n;
  27.     for (int i = 1;i <= n;++i) cin >> per[i];
  28.  
  29.     for (int i = 2;i <= n;++i) if (pfac[i].empty()) {
  30.         for (int j = i;j <= n;j += i)
  31.             pfac[j].pb(i);
  32.     }
  33.  
  34.     for (int i = 1;i <= n;++i) {
  35.         if (vis[i]) continue;
  36.         int len = 1;
  37.         while (i != per[i]) {
  38.             vis[ per[i] ] = true;
  39.             swap(per[i], per[ per[i] ]);
  40.             ++len;
  41.         }
  42.  
  43.         for (int j : pfac[len]) {
  44.             while (len % j == 0) {
  45.                 ++cnt[j];
  46.                 len /= j;
  47.             }
  48.         }
  49.     }
  50.  
  51.  
  52. }
  53.  
RAW Paste Data