QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#547709 | #6512. Completely Multiplicative Function | rotcar07 | WA | 0ms | 5664kb | C++14 | 650b | 2024-09-05 08:06:15 | 2024-09-05 08:06:16 |
Judging History
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)