QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#744145 | #9597. Grade 2 | xdz_# | WA | 20ms | 3640kb | C++20 | 1.3kb | 2024-11-13 20:59:33 | 2024-11-13 20:59:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
int gcd(int a,int b){
return b ? gcd(b,a % b) : a;
}
void solve(){
int x,n;
cin >>x>>n;
for(int i = 2;i <= x + 10;i ++){
int z = (i * x) ^ x;
int z1 = gcd(z,x);
if(z1 == x){
x = i - 1;
break;
}
}
vector<int> s(x + 2);
for(int i = 1;i <= x + 1;i ++){
int z = (i * x) ^ x;
int z1 = gcd(z,x);
if(z1 == 1){
s[i] = s[i - 1] + 1;
}
else s[i] = s[i - 1];
}
for(int i = 1;i <= n;i ++){
int l,r;
cin >>l>>r;
int sum = 0;
if(l == r){
l = (l % (x + 1));
if(l == 0)cout<<s[(x + 1)] - s[x]<<'\n';
else cout<<s[l] - s[l - 1]<<'\n';
continue;
}
if(l % (x + 1) == 0){
l ++;
sum += s[x + 1] - s[x];
}
if(r <= l + ((x + 1) - (l % (x + 1)))){
if(r % (x + 1) != 0)cout<<s[r % (x + 1)] - s[(l % (x + 1)) - 1]<<'\n';
else cout<<s[x + 1] - s[(l % (x + 1)) - 1]<<'\n';
continue;
}
int z = l % (x + 1);
int z1 = r % (x + 1);
r -= r % (x + 1);
l += ((x + 1) - (l % (x + 1)));
sum = ((r - l) / (x + 1)) * s[x + 1];
sum += s[(x + 1)] - s[z - 1];
sum += s[z1] - s[0];
cout<<sum<<'\n';
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
T = 1;
while(T --){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
input:
15 2 1 4 11 4514
output:
2 2252
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 20ms
memory: 3640kb
input:
500696 100000 110442401300 646889080214 337192 670162015551 508011001649 508011014425 94418501628 94418501634 824168677375 824168677376 732815842309 795402573302 353241304050 846773277757 622033633276 622033633284 760381702139 760381702143 207714 795408271057 382792 952061527685 686173 331215904334 ...
output:
536047537041 669663046158 12769 7 2 62540163486 493164762418 9 5 794816241868 951352766066 330968778268 8 25744 326617718276 3 56488 964815023936 853625736538 913283336225 552895432371 968013286248 286499183685 149771 5 20510649065 472808015393 8 352398 25771 4 337300751232 688574522968 11569 11 672...
result:
wrong answer 1st lines differ - expected: '0', found: '536047537041'