QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#265180 | #7679. Master of Both IV | qkm66666# | WA | 38ms | 24456kb | C++14 | 2.8kb | 2023-11-25 17:07:33 | 2023-11-25 17:07:34 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
const int maxn=4e5,mod=998244353;
int T,n;
int a[maxn],Cnt[maxn],cnt[maxn];
int base[maxn][30],siz[maxn];
long long po[maxn],fac[maxn],inv[maxn],Ans;
long long tot,p[maxn];
long long qpow(long long x,int n){
long long ret=1;
while(n){
if(n&1){ret=ret*x%mod;}
x=x*x%mod;
n>>=1;
}
return ret;
}
void Add(int num,int x){
for(int i=20;i>=0;i--){
if(x&(1<<i)){
if(base[num][i]){
x^=base[num][i];
}
else{
siz[num]++;
base[num][i]=x;
return;
}
}
}
return;
}
void Merge(int a,int b,int c){//a,b合并到c
if(siz[a]<siz[b]) swap(a,b);
siz[0]=siz[a];
for(int i=0;i<=20;i++){
base[0][i]=base[a][i];
}
for(int i=0;i<=20;i++){
if(base[b][i]){
Add(0,base[b][i]);
}
}
siz[c]=siz[0];
for(int i=0;i<=20;i++){
base[c][i]=base[0][i];
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
po[0]=1;
for(int i=1;i<=200000;i++){
po[i]=po[i-1]*2%mod;
}
fac[0]=1;
for(int i=1;i<=200000;i++){
fac[i]=fac[i-1]*i%mod;
}
inv[200000]=qpow(fac[200000],mod-2);
for(int i=200000;i>=1;i--){
inv[i-1]=inv[i]*i%mod;
}
tot=0;
for(int i=2;i<=200000;i++){
bool flag=true;
for(int j=1;j<=tot;j++){
if(i%p[j]==0) flag=false;
if(p[j]*p[j]>i) break;
}
if(flag){
p[++tot]=i;
}
}
cin>>T;
while(T--){
cin>>n;
for(int i=1;i<=n;i++){
cnt[i]=0;
Cnt[i]=0;
siz[i]=0;
for(int j=0;j<=20;j++){
base[i][j]=0;
}
}
siz[0]=0;
for(int i=0;i<=20;i++){
base[0][i]=0;
}
for(int i=1;i<=n;i++){
cin>>a[i];
cnt[a[i]]++;
Add(0,a[i]);
}
Ans=(po[n-siz[0]]-1);
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j+=i){
Cnt[j]+=cnt[i];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=tot;j++){
if(i%p[j]==0){
Merge(i,i/j,i);
}
if(p[j]>=i) break;
}
long long C=0;
for(int j=1;j<=cnt[i];j+=2){
C=(C+fac[cnt[i]]*inv[j]%mod*inv[cnt[i]-j]%mod)%mod;
}
Ans=(Ans+1ll*C*po[Cnt[i]-cnt[i]-siz[i]])%mod;
if(cnt[i]){
Add(i,i);
}
}
printf("%lld\n",Ans);
}
//system("pause");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 38ms
memory: 24456kb
input:
2 3 1 2 3 5 3 3 5 1 1
output:
5 11
result:
wrong answer 1st numbers differ - expected: '4', found: '5'