QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#558171#858. GCD vs. XORrotcar07TL 508ms117964kbC++20610b2024-09-11 14:37:562024-09-11 14:37:56

Judging History

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

  • [2024-09-11 14:37:56]
  • 评测
  • 测评结果:TL
  • 用时:508ms
  • 内存:117964kb
  • [2024-09-11 14:37:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int maxn=1e6+5;
vector<int> d[maxn];
int mp[maxn];
inline void solve(){
    int n;cin>>n;
    unordered_set<int> s;
    for(int i=1,x;i<=n;i++) cin>>x,mp[x]++,s.insert(x);
    long long ans=0;
    for(auto x:s){
        for(auto z:d[x]){
            int w=(x^z);
            if(w<maxn-5&&mp[w]&&gcd(w,x)==z) ans+=mp[x]*1ll*mp[w];
        }
    }
    cout<<ans/2<<'\n';
    for(auto x:s) mp[x]=0;
}
int main(){
    for(int i=1;i<=1e6;i++)
    for(int j=i+i;j<=1e6;j+=i) d[j].push_back(i);
    int T;cin>>T;
    while(T--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 502ms
memory: 117920kb

input:

1
4
2 3 4 3

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 508ms
memory: 117964kb

input:

20
43
128 66 452 384 400 441 232 203 228 33 284 156 128 190 197 292 388 31 179 343 147 206 450 284 180 73 273 130 168 250 405 203 235 340 309 28 267 395 152 191 295 463 344
54
48 7 12 37 49 24 5 18 15 37 26 57 53 59 22 10 2 16 36 52 64 1 56 42 38 46 53 7 2 8 60 38 54 11 19 50 20 61 6 50 27 5 26 3 4 ...

output:

9
54
13
7
8
34
47
11
1
102
6
5
37
1
3
8
8
348
15
0

result:

ok 20 numbers

Test #3:

score: -100
Time Limit Exceeded

input:

20
1318434
383714 853663 66866 511925 858736 184314 296349 849141 468962 414270 917939 220934 778184 984811 194692 105206 528188 310859 57152 790101 274637 529663 931099 79533 179471 539390 210762 400829 514992 127623 369248 168711 380204 767781 753089 645551 714964 101060 340524 937457 928656 65201...

output:

3032045
3638993
2800795
2440602
4854505
3744477
2051987
2014444
1784403
4514139
3348716
2455323
2051402

result: