QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#759346#9619. 乘积,欧拉函数,求和KOH-WA 480ms216820kbC++142.4kb2024-11-18 01:58:302024-11-18 01:58:31

Judging History

你现在查看的是最新测评结果

  • [2024-11-18 01:58:31]
  • 评测
  • 测评结果:WA
  • 用时:480ms
  • 内存:216820kb
  • [2024-11-18 01:58:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x){
	x=0;char ch=getchar();bool f=false;
	while(!isdigit(ch))	f|=ch=='-',ch=getchar();
	while(isdigit(ch))	x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	x=f?-x:x;return; 
}
template <typename T>
inline void print(T x){
	if(x<0)	putchar('-'),x=-x;
	if(x>9)	print(x/10);
	putchar(x%10^48);return;
}	
#define int long long
#define lowbit(x)	x&(-x)
const int N=2003,MOD=998244353;
const int P[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};//16
int Inc(int x,int y){x+=y;return x>=MOD?x-MOD:x;}
int Dec(int x,int y){x-=y;return x<0? x+MOD :x;}
int dp[N][(1<<16)-1],f[(1<<16)-1],mx=1;
int inv[N],pr[N];
vector<pair<int,int> > vec[N];
unordered_map<int,int> rev;
int pw[1<<15+1];
void Div(int x){
	int tmp=0,t=x;
	for(int i=0;i<16;++i){
		if(x%P[i])	continue;
		tmp|=(1<<i);
		while(x%P[i]==0)	x/=P[i];
	}
	if(x!=1){
		if(!rev.count(x))	rev[x]=++mx,pr[mx]=x;
		vec[rev[x]].push_back(make_pair(t,tmp));
	}
	else vec[1].push_back(make_pair(t,tmp));
} 
int Quick_pow(int x,int p){
	int res=1;
	while(p){
		if(p&1)	res=(res*x)%MOD;
		x=(x*x)%MOD;
		p>>=1;
	}
	return res;
}
int n;
signed main(){
	for(int i=0;i<16;++i){
		pw[1<<i]=i;
		inv[i]=(P[i]-1)*Quick_pow(P[i],MOD-2)%MOD;
	}	
	read(n);
	for(int i=1;i<=n;++i){
		int x;read(x);
		Div(x);
	}
	for(int i=1;i<=mx;++i){
		int siz=vec[i].size();
		if(i==1){	
			dp[1][0]=1;
			for(int j=0;j<siz;++j){
				int tmp=vec[i][j].second,x=vec[i][j].first;
				for(int k=(1<<16)-1;k>=0;--k){
					int t=(tmp^(tmp&k));
					int fac=1;
					while(t){
						fac=fac*inv[pw[lowbit(t)]]%MOD;
						t-=lowbit(t);
					}
					dp[1][k|tmp]=Inc(dp[1][k|tmp],dp[1][k]*fac%MOD*x%MOD);
				}
			}	
		}
		else{
			int iv=(pr[i]-1)*Quick_pow(pr[i],MOD-2)%MOD;
			for(int k=(1<<16)-1;k>=0;--k) dp[i][k]=dp[i-1][k]*iv%MOD;
			for(int j=0;j<siz;++j){
				int tmp=vec[i][j].second,x=vec[i][j].first;
				for(int k=(1<<16)-1;k>=0;--k){
					int t=(tmp^(tmp&k));
					int fac=1;
					while(t){
						fac=fac*inv[pw[lowbit(t)]]%MOD;
						t-=lowbit(t);
					}
					dp[i][k|tmp]=Inc(dp[i][k|tmp],dp[i][k]*fac%MOD*x%MOD);
				}
			}
			int iv2=Quick_pow(pr[i],MOD-2);
			for(int k=(1<<16)-1;k>=0;--k) dp[i][k]=Inc(dp[i][k],dp[i-1][k]*iv2%MOD);
		}
	}
	int ans=0;
	for(int i=0;i<(1<<16);++i)	ans=Inc(ans,dp[mx][i]);
	print(ans);
	
	return 0;
} 

/*
3
1 2 3

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 5680kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 2ms
memory: 5680kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Wrong Answer
time: 480ms
memory: 216820kb

input:

2000
79 1 1 1 1 1 1 2803 1 1 1 1 1 1 1609 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2137 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 613 1 499 1 211 1 2927 1 1 1327 1 1 1123 1 907 1 2543 1 1 1 311 2683 1 1 1 1 2963 1 1 1 641 761 1 1 1 1 1 1 1 1 1 1 1 1489 2857 1 1 1 1 1 1 1 1 1 1 1 1 1 967 1 821 1 1 1 1 2143 1861...

output:

449217761

result:

wrong answer 1st lines differ - expected: '50965652', found: '449217761'