QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#376587#6512. Completely Multiplicative Functionforget-star#WA 8ms9932kbC++142.1kb2024-04-04 13:26:152024-04-04 13:26:15

Judging History

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

  • [2024-04-04 13:26:15]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:9932kb
  • [2024-04-04 13:26:15]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<bitset>
#include<deque>
#include<stack>
#include<unordered_map>
#include<ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int N=1e6+10;
int n,k,vis[N],pri[N],c,f[N];
int main()
{
	for(int i=2;i<=1000000;i++)
		if(!vis[i])
		{
			pri[++c]=i;
			for(int j=i;j<=1000000;j+=i) vis[j]=1;
		}
	int T;scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d",&n,&k);
		if((n+k)&1){printf("-1\n");continue;}
		if(n<=300)
		{
			int o=0;
			for(int i=1;i<=c;i++)
				if(pri[i]*pri[i]<=n) o=i;
				else break;
			bool check=0;
			for(int s=0;s<(1<<o)&&!check;s++)
			{
				for(int i=1;i<=n;i++) f[i]=0;f[1]=1;
				for(int i=0;i<o;i++)
					if((s>>i)&1) f[pri[i+1]]=1;
					else f[pri[i+1]]=-1;
				for(int i=1;i<=o;i++)
					for(int j=2*pri[i];j<=n;j+=pri[i])
						if(f[j/pri[i]]!=0) f[j]=f[j/pri[i]]*f[pri[i]];
				int tot=0;
				for(int i=1;i<=n;i++) tot+=f[i]==1;
				int m=(n+k)/2;
				for(int i=1;i<=c&&pri[i]<=n;i++)
					if(1ll*pri[i]*pri[i]>n)
						if(tot<=m)
						{
							tot+=(n/pri[i]);
							for(int j=pri[i];j<=n;j+=pri[i]) f[j]=1;
						}
						else
						{
							tot-=(n/pri[i]);
							for(int j=pri[i];j<=n;j+=pri[i]) f[j]=-1;
						}
				if(tot==m)
				{
					check=1;
					for(int i=1;i<=n;i++) printf("%d ",f[i]);
					printf("\n");
				}
			}
			if(!check) printf("-1\n");
			continue;
		}
		for(int i=1;i<=n;i++) f[i]=0;
		int m=(n+k)/2,tot=n;
		for(int i=1;i<=c&&pri[i]<=n;i++)
			if(1ll*pri[i]*pri[i]>n)
				tot-=(n/pri[i]);
		for(int i=1;i<=c&&pri[i]<=n;i++)
			if(1ll*pri[i]*pri[i]>n)
				if(tot<=m)
				{
					tot+=(n/pri[i]);
					for(int j=pri[i];j<=n;j+=pri[i]) f[j]=1;
				}
				else
				{
					tot-=(n/pri[i]);
					for(int j=pri[i];j<=n;j+=pri[i]) f[j]=-1;
				}
		if(tot==m)
		{
			for(int i=1;i<=n;i++)
				printf("%d ",f[i]==-1?-1:1);
			printf("\n");
		}
		else printf("-1\n");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 9932kb

input:

4
4 2
10 0
10 1
10 10

output:

1 -1 1 1 
1 -1 -1 1 1 1 -1 -1 1 1 
-1
1 1 1 1 1 1 1 1 1 1 

result:

wrong answer sum of f is not k (test case 2)