Submission #847200
Source Code Expand
Copy
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAX_N = 100030; // Change as necessary const ll MODD = 1000000009; // vector<ll> pr; bool is_prime[MAX_N]; __int128 fast_exp_mod(__int128 b, __int128 n, __int128 m) { if (n == 0) return 1 % m; if (n % 2 == 0) return fast_exp_mod((b*b)%m, n/2, m); return (fast_exp_mod(b, n-1, m) * b) % m; } ll q_mod(ll x,ll m){ return (x >= m) ? x-m : x; } ll mult_mod(ll x,ll y,ll m){ // Use int128 __int128 X = x, Y = y, M = m; return ll(X * Y % M); ll r = 0; while(y){ if(y % 2) r = q_mod(r+x,m); y >>= 1; x = q_mod(x << 1,m); } return r; } const ll val[] = {2,13,23,1662803}; bool isLargePrime(ll n){ if(n < 100000) return false; for(auto p : pr){ if(p*p*p > n) break; if(n % p == 0) return false; } ll s = __builtin_ctzll(n-1), d = (n-1) >> s; for(int i=0;i<4;i++){ if(val[i] >= n) break; ll x = fast_exp_mod(val[i],d,n); // Use int128 in here if(x == 1 || x == n-1) continue; for(ll r=1;r<s;r++) if((x = mult_mod(x,x,n)) == n-1) goto nextPr; return false; nextPr:; } return true; } vector<pair<ll,int> > factor(long long x){ vector<pair<ll,int> > ans; if(isLargePrime(x)){ ans.emplace_back(x,1); return ans; } for(auto p : pr){ if(p*p > x) break; if(x % p == 0){ int ctr = 0; while(x % p == 0){ x /= p; ctr++; } if(ctr % 3) ans.emplace_back(p,ctr%3); } } if(x != 1) ans.emplace_back(x,1); return ans; } ll A[MAX_N]; map<vector<pair<ll,int> >, int> M; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); pr.push_back(2); fill(is_prime,is_prime+MAX_N,true); for(int i=3;i*i<MAX_N;i++) if(is_prime[i]) for(int j=i*i;j<MAX_N;j+=i) is_prime[j] = false; for(int i=3;i<MAX_N;i+=2) if(is_prime[i]) pr.push_back(i); int n; cin >> n; for(int i=0;i<n;i++) cin >> A[i]; for(int i=0;i<n;i++) M[factor(A[i])]++; int ans = 0; for(const auto& x : M){ vector<pair<ll,int> > tmp = x.first; bool found = false; for(auto& p : tmp){ p.second = (3-p.second)%3; found |= p.second; } if(!found) ans+=2; else if(M.count(tmp)){ ans += max((ll)x.second,(ll)M[tmp]); } else { ans += x.second*2; } } cout << ans/2 << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Anticube |
User | MathCrusader |
Language | C++14 (GCC 5.4.1) |
Score | 1100 |
Code Size | 2517 Byte |
Status | AC |
Exec Time | 1781 ms |
Memory | 16896 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1100 / 1100 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt, s3.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, s1.txt, s2.txt, s3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 1762 ms | 16896 KB |
02.txt | AC | 1773 ms | 16896 KB |
03.txt | AC | 1761 ms | 16896 KB |
04.txt | AC | 1760 ms | 16896 KB |
05.txt | AC | 1748 ms | 16896 KB |
06.txt | AC | 1739 ms | 16896 KB |
07.txt | AC | 1735 ms | 16896 KB |
08.txt | AC | 1755 ms | 16896 KB |
09.txt | AC | 1756 ms | 16896 KB |
10.txt | AC | 1781 ms | 16896 KB |
11.txt | AC | 1230 ms | 4608 KB |
12.txt | AC | 1230 ms | 4608 KB |
13.txt | AC | 1617 ms | 5248 KB |
14.txt | AC | 1649 ms | 5248 KB |
15.txt | AC | 1648 ms | 5248 KB |
16.txt | AC | 1650 ms | 5248 KB |
17.txt | AC | 128 ms | 1280 KB |
18.txt | AC | 128 ms | 1280 KB |
19.txt | AC | 128 ms | 1408 KB |
20.txt | AC | 128 ms | 1280 KB |
21.txt | AC | 1213 ms | 9216 KB |
22.txt | AC | 1215 ms | 9088 KB |
23.txt | AC | 1213 ms | 9088 KB |
24.txt | AC | 1206 ms | 9088 KB |
25.txt | AC | 1221 ms | 9088 KB |
26.txt | AC | 1213 ms | 9088 KB |
27.txt | AC | 218 ms | 12928 KB |
28.txt | AC | 18 ms | 1280 KB |
29.txt | AC | 31 ms | 1280 KB |
30.txt | AC | 49 ms | 1280 KB |
31.txt | AC | 47 ms | 1408 KB |
32.txt | AC | 47 ms | 1280 KB |
33.txt | AC | 5 ms | 512 KB |
34.txt | AC | 123 ms | 1280 KB |
35.txt | AC | 99 ms | 1408 KB |
36.txt | AC | 5 ms | 512 KB |
37.txt | AC | 1227 ms | 5632 KB |
38.txt | AC | 1228 ms | 5632 KB |
39.txt | AC | 1223 ms | 5632 KB |
40.txt | AC | 1239 ms | 5632 KB |
41.txt | AC | 5 ms | 512 KB |
42.txt | AC | 5 ms | 512 KB |
43.txt | AC | 5 ms | 512 KB |
44.txt | AC | 5 ms | 512 KB |
45.txt | AC | 5 ms | 512 KB |
46.txt | AC | 5 ms | 512 KB |
47.txt | AC | 5 ms | 512 KB |
48.txt | AC | 5 ms | 512 KB |
s1.txt | AC | 5 ms | 512 KB |
s2.txt | AC | 5 ms | 512 KB |
s3.txt | AC | 5 ms | 512 KB |