【容斥原理】1717 题解
来源:互联网 发布:毕业生户口迁移 知乎 编辑:程序博客网 时间:2024/05/22 04:52
#include <iostream>#include <sstream>#include <cstdio>#include <cstdlib>#include <ctime>#include <cmath>#include <cctype>#include <cstring>#include <algorithm>#ifndef WIN32#define Auto "%lld"#else#define Auto "%I64d"#endifusing namespace std;#define ll long longll gcd(ll a, ll b) { return (!b) ? (a) : (gcd(b, a % b));}int n, m;int *arr;ll res = 0;inline void init() { int bn; scanf("%d%d", &bn, &m); arr = new int[(bn + 1)]; for(int i = 1, x; i <= bn; i++) { scanf("%d", &x); if(x > 17) arr[++n] = x; }}void dfs(int dep, int flag, ll temp) { if(temp > m) return; if(dep == n + 1) { if(temp > 1) res += flag * (m / temp); return; } int g = gcd(temp, arr[dep]); dfs(dep + 1, flag, temp); dfs(dep + 1, flag * -1, temp / g * arr[dep]);}inline void solve() { res = (m >= 17 && n) ? (1) : (0); m -= 17; dfs(1, -1, 1); printf(Auto, res);}int main() { init(); solve(); return 0;}
阅读全文
0 0
- 【容斥原理】1717 题解
- 【Codeforces 808B】【容斥原理】Average Sleep Time 题解
- 【容斥原理】Codeforces547C[Mike and Foam]题解
- 【BZOJ3812】【状压DP】【容斥原理】主旋律 题解
- hdu4135题解 容斥
- 周赛 1007 题解 hdu 4390 Number Sequence (质因数分解+组合数学+容斥原理)
- 【NOIP模拟题】【容斥原理】【数学归纳法】2016.11.18 第三题 题 题解
- 容斥原理
- 容斥原理 POJ3904
- 【容斥原理】八
- 【八】容斥原理
- 广义容斥原理
- 容斥原理
- 容斥原理 专题
- 容斥原理 专题
- hdu4390 容斥原理
- hdu1695 容斥原理
- HDU3929(容斥原理)
- 组合数性质的证明Ⅰ
- VMware Suspend 常见问题以及解决办法
- leetcode395. Longest Substring with At Least K Repeating Characters
- Maven学习总结(一)——Maven项目构建过程练习
- JAVA String.split()方法
- 【容斥原理】1717 题解
- Ural 1040 Airline Company(构造)
- O
- 为什么struct x1{struct x1 stX};无法通过编译
- 10种简单的Java性能优化
- Node.js——bower简明入门教程
- 34.笔记go语言——内建函数
- ResourceManager(八)—— 在安卓机子上实现加载AssetBundle
- vs的使用技巧