hdu 5344 简单题

很显然,i和j不同时,A[i]+A[j]会被异或两次,也就是没有异或。所以只要把每个数的二倍异或一遍(或者异或一遍最后乘2)就可以得到答案。

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 using namespace std;
 5 
 6 typedef long long ll;
 7 int n, m, z, l;
 8 
 9 void init()
10 {
11     int pre = 0, ans = 0;
12     for ( int i = 1; i < n; i++ )
13     {
14         pre = ( ( ll ) pre * m + z ) % l;
15         ans = ans ^ pre;
16     }
17     ans <<= 1;
18     printf("%d
", ans);
19 }
20 
21 int main ()
22 {
23     int t;
24     scanf("%d", &t);
25     while ( t-- )
26     {
27         scanf("%d%d%d%d", &n, &m, &z, &l);
28         init();
29     }
30     return 0;
31 }
原文地址:https://www.cnblogs.com/huoxiayu/p/4702861.html