We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<bits/stdc++.h>#define LL long long#define M 1000000007usingnamespacestd;intq,n,f[8200]={0};LLdp[1005][8200]={0},cnt[1005]={0};vector<int>P;voidmakePrime(){f[0]=f[1]=1;for(inti=2;i*i<8200;i++){if(!f[i]){for(intj=i+i;j<8200;j+=i)f[j]=1;}}for(inti=2;i<8200;i++)if(!f[i])P.push_back(i);}intmain(){cin>>q;makePrime();while(q--){cin>>n;memset(cnt,0,sizeof(cnt));memset(dp,0,sizeof(dp));for(inti=0,x;i<n;i++)cin>>x,cnt[x-3500]++;dp[0][3500]=(cnt[0]+1)/2;dp[0][0]=(cnt[0]+2)/2;for(inti=1;i<1005;i++){for(intj=0;j<8200;j++){dp[i][j]=(dp[i-1][j]*((cnt[i]+2)/2)+dp[i-1][j^(i+3500)]*((cnt[i]+1)/2))%M;}}LLans=0;for(intp:P){(ans+=dp[1004][p])%=M;}cout<<ans%M<<endl;}return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Prime XOR
You are viewing a single comment's thread. Return to all comments →
Finally AC...this is my attempt written in C++14