QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#787795#6512. Completely Multiplicative FunctionOIer_kzc#WA 24ms10744kbC++201.3kb2024-11-27 14:39:242024-11-27 14:39:25

Judging History

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

  • [2024-11-27 14:39:25]
  • 评测
  • 测评结果:WA
  • 用时:24ms
  • 内存:10744kb
  • [2024-11-27 14:39:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int prime[100005],to[1000005],f[1000005];
bool no[1000005];
using ll=long long;
#define endl '\n'
int main(){
    int t;cin>>t;
    no[1]=1;
    int cnt=0;
    for(int i=2;i<1000001;i++){
        if(!no[i]) prime[++cnt]=i;
        for(int j=1;j<=cnt&&prime[j]*i<1000001;j++){
            no[i*prime[j]]=1,to[i*prime[j]]=prime[j];
            if(!(i%prime[j])) break;
        }
    }
    f[1]=1;
    while(t--){
        int n,k;cin>>n>>k;
        if((n^k)&1){
            cout<<"-1\n";continue;
        }
        if(n==18&&!k){
            cout<<"1 1 -1 1 1 -1 -1 1 1 1 -1 -1 -1 -1 -1 1 -1 1\n";
            continue;
        }
        k=n-k>>1;
        for(int i=1;i<=cnt&&prime[i]<=n;i++) if(2ll*prime[i]*prime[i]>n&&k>=n/prime[i]-((ll)prime[i]*prime[i]<=n)){
            k-=n/prime[i]-((ll)prime[i]*prime[i]<=n),f[prime[i]]=-1;
        }
        else f[prime[i]]=1;
        for(int i=4;i<=n;i++) if(no[i]) f[i]=f[i/to[i]]*f[to[i]];
        for(int i=1;i<=n;i++) cout<<f[i]<<' ';
        cout<<endl;
    }
    /*
    for(int n=1;n<1000001;n++){
        int ans=0;
        for(int i=1;i<=cnt&&prime[i]<=n;i++) if((ll)prime[i]*prime[i]*2>n) ans+=min(prime[i]-1,n/prime[i]);
        if(ans<n/2) cout<<n<<' '<<ans<<endl;
    }
    */
}

详细

Test #1:

score: 100
Accepted
time: 6ms
memory: 10744kb

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:

ok ok (4 test cases)

Test #2:

score: -100
Wrong Answer
time: 24ms
memory: 9888kb

input:

11475
1 0
1 1
2 0
2 1
2 2
3 0
3 1
3 2
3 3
4 0
4 1
4 2
4 3
4 4
5 0
5 1
5 2
5 3
5 4
5 5
6 0
6 1
6 2
6 3
6 4
6 5
6 6
7 0
7 1
7 2
7 3
7 4
7 5
7 6
7 7
8 0
8 1
8 2
8 3
8 4
8 5
8 6
8 7
8 8
9 0
9 1
9 2
9 3
9 4
9 5
9 6
9 7
9 8
9 9
10 0
10 1
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
10 10
11 0
11 1
11 2
11 3
11...

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
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 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
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 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 121)