日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Dreamoon Likes Sequences CodeForces - 1330D(组合数学+位运算)

發(fā)布時間:2023/12/15 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Dreamoon Likes Sequences CodeForces - 1330D(组合数学+位运算) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Dreamoon likes sequences very much. So he created a problem about the sequence that you can’t find in OEIS:

You are given two integers d,m, find the number of arrays a, satisfying the following constraints:

The length of a is n, n≥1
1≤a1<a2<?<an≤d
Define an array b of length n as follows: b1=a1, ?i>1,bi=bi?1⊕ai, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b1<b2<?<bn?1<bn should hold.
Since the number of possible arrays may be too large, you need to find the answer modulo m.

Input
The first line contains an integer t (1≤t≤100) denoting the number of test cases in the input.

Each of the next t lines contains two integers d,m (1≤d,m≤109).

Note that m is not necessary the prime!

Output
For each test case, print the number of arrays a, satisfying all given constrains, modulo m.

Example
Input
10
1 1000000000
2 999999999
3 99999998
4 9999997
5 999996
6 99995
7 9994
8 993
9 92
10 1
Output
1
3
5
11
17
23
29
59
89
0
題意:
給出一個限制 d 與模數(shù) mod ,求出可以構(gòu)造出的滿足條件的數(shù)組 a 的個數(shù),需要滿足以下條件:
①數(shù)組 a 的長度大于等于 1
②數(shù)組 a 嚴格遞增
③數(shù)組 a 的最小值大于等于 1 ,數(shù)組 a 的最大值小于等于 d
對于數(shù)組 a ,構(gòu)造出一個數(shù)組 b :
i == 1 時:b[ 1 ] = a[ 1 ]
i > 1 時:b[ i ] = b[ i - 1 ] ^ a[ i ]
數(shù)組 b 嚴格遞增。
思路:牽扯到異或,我們就要考慮位運算了。對于a數(shù)組的每一個數(shù),如果它選擇了2,那么它接下來就沒有辦法選擇3;如果它選擇了4,那么它接下來就沒有辦法選擇5,6,7;如果它選擇了8,那么它接下來就沒有辦法選擇9,10,11,12,13,14,15.換句話說,最高位為i的數(shù)字只能出現(xiàn)一次。那么第i位可以選擇的數(shù)量為,但是第i位還有可能不加,也就是在原來基礎(chǔ)上加1.然后累乘就可以了。最后結(jié)果要減一,這代表的是所有位都沒有選擇數(shù)的情況。
代碼如下:

#include<bits/stdc++.h> #define ll long long using namespace std;int n,mod;int main() {int t;scanf("%d",&t);while(t--){scanf("%d%d",&n,&mod);ll ans=1;for(int i=0;i<30;i++){if((1<<i)>n) break;ans=(ans*(min((1<<(i+1))-1,n)-(1<<i)+2));ans%=mod;}ans=(ans-1+mod)%mod;cout<<ans<<endl;}return 0; }

努力加油a啊,(o)/~

總結(jié)

以上是生活随笔為你收集整理的Dreamoon Likes Sequences CodeForces - 1330D(组合数学+位运算)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。