hdu 1796 How many integers can you find(容斥原理)
来源:互联网 发布:上海爱知锻造有限公司 编辑:程序博客网 时间:2024/06/09 14:32
点击打开链接
#include <iostream>#include <cstring>#include <vector>using namespace std;typedef long long ll;const int N=1e6+20;ll n,m,num,ans;int fac[N];ll gcd(ll a,ll b){if(a%b==0)return b;elsereturn gcd(b,a%b);}ll dfs(int id,int flag,ll LCM){LCM=fac[id]/gcd(fac[id],LCM)*LCM;//flag个数的LCM if(flag%2)ans+=n/LCM;elseans-=n/LCM;for(int i=id+1;i<=num;i++) {dfs(i,flag+1,LCM); } }int main(){while(cin>>n>>m){ans=0; num=0;for(int i=0;i<m;i++){ll x;cin>>x;if(x){fac[++num]=x;}} n--; //小于n //能被fac[i]整除的为集合pi 则小于N&&能被任意一个fac[i]整除的个数为 p1Up2..Upm //p1Up2=n/p1+n/p2-n/LCM(p1,p2)..for(int i=1;i<=num;i++){dfs(i,1,fac[i]);} cout<<ans<<endl;}return 0;}
0 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 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 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(容斥原理)
- bzoj3376/poj1988[Usaco2004 Open]Cube Stacking 方块游戏
- 如何将科学技术转化为财富
- 【Android Studio】svn 新建的文件自动添加到版本控制
- mybatis使用字符串参数
- 支付宝接口开发
- hdu 1796 How many integers can you find(容斥原理)
- Java之关于super的用法
- php 信号量(共享内存)
- Java 面向对象
- 设置IE渲染方式默认为最高
- Supervisor安装步骤:
- html——03(input、form、mark)
- select2插件笔记
- windows xp,windows 7电源管理总结