1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| #include<bits/stdc++.h> #define x first #define y second #define ok cout << "ok" << endl; using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const double PI = acos(-1.0); const int INF=0x3f3f3f3f; const ll LINF=0x3f3f3f3f3f3f3f3f; const int N=1e5+9; const int shift=1e3+9; const double Eps=1e-7;
vi pri; int n, a[N], ans[N];
void pre() { int up = 10000; bool vis[N]; memset(vis, 0, sizeof vis); for(int i = 2; i <= up; i++) if(!vis[i]) for(int j = 2 * i; j <= up; j += i) vis[j] = 1; for(int i = 2; i <= up; i++) if(!vis[i]) pri.push_back(i); }
int fac(int d) { if(d == 0) return d; int ans = 1; if(d < 0) ans *= -1, d *= -1; int p = 0; while(d != 1 && p < pri.size()) { int cnt = 0; while(d % pri[p] == 0) cnt++, d /= pri[p]; if(cnt & 1) ans *= pri[p]; p++; } if(d != 1) ans *= d;
return ans; }
void lisanhua() { set<int> se; map<int, int> m; for(int i = 0; i < n; i++) se.insert(a[i]); int cnt = 1; for(auto i: se) { if(i == 0) m[i] = 0; else m[i] = cnt++; } for(int i = 0; i < n; i++) a[i] = m[a[i]]; }
int main(void) { if(fopen("in", "r")!=NULL) {freopen("in", "r", stdin); freopen("out", "w", stdout);} pre(); while(cin >> n) { for(int i = 0; i < n; i++) { scanf("%d", a + i); a[i] = fac(a[i]); } memset(ans, 0, sizeof ans); lisanhua(); for(int i = 0; i < n; i++) { int cnt = 0, zeroFlag = 0, b[N]; memset(b, 0, sizeof b); for(int j = i; j < n; j++) { if(a[j] == 0) zeroFlag = 1; if(b[a[j]]++ == 0) cnt++; if(zeroFlag && cnt != 1) ans[cnt-1]++; else ans[cnt]++; } } for(int i = 1; i <= n; i++) printf("%d%c", ans[i], i == n ? '\n': ' '); }
return 0; }
|