Codeforces Round #631 (Div. 2) D. Dreamoon Likes Sequences (位运算&组合数学)

Codeforces Round #631 (Div. 2) D. Dreamoon Likes Sequences (位运算&组合数学)

题目传送门

题意:给定d,mod,求所有满足ai在[1,d]且异或运算后bi

思路:
Codeforces Round #631 (Div. 2) D. Dreamoon Likes Sequences (位运算&组合数学)_第1张图片
Codeforces Round #631 (Div. 2) D. Dreamoon Likes Sequences (位运算&组合数学)_第2张图片

AC代码

#include
using namespace std;
typedef long long ll;
int main(){
	int t;
	cin>>t;
	while(t--){
		ll d,mod,k=1,ans=1;
		cin>>d>>mod;
		while(k<=d){
			ans=ans*(min((k<<1)-1,d)-k+2)%mod;
			k<<=1;
		}
		cout<<(ans-1+mod)%mod<<endl; 
	}
	return 0;
}

你可能感兴趣的:(数论,位运算,组合数学)