- P39's solution
P39's Solution
- 2025-9-4 21:59:23 @
正难则反:累乘积为奇数当且仅当所有参与累乘的数都是奇数。
#include <bits/stdc++.h>
using namespace std;
const int P = 1e7 + 7;
int power(int b, int k, int p)
{
if (k == 0) return 1;
if (k == 1) return b;
long long s = power(b, k >> 1, p);
s = s * s % p;
if (k & 1) s *= b;
return s % p;
}
int main()
{
ios::sync_with_stdio(0);
int n, m = 0;
cin >> n;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
if (x & 1) m++;
}
cout << (power(2, n, P) - power(2, m, P) + 1 + P) % P << endl;
return 0;
}