ZOJ-2996 (1+x)^n
来源:互联网 发布:炉石传说卡牌数据库 编辑:程序博客网 时间:2024/06/09 15:24
Please calculate the coefficient modulo 2 of x^i in (1+x)^n.
Input
For each case, there are two integers n, i (0<=i<=n<=2^31-1)
Output
For each case, print the coefficient modulo 2 of x^i in (1+x)^n on a single line.
Sample Input
3 14 2
Sample Output
10
题目描述:给出n和i,(1+x)^n ,让你求x^i次的系数。
题目思路:很容易想到的是二项式展开,然后求x^i的系数。求C(n,i)的奇偶性偶数输出0,奇数则输出1,由此可以简化代码。C(n,i)的奇偶性有一个性质就是如果为奇数,(n & i) == i。
题目链接:ZOJ 2996
以下是代码:
#include <vector>#include <map>#include <set>#include <algorithm>#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>#include <string>#include <cstring>using namespace std;int main(){long long n,i;while (cin >> n >> i){if ((n & i) == i)cout << 1 << endl;elsecout << 0 << endl;}return 0;}
0 0
- ZOJ 2996 (1+x)^n
- ZOJ-2996 (1+x)^n
- zoj 2996 (1+x)^n
- ZOJ 2996 (1+x)^n【模板题】【常用技巧】
- zoj 1489 2^x mod n = 1
- zoj 1489 2^x mod n = 1
- ZOJ 1489 2^x mod n = 1 数论
- zoj 1489 2^x mod n = 1
- ZOJ - 1489 2^x mod n = 1
- ZOJ 1489 HDU1395 2^x mod n = 1 数学
- zoj ——1489——2^x mod n = 1
- x^n+1~~~
- ZOJ 3175 Number of Containers(n/1+n/2+...+n/(n-1)+n/n求法)
- (((x)+(n)-1)&~((n) - 1) ) 详解!
- x^1 + x ^2 +...+x ^n = m 求x
- 1^x + 2 ^ x + 3 ^x + …… + n^x
- zoj 3175 Number of Containers (nbut1375) 计算n /1+n/2+n/3+n/4....+n/n
- (((x)+(n)-1)&~((n) - 1) ) 的数学原理
- 推送通知的实现
- android设备获取当前wifi下的路由器的mac和路由器的名称
- 文章标题
- Jquery ajax 得到返回值
- PKU Campus 2015 E:Transformation
- ZOJ-2996 (1+x)^n
- Linux平台Oracle多个实例启动
- kX 3552插件===优化注册表小程序
- 设计模式C++实现三:装饰模式
- Android自定义模板view的方法
- Android 5.0重启恢复Task功能分析
- flume ng
- LayoutInflater作用及使用
- Spring核心学习(4)从XML中读取BeanDefinition-将代码变成配置