S a m p l e I n p u t Sample Input SampleInput
10 1 10000000
7 9 9 4 0 0 8 8 4 7
S a m p l e O u t p u t Sample Output SampleOutput
251
说明
1
≤
n
,
p
≤
1
0
5
1 \le n, p \le 10^{5}
1≤n,p≤105
0
≤
b
,
d
i
r
t
y
i
≤
1
0
7
0 \le b, dirty_{i} \le 10^{7}
0≤b,dirtyi≤107
思路
我们先对每一次操作做分析
&:
d
i
r
t
y
i
dirty_{i}
dirtyi:0
那么做下一次与运算时,结果都是0
d
i
r
t
y
i
dirty_{i}
dirtyi:1
那么做下一次与运算是,结果要么1要么0,也就是要么更小要么不变
|:
d
i
r
t
y
i
dirty_{i}
dirtyi:0
那么做下一次或运算时,结果要么1要么0,也就是要么更小要么更大
d
i
r
t
y
i
dirty_{i}
dirtyi:1
那么做下一次或运算是,结果都是1,就是不变
但是我们发现
替代还不如直接换成下一个数
所以直接求数列中最大的数就行了
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define ll long long
using namespace std;
ll Maxx ,n ,b ,p ,k;
ll Counting(ll n, ll b, ll p)//快速幂
{
ll Ans = 1;
n %= p;
while(b)
{
if(b & 1) Ans = Ans * n % p;
n = n * n % p;
b >>= 1;
}
return Ans % p;
}
int main()
{
scanf("%lld%lld%lld" ,&n ,&b ,&p);
for(int i = 1; i <= n; ++i)
{
scanf("%lld" ,&k);
Maxx = max(Maxx, k);
}
Maxx *= 2;
printf("%lld" ,Counting(Maxx + 233 ,b ,p));
return 0;
}