Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ll long long
- #include <bits/stdc++.h>
- using namespace std;
- const int OO = 1e9;
- const double EPS = 1e-9;
- vector<int> primes;
- bool is_prime[10001];
- void pre() {
- memset(is_prime,1,sizeof(is_prime));
- for(int i = 2; i < 10001; i++) {
- if(is_prime[i]) {
- primes.push_back(i);
- for(int j = i*2; j < 10001; j+= i) {
- is_prime[j] = false;
- }
- }
- }
- }
- vector<int> ftr(ll x) {
- vector<int> ret;
- for(int e : primes) {
- if(x == 1) {
- break;
- }
- if(x%e == 0) {
- ret.push_back(e);
- while(x%e == 0) {
- x /= e;
- }
- }
- }
- return ret;
- }
- map<ll,ll> mp;
- ll arr[10000];
- ll p[10000];
- ll cnt(vector<int> &f, int idx = 0, int len = 0, ll total = 1) {
- if(idx == f.size()) {
- if(len == 0) {
- return 0;
- }
- return ((mp[total] * (mp[total]-1) * (mp[total]-2))/6) * (len%2 ? 1:-1);
- }
- return cnt(f,idx+1,len+1,total*f[idx]) + cnt(f,idx+1,len,total);
- }
- void add(vector<int> &f, int idx = 0, ll total = 1) {
- if(idx == f.size()) {
- mp[total]++;
- }
- else {
- add(f,idx+1,total*f[idx]);
- add(f,idx+1,total);
- }
- }
- int main()
- {
- ios_base::sync_with_stdio(NULL);
- cin.tie(0);
- cout.tie(0);
- pre();
- ll n;
- while(cin >> n) {
- mp.clear();
- for(int i = 0; i < n; i++) {
- cin >> arr[i];
- }
- ll ans = (n * (n-1) * (n-2) * (n-3))/24;
- for(int i = n-1; i >= 0; i--) {
- vector<int> f = ftr(arr[i]);
- ans -= cnt(f);
- add(f);
- }
- cout << ans << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement