Submission #1776856
Source Code Expand
#include <cstdio> #include <cstring> #include <string> #include <cmath> #include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #include <vector> using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int, int> PII; typedef vector<int> VI; #define fi first #define se second #define MP make_pair ll read() { ll v = 0, f = 1; char c = getchar(); while (c < 48 || 57 < c) {if (c == '-') f = -1; c = getchar();} while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar(); return v * f; } map<ll, ll> mp; ll pr[101000], vis[101000], a[101000], b[101000], n; const ll INF = 1e12; const ll p[] = {2, 3, 5, 7, 11, 13, 17, 19, 23}; inline ll mul(ll a, ll b, ll p) { ll t = ll((double) a * b / (double) p + 0.5); t = a * b - p * t; return t < 0 ? t + p : t; } inline ll pw(ll a, ll b) { ll re = 1; while (b) { if (b & 1) re *= a; a *= a; b >>= 1; } return re; } inline ll pw(ll a, ll b, ll p) { ll re = 1; while (b) { if (b & 1) re = mul(re, a, p); a = mul(a, a, p); b >>= 1; } return re; } inline bool millerRabbin(ll n) { if (n < 29) { for (int i = 0; i < 9; i++) if (p[i] == n) return 1; return 0; } ll d = n - 1; int s = 0; while (d % 2 == 0) d /= 2, s++; for (int i = 0; i < 9; i++) { ll j = p[i]; ll t = pw(j, d, n); for (int is = 0; is < s; is++) { ll tmp = mul(t, t, n); if (tmp == 1) if (t != 1 && t != n - 1) return 0; t = tmp; } if (t != 1) return 0; } return 1; } ll num[10000]; ll rho(ll n) { ll c = rand() % (n - 1) + 1; ll p1 = 1, p2 = 1, k = 1, t = 1; for (ll i = 1; t == 1; i++) { p1 = (mul(p1, p1, n) + c) % n; if (p1 == p2) return 1; t = __gcd(abs(p1 - p2), n); if (i == k) k += k, p2 = p1; } return t; } void cal(ll n) { if (millerRabbin(n)) { num[++num[0]] = n; return ; } ll t = 1; while (t == 1) t = rho(n); cal(t); cal(n / t); } int main() { n = read(); for (int i = 2; i <= 100000; i++) { if (!vis[i]) pr[++pr[0]] = i; for (int j = 1; j <= pr[0] && i * pr[j] <= 100000; j++) { vis[i * pr[j]] = 1; if (i % pr[j] == 0) break; } } for (int i = 1; i <= n; i++) { ll u = read(); num[0] = 0; if (u > 1) cal(u); map<ll, int> t; for (int j = 1; j <= num[0]; j++) t[num[j]]++; ll p1 = 1, p2 = 1; for (map<ll, int> :: iterator j = t.begin(); j != t.end(); j++) { int t1 = (*j).second % 3; int t2 = (3 - t1) % 3; p1 *= pw((*j).first, t1); if (pw((*j).first, t2) <= INF / p2) p2 *= pw((*j).first, t2); else p2 = INF; } a[i] = p1; b[i] = p2; if (p1 > 1) mp[p1]++; } ll ans = 0; set<ll> S; for (int i = 1; i <= n; i++) if (a[i] > 1 && !S.count(a[i]) && !S.count(b[i])) { ans += max(mp[a[i]], mp[b[i]]); S.insert(a[i]); } ll flg = 0; for (int i = 1; i <= n; i++) if (a[i] == 1) flg = 1; printf("%lld\n", ans + flg); }
Submission Info
Submission Time | |
---|---|
Task | D - Anticube |
User | Misaka10032 |
Language | C++14 (GCC 5.4.1) |
Score | 1100 |
Code Size | 3724 Byte |
Status | AC |
Exec Time | 2112 ms |
Memory | 16768 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 | 1948 ms | 13824 KB |
02.txt | AC | 1926 ms | 13824 KB |
03.txt | AC | 1937 ms | 13824 KB |
04.txt | AC | 1933 ms | 13824 KB |
05.txt | AC | 1933 ms | 13824 KB |
06.txt | AC | 1927 ms | 13824 KB |
07.txt | AC | 1937 ms | 13824 KB |
08.txt | AC | 1935 ms | 13824 KB |
09.txt | AC | 1940 ms | 13824 KB |
10.txt | AC | 1915 ms | 13824 KB |
11.txt | AC | 544 ms | 6784 KB |
12.txt | AC | 546 ms | 6784 KB |
13.txt | AC | 2092 ms | 8064 KB |
14.txt | AC | 2112 ms | 8064 KB |
15.txt | AC | 2112 ms | 8064 KB |
16.txt | AC | 2107 ms | 8064 KB |
17.txt | AC | 819 ms | 2688 KB |
18.txt | AC | 841 ms | 2688 KB |
19.txt | AC | 819 ms | 2688 KB |
20.txt | AC | 819 ms | 2688 KB |
21.txt | AC | 1383 ms | 10880 KB |
22.txt | AC | 1383 ms | 10752 KB |
23.txt | AC | 1372 ms | 10880 KB |
24.txt | AC | 1381 ms | 10752 KB |
25.txt | AC | 1397 ms | 10752 KB |
26.txt | AC | 1389 ms | 10752 KB |
27.txt | AC | 442 ms | 16768 KB |
28.txt | AC | 6 ms | 2688 KB |
29.txt | AC | 100 ms | 2688 KB |
30.txt | AC | 65 ms | 2688 KB |
31.txt | AC | 70 ms | 2688 KB |
32.txt | AC | 70 ms | 2816 KB |
33.txt | AC | 3 ms | 1152 KB |
34.txt | AC | 1237 ms | 2688 KB |
35.txt | AC | 1074 ms | 2688 KB |
36.txt | AC | 3 ms | 1152 KB |
37.txt | AC | 691 ms | 7808 KB |
38.txt | AC | 689 ms | 7808 KB |
39.txt | AC | 692 ms | 7808 KB |
40.txt | AC | 697 ms | 7808 KB |
41.txt | AC | 3 ms | 1152 KB |
42.txt | AC | 3 ms | 1152 KB |
43.txt | AC | 3 ms | 1152 KB |
44.txt | AC | 3 ms | 1152 KB |
45.txt | AC | 3 ms | 1152 KB |
46.txt | AC | 3 ms | 1152 KB |
47.txt | AC | 3 ms | 1152 KB |
48.txt | AC | 3 ms | 1152 KB |
s1.txt | AC | 3 ms | 1152 KB |
s2.txt | AC | 3 ms | 1152 KB |
s3.txt | AC | 3 ms | 1152 KB |