QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#748092#9597. Grade 2xdz_WA 0ms3680kbC++141.1kb2024-11-14 19:18:132024-11-14 19:18:14

Judging History

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

  • [2024-11-14 19:18:14]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3680kb
  • [2024-11-14 19:18:13]
  • 提交

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;
int gcd(int a,int b){
	return a == 0 ? b : gcd(b % a, a);
}
void solve(){
	int n,x;
	cin >>x>>n; 
	int inter = 1;//区间长度
	while (inter < x)
		inter <<= 1;//2的log2x(向上取整)次方
	vector<int> sum(inter + 1);
	for(int i = 1;i <= inter;i ++){
		int z = (i * x) ^ x;
		int z1 = gcd(z,x);
		if(z1 == 1){
			sum[i] = sum[i - 1] + 1;
		}
		else sum[i] = sum[i - 1];
	}
	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)/inter*sum[inter];
		int ls=(l-1)%inter;
		lans += sum[ls];
		
		//在求 R 左边有几个 1;
		int rans=0;
		rans=(r)/inter*sum[inter];
		int rs=(r)%inter;
		rans += sum[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();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3680kb

input:

15 2
1 4
11 4514

output:

3906723112781845820
3906723112781845820

result:

wrong answer 1st lines differ - expected: '2', found: '3906723112781845820'