打个表,记录1到下标为止所有数的XOR值即可
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 using namespace std; 5 int array[1000001]; 6 int main(){ 7 int cnt, i, j, k, t, n, num; 8 int temp = 0; 9 for(k = 0 ;k <= 1000000 ; k++){ 10 temp ^= k; 11 array[k] = temp; 12 } 13 while(EOF != scanf("%d",&n)){ 14 cnt = 0; 15 for(i = 1; i <= n; i++){ 16 scanf("%d",&num); 17 cnt ^= num; 18 } 19 for(i = 1 ;i <= n; i++){ 20 int tmp_q = n / i; 21 int tmp_w = n % i; 22 while(tmp_q--){ 23 cnt ^= array[i-1]; 24 } 25 if(tmp_w) 26 cnt ^= array[tmp_w]; 27 } 28 printf("%d ",cnt); 29 } 30 return 0; 31 }