QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#744014 | #9597. Grade 2 | xdz_# | RE | 0ms | 3552kb | C++20 | 1.1kb | 2024-11-13 20:35:39 | 2024-11-13 20:35:40 |
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;
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){
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();
}
}
Details
Tip: Click on the bar to expand more detailed information
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
Runtime Error
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 ...