hdu 1796 How many integers can you find 容斥定理
How many integers can you find
Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
2 3
- #include<iostream>
- #include<cstdio>
- #include<cmath>
- #include<string>
- #include<queue>
- #include<algorithm>
- #include<stack>
- #include<cstring>
- #include<vector>
- #include<list>
- #include<set>
- #include<map>
- using namespace std;
- #define ll __int64
- #define mod 1000000007
- #define inf 999999999
- //#pragma comment(linker, "/STACK:102400000,102400000")
- int scan()
- {
- int res = , ch ;
- while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
- {
- if( ch == EOF ) return << ;
- }
- res = ch - '' ;
- while( ( ch = getchar() ) >= '' && ch <= '' )
- res = res * + ( ch - '' ) ;
- return res ;
- }
- ll a[];
- ll ji;
- ll ans,x,y;
- ll gcd(ll x,ll y)
- {
- return y==?x:gcd(y,x%y);
- }
- void dfs(ll lcm,ll pos,ll step)
- {
- if(lcm>x)
- return;
- if(pos==ji)
- {
- if(step==)
- return;
- if(step&)
- ans+=x/lcm;
- else
- ans-=x/lcm;
- return;
- }
- dfs(lcm,pos+,step);
- dfs(lcm/gcd(a[pos],lcm)*a[pos],pos+,step+);
- }
- int main()
- {
- ll z,i,t;
- while(~scanf("%I64d%I64d",&x,&y))
- {
- x--;
- ji=;
- for(i=;i<y;i++)
- {
- scanf("%I64d",&z);
- if(z==)continue;
- a[ji++]=z;
- }
- ans=;
- dfs(,,);
- printf("%I64d\n",ans);
- }
- return ;
- }
hdu 1796 How many integers can you find 容斥定理的更多相关文章
- hdu 1796 How many integers can you find 容斥第一题
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1796 How many integers can you find 容斥入门
How many integers can you find Problem Description Now you get a number N, and a M-integers set, y ...
- HDU 1796 How many integers can you find (容斥)
题意:给定一个数 n,和一个集合 m,问你小于的 n的所有正数能整除 m的任意一个的数目. 析:简单容斥,就是 1 个数的倍数 - 2个数的最小公倍数 + 3个数的最小公倍数 + ...(-1)^(n ...
- HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举)
HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举) 题意分析 求在[1,n-1]中,m个整数的倍数共有多少个 与 UVA.10325 ...
- HDU 1796How many integers can you find(简单容斥定理)
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU1796 How many integers can you find【容斥定理】
题目链接: http://acm.hdu.edu.cn/showproblem.php? pid=1796 题目大意: 给你一个整数N.和M个整数的集合{A1.A2.-.Am}.集合内元素为非负数(包 ...
- hdu 4135 [a,b]中n互质数个数+容斥
http://acm.hdu.edu.cn/showproblem.php?pid=4135 给定一个数n,求某个区间[a,b]内有多少数与这个数互质. 对于一个给定的区间,我们如果能够求出这个区间内 ...
- HDU 4135 Co-prime 欧拉+容斥定理
Co-prime Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
随机推荐
- [py]letcode第一题求和
letcode第一题, tm的不好弄. 想了很久想到了一个粗蠢的解决办法. Given an array of integers, return indices of the two numbers ...
- [LeetCode] 331. Verify Preorder Serialization of a Binary Tree_Medium tag: stack
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, ...
- [LeetCode] 675. Cut Off Trees for Golf Event_Hard tag: BFS
You are asked to cut off trees in a forest for a golf event. The forest is represented as a non-nega ...
- numpy的ravel()和flatten()函数
相同点: 两者所要实现的功能是一致的(将多维数组降位一维).这点从两个单词的意也可以看出来,ravel(散开,解开),flatten(变平). In [14]: x=np.array([[1,2],[ ...
- C:\WINDOWS\system32\drivers\etc\hosts 文件的作用
先来看一看C:\WINDOWS\system32\drivers\etc\hosts 系统原来的hosts文件(未经过改动) 打开原来的hosts文件,查看原来的内容 host是一个没有扩展名的系统文 ...
- servlet07
1.session验证 可以防止非登录的用户,通过在地址栏中输入地址,访问受保护的页面 step1.在用户登录成功之后,将用户的信息保存到session中 step2.在访问受保护的页面时,校验ses ...
- 9/24matplotlib简介
Matplotlib是一个在python下实现的类matlib的纯python的三方库,旨在用python实现matlib的功能,是python下最出色的绘图库,功能很完善,其风格根matlib很相似 ...
- Problem B. Full Binary Tree
题目 链接:http://code.google.com/codejam/contest/2984486/dashboard#s=p1 googlde code jam 2014 Round1A 解题 ...
- SQL 中单引号 和一些特殊字符的处理
为了防止程序SQL语句错误以及SQL注入,单引号必须经过处理.有2种办法: 1.使用参数,比如SELECT * FROM yourTable WHERE name = @name; 在Java中就是用 ...
- PowerDesigner 表格导出为excel
PD菜单栏中,依次点击 Tools ->Excute Commands->Edit/Run Script.. 填入 '*********************************** ...