QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#633992#7735. Primitive RootYurily#WA 1ms3636kbC++20754b2024-10-12 16:31:442024-10-12 16:31:51

Judging History

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

  • [2024-10-12 16:31:51]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3636kb
  • [2024-10-12 16:31:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
long long p,m;
long long calc(long long st,long long ed){
	if(ed<st)
		return 0;
	long long l;
	if(st-2<=0)
		l=0;
	else
		l=(st-2)/p;
	long long r=(ed-1)/p;
	return r-l;
}
void solve(){
	cin>>p>>m;
	if(m==0){
		if(p==2){
			cout<<1<<endl;
		}
		else
			cout<<0<<endl;
		return;
	}
	long long ans=0,st=0,ed;
	for(int i=62;i>=0;--i){
		if((1ll<<i)&m){
			if((1ll<<i)&p){
				st+=((1ll)<<i); 
			}
			ed=st+((1ll)<<i)-1;
			ans+=calc(st,ed);
			if((1ll<<i)&p){
				st-=((1ll)<<i); 
			} 
			else
				st+=((1ll)<<i);
		}
		else{
			if((1ll<<i)&p){
				st+=((1ll)<<i); 
			} 
		}
	}
	cout<<ans<<endl;
}
int main(){
	int T;
	cin>>T;
	while(T--){
		solve();
	} 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3636kb

input:

3
2 0
7 11
1145141 998244353

output:

1
1
871

result:

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