HDU 1796 How many integers can you find (简单容斥)
来源:互联网 发布:js onclick 变量 编辑:程序博客网 时间:2024/06/10 14:33
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1796
题意:给你m个正整数,问你从1到n-1有多少个数至少能被这m个数中的一个数整除。
题解:
AC代码:
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cstdlib>#include <cmath>#include <vector>#include <list>#include <deque>#include <queue>#include <iterator>#include <stack>#include <map>#include <set>#include <algorithm>#include <cctype>using namespace std;#define si1(a) scanf("%d",&a)#define si2(a,b) scanf("%d%d",&a,&b)#define sd1(a) scanf("%lf",&a)#define sd2(a,b) scanf("%lf%lf",&a,&b)#define ss1(s) scanf("%s",s)#define pi1(a) printf("%d\n",a)#define pi2(a,b) printf("%d %d\n",a,b)#define mset(a,b) memset(a,b,sizeof(a))#define forb(i,a,b) for(int i=a;i<b;i++)#define ford(i,a,b) for(int i=a;i<=b;i++)typedef __int64 LL;const int N=40000;const int INF=0x3f3f3f3f;const double PI=acos(-1.0);const double eps=1e-7;int n,m,cnt;LL a[12];LL gcd(LL a,LL b){ while(b) { LL t=a%b; a=b; b=t; } return a;}//容斥void dfs(int now,int count,LL lcm,LL &ans){ lcm=a[now]/gcd(lcm,a[now])*lcm; if(count&1) ans+=(n-1)/lcm; else ans-=(n-1)/lcm; for(int i=now+1;i<cnt;i++) dfs(i,count+1,lcm,ans);}int main(){// freopen("input.txt","r",stdin); int i,j; while(cin>>n>>m) { cnt=0; for(int i=0;i<m;i++) { int x; scanf("%d",&x); if(x) a[cnt++]=x; } LL ans=0; for(int i=0;i<cnt;i++) { dfs(i,1,a[i],ans); } printf("%I64d\n",ans); } return 0;}
- 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 1796 How many integers can you find(容斥原理)
- HDU 1796 How many integers can you find(组合数学-容斥原理)
- HDU 1796 How many integers can you find(组合数学-容斥原理)
- 容斥定理(1)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 (容斥原理)
- [ACM] HDU 1796 How many integers can you find (容斥原理)
- Android用百度云上传文件
- IT战略规划之流程再造
- jQuery中的Ajax几种请求方法
- struts2效验框架学习笔记(第一季)
- 第一个C++程序
- HDU 1796 How many integers can you find (简单容斥)
- SpringContextUtil工具类实现
- linux下应用软件突然丢失的的故障
- Map接口实现类HashMap之实现原理
- VC++实现NAT穿透之NAT类型检测
- 算法习题6:查找最小的k个元素
- 关于内网或者本机域名解析导致服务无法正常运行
- hadoop研究:mapreduce研究前的准备工作
- Spring事务的传播行为 @Transactional