50pts,判无解错误,求调
查看原帖
50pts,判无解错误,求调
987524
lhy_cpp楼主2024/8/15 17:24
#include<bits/stdc++.h>
#define wcis puts("man!!!\n")
#define int long long
using namespace std;
int t,mod,ln;
int fpow(int x,int y){
	long long res=1;
	while(y){
		if(y&1)res=res*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return res;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t>>mod;
	while(t--){
		long long a,b;
		cin>>a>>b;
		int c=a-2*b;
		if(bool(c&b)||c<0||a==0){
			cout<<0<<endl;
			continue;
		}
		for(int i=60;i>=0;i--){
			if(c&(1ll<<i)){
				cout<<((1ll<<i)%mod*(fpow(2,((__builtin_popcountll(c))-1ll)%mod)%mod))%mod<<endl;
				break;
			}
		}
	}
	return 0;
}

2024/8/15 17:24
加载中...