Advertisement
_rashed

MSKYCODE

Jul 29th, 2022
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #define ll long long
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. const int OO = 1e9;
  6. const double EPS = 1e-9;
  7.  
  8. vector<int> primes;
  9. bool is_prime[10001];
  10.  
  11. void pre() {
  12.     memset(is_prime,1,sizeof(is_prime));
  13.     for(int i = 2; i < 10001; i++) {
  14.         if(is_prime[i]) {
  15.             primes.push_back(i);
  16.             for(int j = i*2; j < 10001; j+= i) {
  17.                 is_prime[j] = false;
  18.             }
  19.         }
  20.     }
  21. }
  22.  
  23. vector<int> ftr(ll x) {
  24.     vector<int> ret;
  25.     for(int e : primes) {
  26.         if(x == 1) {
  27.             break;
  28.         }
  29.         if(x%e == 0) {
  30.             ret.push_back(e);
  31.             while(x%e == 0) {
  32.                 x /= e;
  33.             }
  34.         }
  35.     }
  36.     return ret;
  37. }
  38.  
  39. map<ll,ll> mp;
  40. ll arr[10000];
  41. ll p[10000];
  42.  
  43. ll cnt(vector<int> &f, int idx = 0, int len = 0, ll total = 1) {
  44.     if(idx == f.size()) {
  45.         if(len == 0) {
  46.             return 0;
  47.         }
  48.         return ((mp[total] * (mp[total]-1) * (mp[total]-2))/6) * (len%2 ? 1:-1);
  49.     }
  50.     return cnt(f,idx+1,len+1,total*f[idx]) + cnt(f,idx+1,len,total);
  51. }
  52.  
  53. void add(vector<int> &f, int idx = 0, ll total = 1) {
  54.     if(idx == f.size()) {
  55.         mp[total]++;
  56.     }
  57.     else {
  58.         add(f,idx+1,total*f[idx]);
  59.         add(f,idx+1,total);
  60.     }
  61. }
  62.  
  63. int main()
  64. {
  65.     ios_base::sync_with_stdio(NULL);
  66.     cin.tie(0);
  67.     cout.tie(0);
  68.     pre();
  69.     ll n;
  70.     while(cin >> n) {
  71.         mp.clear();
  72.         for(int i = 0; i < n; i++) {
  73.             cin >> arr[i];
  74.         }
  75.         ll ans = (n * (n-1) * (n-2) * (n-3))/24;
  76.         for(int i = n-1; i >= 0; i--) {
  77.             vector<int> f = ftr(arr[i]);
  78.             ans -= cnt(f);
  79.             add(f);
  80.         }
  81.         cout << ans << "\n";
  82.     }
  83.  
  84.     return 0;
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement