QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#748039 | #9597. Grade 2 | xdz_ | WA | 0ms | 3724kb | C++14 | 940b | 2024-11-14 19:08:20 | 2024-11-14 19:08:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define endl '\n'
typedef pair<int,int> PII;
void solve(){
int n,x;
cin >>x>>n;
int zz = 1;//区间长度
while (zz < x)
zz <<= 1;//2的log2x(向上取整)次方
vector<int> s(zz + 1,0);
for(int i = 1;i <= zz;i ++){
int s1 = (__gcd((i*x)^x,x) == 1);
s[i] = s[i-1] + s1;
}
for(int i=0;i<n;i++){
int l,r;
scanf("%lld%lld",&l,&r);
int ans=0;
//先求 L 左边有几个 1;
int lans=0;
lans=(l-1)/zz*s[zz];
int ls=(l-1)%zz;
lans += s[ls];
//在求 R 左边有几个 1;
int rans=0;
rans=(r)/zz*s[zz];
int rs=(r)%zz;
rans += s[rs];
ans = rans - lans;
cout<<ans<<'\n';
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
T = 1;
// cin>>T;
while(T --){
solve();
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3724kb
input:
15 2 1 4 11 4514
output:
3906723072621868348 3906723072621868348
result:
wrong answer 1st lines differ - expected: '2', found: '3906723072621868348'