hdu1796 How many integers can you find
//设置m,Q小于n可以设置如何几号m随机多项整除
//利用已知的容斥原理
//ans = 数是由数的数目整除 - 数为整除的两个数的数的最小公倍数 + 由三个数字。。。
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std ;
const int maxn = 110 ;
typedef __int64 ll ;
int a[maxn] ;
int len ;
int n , m ;
ll gcd(ll a , ll b)
{
if(b == 0)
return a ;
return gcd(b, a%b) ;
}
int dfs(int pos , ll lcm)
{
int ans = 0 ;
for(int i = pos ;i <= len;i++)
{
ll lcm_n = lcm*a[i]/gcd(lcm , a[i]) ;//最小公倍数可能会爆int,被坑了一下
ans += (n-1)/lcm_n - dfs(i+1 , lcm_n) ;
}
return ans ;
}
int main()
{
while(~scanf("%d%d" , &n , &m))
{
len = 0 ;
for(int i = 1;i <= m;i++)
{
int t ;
scanf("%d" , &t) ;
if(!t) continue ;//可能会有0
a[++len] = t ;
}
int ans = dfs(1 , 1) ;
printf("%d\n" , ans) ;
}
return 0 ;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
hdu1796 How many integers can you find的更多相关文章
- hdu1796 How many integers can you find 容斥原理
Now you get a number N, and a M-integers set, you should find out how many integers which are small ...
- Hdu1796 How many integers can you find 2017-06-27 15:54 25人阅读 评论(0) 收藏
How many integers can you find Time Limit : 12000/5000ms (Java/Other) Memory Limit : 65536/32768K ...
- HDU1796 How many integers can you find(容斥原理)
题目给一个数字集合,问有多少个小于n的正整数能被集合里至少一个元素整除. 当然是容斥原理来计数了,计算1个元素组合的有几个减去2个元素组合的LCM有几个加上3个元素组合的LCM有几个.注意是LCM. ...
- HDU1796 How many integers can you find【容斥定理】
题目链接: http://acm.hdu.edu.cn/showproblem.php? pid=1796 题目大意: 给你一个整数N.和M个整数的集合{A1.A2.-.Am}.集合内元素为非负数(包 ...
- 容斥原理学习(Hdu 4135,Hdu 1796)
题目链接Hdu4135 Co-prime Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- How many integers can you find(hdu1796)
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- [LeetCode] Sum of Two Integers 两数之和
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...
- [LeetCode] Divide Two Integers 两数相除
Divide two integers without using multiplication, division and mod operator. If it is overflow, retu ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- iframe属性參数
iframe属性參数 当点击一个子页面的链接时, 怎样将还有一个子页面嵌入到当前iframe中 仅仅要给这个iframe命名就能够了. <iframe width=420 height=330 ...
- CentOS 6 安装Oracle11g
原创作品.从 "深蓝blog" 博客,欢迎转载,请务必注明转载如下源.否则追究其版权责任. 深蓝的blog:http://blog.csdn.net/huangyanlong/ar ...
- 轻松管理您的网络password
在互联网在现在这个时代,,我们注册了很多帐户.支付宝账号password,各种宝账户password.微信,QQ,电话password,购买各种网站,金融password,它是不是让孩子们的鞋子瞬间淡 ...
- uva 11396Claw Decomposotion(二分图判定)
题目大意:给出一个简单无向图,每一个点的度为3.推断是否能将此图分解成若干爪的形式.使得每条边都仅仅出如今唯一的爪中. (点能够多次出如今爪中) 这道题实质上就是问这个图是否为二分图,dfs判定 ...
- [Unity3D]脚本中Start()和Awake()的差别
Unity3D刚開始学习的人常常把Awake和Start混淆. 简单说明一下,Awake在MonoBehavior创建后就立马调用,Start将在MonoBehavior创建后在该帧Update之前. ...
- JAVA字符串比较equals()和equalsIgnoreCase()差异
.用equals( )方法比較两个字符串是否相等.它具有例如以下的一般形式: boolean equals(Object str) 这里str是一个用来与调用字符串(String)对象做比較的字符串( ...
- Andorid Async-HttpClient阅览
Async-httpclient它是一个用于Android应用程序开发http访问开源框架.开源GitHub在,因为今天GitHub下载没有看到.我在这里提供下载地址.是之前从GitHub上下载的,版 ...
- UI —— 计算器
#import <UIKit/UIKit.h> @interface MyViewController :UIViewController { NSInteger _firstName; ...
- virus.win32.parite.H查杀病毒的方法
virus.win32.parite.H病毒的查杀方法 昨天电脑中了virus.win32.parite.H病毒,搞了2个多小时最终搞定了.以下记录下我的解决方法. 第一步:下载Win32.Parit ...
- [LeetCode228]Summary Ranges
题目: Given a sorted integer array without duplicates, return the summary of its ranges. For example, ...