QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#547709#6512. Completely Multiplicative Functionrotcar07WA 0ms5664kbC++14650b2024-09-05 08:06:152024-09-05 08:06:16

Judging History

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

  • [2024-09-05 08:06:16]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5664kb
  • [2024-09-05 08:06:15]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int maxn=1e6+5;
int f[maxn],pr[maxn];
int main(){
    int t;cin>>t;
    while(t--){
        int n,k;cin>>n>>k;
        if((n-k)&1){cout<<"-1\n";continue;}
        for(int i=1;i<=n;i++) f[i]=1,pr[i]=0;
        int cur=n;
        for(int i=2;i<=n;i++)if(!pr[i]){
            int cnt=0;
            for(int j=i;j<=n;j+=i) cnt+=f[j],pr[j]=1;
            int now=cur-2*cnt;
            if(abs(cur-k)>abs(now-k)){
                for(int j=i;j<=n;j+=i) f[j]=-f[j];
                cur=now;
            }
        }
        for(int i=1;i<=n;i++) cout<<f[i]<<' ';cout<<'\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 5664kb

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 f[4] != f[2] * f[2] (test case 2)