传送门

题目:

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.

思路:容易想到如果两个数二进制的最高位都是1,则两者"^"后者数值一定比前者小,可以推断出"2^0 ~ 2^1 - 1","2^1 ~ 2^2 - 1",...,"2^(n-1) ~ 2^(n) - 1"为不同集合,我们只需要统计出每个集合的个数,然后求出组合方案数就行。

 #include<iostream>
#include<string>
#include<vector>
#include<cstdio> #define ll long long
#define pb push_back using namespace std; const int N = 1e6 + ;
vector<ll > a;
ll p[N];
ll ans, MOD; void init()
{
int x = ;
while(){
p[x] = ( << x) - ;
if(p[x] > 1e9) break;
x++;
}
} void solve()
{ init(); int T;
cin >> T;
while(T--){ ans = ;
a.clear(); ll n;
cin >> n >> MOD; int inx = -;
for(int i = ; i < ; ++i){
if(n >= p[i]) a.pb(p[i] - p[i - ]);
else{
inx = i;
break;
}
} if(n - p[inx - ] > ) a.pb(n - p[inx - ]);
for(auto x : a){
ans = (ans * (x + )) % MOD;
} ans = (ans - + MOD) % MOD; //cout << "(ans = " << ans << ")" << endl;
cout << ans << endl;
}
} int main() { ios::sync_with_stdio(false);
cin.tie();
cout.tie();
solve();
//cout << "ok" << endl;
return ;
}

最新文章

  1. Allegro之Enhance pad Entry(增强焊盘进入约束功能)的使用
  2. SQL Server 聚合函数算法优化技巧
  3. 展讯camera去除尺寸相关缓存
  4. UNIX环境高级编程笔记之标准I/O库
  5. 第二百七十九天 how can I 坚持
  6. Cocos2d-x实例:单点触摸事件
  7. MySQL - 启停服务
  8. php框架练习
  9. 动态规划---最长上升子序列问题(O(nlogn),O(n^2))
  10. zoj 2402 - Lenny&amp;#39;s Lucky Lotto Lists
  11. 记一次 bug 修复 , 未将对象引用实例化
  12. 引导加载程序之争: LILO 和 GRUB
  13. 初级Django学习
  14. Windows 7无声音的解决方案
  15. table增删改查操作--jq
  16. Map的嵌套使用
  17. javascript简单的选项卡
  18. eclipse下查看java源码设置
  19. ArduinoYun教程之Arduino编程环境搭建
  20. 用UIInterpolatingMotionEffect产生透视效果

热门文章

  1. Monster Audio 使用教程 (七) 防止声音过大,出现爆音
  2. Centos 安装ixgbe驱动
  3. 在Linux系统中使用Vim读写远程文件
  4. 学习python的几个资料网站
  5. 美团Leaf——全局序列生成器
  6. PHP XML DOM:DOM 是什么?
  7. Python os.getcwdu() 方法
  8. Python 字典(Dictionary) type()方法
  9. Dynamics 2016 启用Bing Maps
  10. 深入探究JVM之类加载与双亲委派机制