https://codeforces.com/problemset/problem/895/C
线性基待补。
思路:将质因子状态集合状压,0表示此时次数为偶数,1表示次数次数为奇数。
对于当前s,奇数时候其分解的质因子要和s异或得之前的状态。偶数直接沿用。
对于某个数字出现的次数k,我们考虑取C(1,K)+C(3,K)+----=2^(K-1).偶数同理。
最后注意,卡时间,预处理幂次。卡空间。改成滚动。
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=100;
typedef long long LL;
const LL mod=1e9+7;
inline LL read(){LL x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn],cnt[maxn];
LL dp[2][1<<(20)];
LL primes[maxn]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67};
LL p[200000];
LL solve(LL num,LL re){
for(LL i=0;i<19;i++){
while(num>1&&(num%primes[i]==0)){
re^=(1<<i);
num/=primes[i];
}
}
return re;
}
int main(void){
p[0]=1;
for(LL i=1;i<200000-10;i++) p[i]=p[i-1]*2%mod;
LL n;n=read();
for(LL i=1;i<=n;i++){
LL x;x=read();cnt[x]++;
}
dp[0][0]=1;
LL bol=0;LL ans=0;
for(LL i=1;i<=70;i++){
if(!cnt[i]){
for(LL s=0;s<p[19];s++) dp[i&1][s]=dp[(i&1)^1][s];
continue;///压维后直接继承过去
}
/// bol^=1;
LL chan=solve(i,0);
for(LL s=0;s<p[19];s++){
LL pre=chan^s;
///当前取奇数个
dp[i&1][s]=(dp[i&1][s]%mod+p[cnt[i]-1]%mod*dp[(i&1)^1][pre]%mod)%mod;
///当前取偶数个
dp[i&1][s]=(dp[i&1][s]%mod+p[cnt[i]-1]%mod*dp[(i&1)^1][s]%mod)%mod;
///dp[bol][s]=(((dp[bol^1][pre]%mod+dp[bol^1][s]%mod)%mod)*p[cnt[i]-1]%mod)%mod;
}
for(LL s=0;s<p[19];s++){
dp[(i&1)^1][s]=0;
}
ans=dp[i&1][0]%mod;
}
printf("%lld\n",(ans-1)%mod);
return 0;
}