2 条题解

  • 1
    @ 2026-8-11 10:24:05
    #include <bits/stdc++.h>
    using namespace std;
    int n, a[100005], b[35], prexor;
    long long ans, cnt[1 << 10];
    vector <int> prime = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
    void read(int &a, int ch = 0) {
    	while (!isdigit(ch = getchar()));
    	for (a = 0; isdigit(ch); ch = getchar()) a = (a << 3) + (a << 1) + (ch ^ 48);
    }
    void prework() {
    	for (int i = 1; i <= 30; i++) {
    		int j = i;
    		for (int k = 0; k < 10; k++) {
    			while (j % prime[k] == 0) {
    				b[i] ^= 1 << k;
    				j /= prime[k];
    			}
    		}
    	}
    }
    int main() {
    	prework();
    	read(n);
    	cnt[0] = 1;
    	for (int i = 1; i <= n; i++) {
    		read(a[i]);
    		prexor ^= b[a[i]];
    		ans += cnt[prexor]++;
    	}
    	cout << ans;
    	return 0;
    }
    
    
    • 0
      @ 2026-8-11 10:25:13

      这是我的代码,希望大家多多参考

      • 1

      信息

      ID
      532
      时间
      1000ms
      内存
      256MiB
      难度
      5
      标签
      递交数
      71
      已通过
      27
      上传者