QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#427446#8747. 朔望PorNPtree#TL 0ms0kbC++201.9kb2024-06-01 13:21:102024-06-01 13:21:10

Judging History

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

  • [2024-06-01 13:21:10]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-06-01 13:21:10]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
const int N=25,M=1<<20|5,mod=1e9+7;
int n,a[N],w[N],f[M],c[N],ans,t[N],p[N][N],k[N];
inline int md(int x){return x>=mod?x-mod:x;}
inline void ad(int &x,int y){x=md(x+y);}
inline int ksm(int x,int p){int s=1;for(;p;(p&1)&&(s=1ll*s*x%mod),x=1ll*x*x%mod,p>>=1);return s;}
inline int sol(int S)
{
	basic_string<int>g,h;int s=0;
	for(int i=0;i<n;i++) if(S>>i&1) g+=i;
	for(int i:g) for(int j=1;j<=t[i];j++) h+=p[i][j];
	sort(h.begin(),h.end());h.erase(unique(h.begin(),h.end()),h.end());
	// for(int i:h) cout<<i<<" ";cout<<"\n";
	memset(k,0,sizeof(k));
	int m=g.size(),sz=h.size();
	for(int i=0;i<m;i++) for(int j=0;j<i;j++)
	{
		int I=a[g[i]],J=a[g[j]];
		LL U=abs(I-J),V=(LL)I*J,d=__gcd(U,V);
		U/=d,V/=d;
		s=__gcd(s,(int)U);
		for(int j=0;j<sz;j++){int c=0;while(V%h[j]==0) V/=h[j],c++;k[j]=max(k[j],c);}
	}
	s=2ll*s%mod;
	for(int i=0;i<sz;i++) s=1ll*s*ksm(h[i],mod-1-k[i])%mod;
	return s;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++)
	{
		int k=a[i];
		for(int j=2;j*j<=k;j++) if(k%j==0)
		{
			p[i][++t[i]]=j;
			while(k%j==0) k/=j;
		}if(k>1) p[i][++t[i]]=k;
	}
	for(int i=2;i<=n;i++) cin>>w[i];
	for(int i=0;i<(1<<n);i++) if(__builtin_popcount(i)>=2) f[i]=sol(i);

	for(int i=0;i<(1<<n);i++) f[i]=__builtin_parity(i)?mod-f[i]:f[i];
	for(int i=0;i<n;i++) for(int j=0;j<(1<<n);j++) if(j>>i&1^1) ad(f[j],f[j+(1<<i)]);
	for(int i=0;i<(1<<n);i++) f[i]=__builtin_parity(i)?mod-f[i]:f[i];


	// for(int i=0;i<(1<<n);i++) cout<<f[i]<<" ";cout<<"\n";
	for(int i=0;i<(1<<n);i++) ad(c[__builtin_popcount(i)],f[i]);
	// cout<<c[2]<<"\n";
	// cout<<(400ll*ksm(24,mod-2)%mod);
	for(int i=2;i<=n;i++) ans=(ans+1ll*c[i]*w[i])%mod;
	return cout<<ans,0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

20
73415948 190825288 205086969 242726140 280691039 291234110 341933576 379938879 399631744 420807939 421811250 486105558 605031352 645495854 714594262 775221445 793534057 818237037 926135349 940293639
108200337 125078426 163639475 261733041 280562529 287327830 310288774 415301468 419144734 46329977...

output:


result: