码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5344 简单题

时间:2015-08-04 20:41:19      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:

很显然,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\n", 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 }

 

hdu 5344 简单题

标签:

原文地址:http://www.cnblogs.com/huoxiayu/p/4702861.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!