You are viewing a single comment's thread. Return to all comments →
C++ solution
int primeXor(vector<int> a) { const int MOD = 1000000007, MAX_XOR = 8192, MIN_VALUE = 3500, MAX_VALUE = 4500; int valueCount[MAX_VALUE - MIN_VALUE + 1], xorCount[MAX_XOR], delta[MAX_XOR]; int i = 0, j = 0; memset(valueCount, 0, sizeof(valueCount)); memset(xorCount, 0, sizeof(xorCount)); for (auto v : a) valueCount[v - MIN_VALUE]++; xorCount[0] = 1; for (int v = MIN_VALUE, vi = 0; v <= MAX_VALUE; v++, vi++) { if (!valueCount[vi]) continue; memset(delta, 0, sizeof(delta)); int odd = (valueCount[vi] + 1) / 2; int even = valueCount[vi] / 2; for (i = 0; i < MAX_XOR; i++) { if(odd) delta[i ^ v] = (delta[i^v] + int64_t(xorCount[i]) * odd) % MOD; if(even) delta[i] = (delta[i] + int64_t(xorCount[i]) * even) % MOD; } for(i = 0; i < MAX_XOR; i++) if(delta[i]) xorCount[i] = (xorCount[i] + delta[i]) % MOD; } int result = 0; vector<int> numbers(MAX_XOR); for (i = 2; i < MAX_XOR; i++) for (j = i * i; j < MAX_XOR; j += i) numbers[j] = 1; for (i = 2; i < MAX_XOR; i++) if (!numbers[i] && xorCount[i]) result = (result + xorCount[i]) % MOD; return result; }
Seems like cookies are disabled on this browser, please enable them to open this website
Prime XOR
You are viewing a single comment's thread. Return to all comments →
C++ solution