QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#634120#7735. Primitive RootYurily#WA 1ms3700kbC++20815b2024-10-12 16:44:122024-10-12 16:44:14

Judging History

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

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

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+1;
	long long r=(ed-1)/p+1;
	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=(__int128)st+(1ll<<i)-1;//cout<<st<<" "<<ed<<endl;
			ans+=calc(st,ed);
			if((1ll<<i)&p){
				st-=((1ll)<<i); 
			} 
			else
				st+=((1ll)<<i);
			cout<<ans<<endl; 
		}
		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: 3700kb

input:

3
2 0
7 11
1145141 998244353

output:

1
1
2
2
2
469
704
821
850
865
872
872
872

result:

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