QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#479246#4624. Shortest Path in GCD GraphmasterhuangWA 272ms95196kbC++201.2kb2024-07-15 16:07:272024-07-15 16:07:27

Judging History

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

  • [2024-07-15 16:07:27]
  • 评测
  • 测评结果:WA
  • 用时:272ms
  • 内存:95196kb
  • [2024-07-15 16:07:27]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define bp __builtin_parity
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
const int N=1e7+5,M=15,NN=1e3+5,mod=998244353;
int n,m,pr[N/10],mu[N],mn[N],t1,a[M],t2,b[M],c[NN],d[NN];bool v[N];
inline int md(int x){return x>=mod?x-mod:x;}
inline void ad(int &x,int y){x=md(x+y);}
inline void init(int M)
{
	for(int i=2;i<=M;i++)
	{
		if(!v[i]) pr[++pr[0]]=i,mn[i]=i,mu[i]=-1;
		for(int j=1;j<=pr[0]&&i*pr[j]<=M;j++)
		{
			v[i*pr[j]]=1;mn[i*pr[j]]=mn[i];
			if(i%pr[j]==0) break;mu[i*pr[j]]=-mu[i];
		}
	}
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>n>>m;init(n);
	while(m--)
	{
		int u,v;LL ans=0,t;cin>>u>>v;
		if(__gcd(u,v)==1){cout<<"1 1\n";continue;}
		ans+=__gcd(u,v)==2;u/=__gcd(u,v);t1=t2=0;
		for(int p;u^1;){p=mn[u],a[t1++]=p;while(!(u%p)) u/=p;}
		for(int p;v^1;){p=mn[v],b[t2++]=p;while(!(v%p)) v/=p;}
		c[0]=1;for(int i=1,B;i<(1<<t1);i++) B=__lg(i),c[i]=c[i-(1<<B)]*a[B];
		d[0]=1;for(int i=1,B;i<(1<<t2);i++) B=__lg(i),d[i]=d[i-(1<<B)]*b[B];
		for(int i=0,k;i<(1<<t1);i++) for(int j=0;j<(1<<t2);j++)
			t=n/(1ll*c[i]*d[j]),ans+=((bp(i)^bp(j))?-t:t);
		cout<<"2 "<<ans<<"\n";
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 272ms
memory: 95196kb

input:

10000000 50000
6063825 1688077
9748275 1717197
5067284 9994733
8895125 6988260
9446181 5378152
9460161 1794337
3393611 9297610
7525386 5806968
9608609 2225468
9808741 2596273
606784 8423027
2361246 4662937
4385583 1195254
8440346 4819524
4256844 679638
8959165 3868431
9063859 4480534
9568261 1389414...

output:

1 1
2 5240548
1 1
2 2133283
1 1
1 1
1 1
2 1935841
1 1
1 1
1 1
1 1
2 2144411
2 3333325
2 1655994
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
2 1758061
1 1
1 1
1 1
2 1794638
1 1
2 2178004
1 1
1 1
1 1
2 3075313
2 3047490
2 3392155
2 3999993
1 1
2 1572149
1 1
1 1
2 1420290
1 1
2 5121187
2 984744
1 1
1 1
1 1
1 1
1 1...

result:

wrong answer 4th lines differ - expected: '2 2666605', found: '2 2133283'