HDU 1796 C - How many integers can you find -容斥
来源:互联网 发布:苹果适合java开发吗 编辑:程序博客网 时间:2024/06/14 15:21
http://bak.vjudge.net/problem/13388/origin
题意:经典容斥。。。不过给出的数不是互质的,容斥的时候不是用乘积,是用lcm
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;typedef long long ll;const ll p =1000000007;const int N=100000;ll lcm(ll a,ll b){ return a*b/__gcd(a,b);}int aa[11];int main(){ ll n; int m; while(scanf("%lld%d",&n,&m)!=EOF) { n--; int id=0; for (int i=0; i<m; i++) { scanf("%d",&aa[id++]); if (aa[id-1]==0)id--; } m=id; int all=1<<m; ll ans=0; for (int i=1; i<all; i++) { ll tmp=1; int cun=0; for (int j=0; j<m; j++) { if ((1<<j)&i) tmp=lcm(tmp,aa[j]),cun++; } if (cun%2) ans+=n/tmp; else ans-=n/tmp; } printf("%lld\n",ans); } return 0;}
0 0
- hdu-1796-How many integers can you find(容斥)
- HDU 1796 How many integers can you find 【容斥】
- HDU 1796 C - How many integers can you find -容斥
- HDOJ 1796 How many integers can you find (容斥)
- 【 hdoj 1796】How many integers can you find 【容斥】
- HDU 1796 How many integers can you find 容斥原理
- 【容斥原理】HDU-1796-How many integers can you find
- HDU 1796 How many integers can you find(容斥原理)
- hdu 1796 How many integers can you find(容斥定理)
- hdu 1796 How many integers can you find(容斥原理)
- 简单容斥定理-hdu-1796-How many integers can you find
- HDU 1796 容斥原理 How many integers can you find
- HDU 1796 How many integers can you find (简单容斥)
- HDU 1796How many integers can you find(简单容斥定理)
- HDU 1796How many integers can you find(简单容斥定理)
- hdu 1796 How many integers can you find(容斥原理)
- hdu 1796 How many integers can you find (容斥原理)
- hdu 1796 How many integers can you find 容斥原理
- HDU 5918 Sequence I CCPC 长春 暴力求解
- C++编程入门系列之前言
- 【智障题系列A】实数二分
- Python
- 浅析java多线程之ReentrantLock的使用
- HDU 1796 C - How many integers can you find -容斥
- [LeetCode]189. Rotate Array
- Gradle for Android(一)基本配置、依赖管理
- angular.js学习(1)--指令之间的交互--动感超人
- NOIP2016提高A组五校联考2总结
- 2069. 【2016.10.5NOIP普及模拟】wd的假日
- Gradle for Android(二)全局设置、自定义BuildConfig、混淆
- Spring IOC理解
- 编程中的难得糊涂