Now you get a number N, and a M-integers set, you should find out how many integers which are small than N, that they can divided exactly by any integers in the set. For example, N=12, and M-integer set is {2,3}, so there is another set {2,3,4,6,8,9,10}, all the integers of the set can be divided exactly by 2 or 3. As a result, you just output the number 7.

Input  There are a lot of cases. For each case, the first line contains two integers N and M. The follow line contains the M integers, and all of them are different from each other. 0<N<2^31,0<M<=10, and the M integer are non-negative and won’t exceed 20.Output  For each case, output the number.Sample Input

12 2
2 3

Sample Output

7
被这个题卡了很久,主要是有个坑和一个一个知识漏洞
题目最欧一句话描述的不太清晰,,他的意思是输入的M的整数中可能有0;
还有就是判断一个数在n前面的数中充当因子的次数时,可以直接用n除以这个数,但是判断多个数时,共同充当因子的次数时,要用n除以这几个数的最小公倍数
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;
ll arr[];
//set<ll>se;
//set<ll>::iterator it;
int main(){
ll n,m;
while(scanf("%lld%lld",&n,&m)!=EOF)
{
ll x,pos=;
for(int i=;i<=m;i++){
scanf("%lld",&x);
if(x!=){
// se.insert(x);
pos++;
arr[pos]=x;
}
}
//
// ll pos=0;
// for(it=se.begin();it!=se.end();it++){
// pos++;
// arr[pos]=*it;
// }
// ll s=;
for(int i=;i<(<<pos);i++){
ll cnt =,sum=;
for(int j=;j<pos;j++){
if(&(i>>j)){
// sum*=arr[j+1];
sum=(sum*arr[j+])/__gcd(sum,arr[j+]);
cnt++;
}
}
if(cnt&){
s+=n/sum;
}
else {
s-=n/sum;
}
}
for(int i=;i<=pos;i++)
if(n%arr[i]==){
s--;
break;
}
printf("%lld\n",s);
// se.clear();
}
return ;
}

B - How many integers can you find 杭电1976的更多相关文章

  1. acm入门 杭电1001题 有关溢出的考虑

    最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...

  2. 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过

    杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...

  3. Help Johnny-(类似杭电acm3568题)

    Help Johnny(类似杭电3568题) Description Poor Johnny is so busy this term. His tutor threw lots of hard pr ...

  4. 『ACM C++』HDU杭电OJ | 1415 - Jugs (灌水定理引申)

    今天总算开学了,当了班长就是麻烦,明明自己没买书却要带着一波人去领书,那能怎么办呢,只能说我善人心肠哈哈哈,不过我脑子里突然浮起一个念头,大二还要不要继续当这个班委呢,既然已经体验过就可以适当放下了吧 ...

  5. 杭电ACM刷题(1):1002,A + B Problem II 标签: acmc语言 2017-05-07 15:35 139人阅读 评

    最近忙于考试复习,没有多少可供自己安排的时间,所以我利用复习之余的空闲时间去刷刷杭电acm的题目,也当对自己编程能力的锻炼吧. Problem Description I have a very si ...

  6. 杭电OJ 输入输出练习汇总

    主题 Calculate a + b 杭电OJ-1000 Input Each line will contain two integers A and B. Process to end of fi ...

  7. 杭电acm 1002 大数模板(一)

    从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的, ...

  8. 杭电OJ——1198 Farm Irrigation (并查集)

    畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...

  9. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

随机推荐

  1. C语言学生管理系统

    想练习一下链表,所以就有了这个用C写的学生管理系统 没有把它写入文件,才不是因为我懒哈哈哈,主要是为了练习链表的 #include<stdio.h> #include<stdlib. ...

  2. Diagnostics: File file:/private/tmp/spark-d4ebd819-e623-47c3-b008-2a4df8019758/__spark_libs__6824092999244734377.zip does not exist java.io.FileNotFoundException: File file:/private/tmp/spark-d4ebd819

    spark伪分布式模式 on-yarn出现一下错误 Diagnostics: File file:/private/tmp/spark-d4ebd819-e623-47c3-b008-2a4df801 ...

  3. 在Windows中安装OpenCV-Python |四

    目标 在本教程中 我们将学习在你的Windows系统中设置OpenCV-Python. 下面的步骤在装有Visual Studio 2010和Visual Studio 2012的Windows 7- ...

  4. [Java8教程]Java8新特性进阶集合

    Java8新特性进阶集合 基于 AOP 抽离方法的重复代码 Java8:当 Lambda 遇上受检异常 Java8:对字符串连接的改进 Java8:Java8 中 Map 接口的新方法 Java8:当 ...

  5. 使用webhooks进行代码的自动化部署

    AutoMaticDeployment---自动部署 项目简介 使用Github的webhooks进行代码的自动化部署 本项目是个人最近搞的一个小工具,自己最近在用hexo部署个人博客(地址:http ...

  6. Vue.js系列(一):Vue项目创建详解

    引言 Vue.js作为目前最热门最具前景的前端框架之一,其提供了一种帮助我们快速构建并开发前端项目的新的思维模式.本文旨在帮助大家认识Vue.js,并详细介绍使用vue-cli脚手架工具快速的构建Vu ...

  7. Day17---轻量级、高性能的服务器--Nginx

    Nginx基础 一.nginx的介绍 简介:Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMPA/POP3/SMTR代理服务器. 二.编译安装nginx 1.首先要安装PRCE(PRCE ...

  8. 使用 Visual Studio 开发、测试和部署 Azure Functions(二)测试,部署

    1,引言 上一篇介绍了使用使用 Visual Studio 开发 "Azure Functions" 函数,此篇介绍 “Azure Functions” 的测试以及直接从 Vist ...

  9. PTA数据结构与算法题目集(中文) 7-24

    PTA数据结构与算法题目集(中文)  7-24 7-24 树种统计 (25 分)   随着卫星成像技术的应用,自然资源研究机构可以识别每一棵树的种类.请编写程序帮助研究人员统计每种树的数量,计算每种树 ...

  10. 荐书在精不在多,推荐一份夯实Java基础的必备书单!

    文/黄小斜 转载请注明出处 head first Java 推荐指数:⭐️⭐️⭐️⭐️⭐️ 推荐理由: 说实话,这本书和其他的我Java类型书籍真的大不相同,它不会一本正经地去说技术概念和原理,而是通 ...