noip模拟赛 计数
【问题描述】
给出m个数a[1],a[2],…,a[m]
求1~n中有多少数不是a[1],a[2],…,a[m]的倍数。
【输入】
输入文件名为count.in。
第一行,包含两个整数:n,m
第二行,包含m个数,表示a[1],a[2],…,a[m]
【输出】
输出文件名为count.out。
输出一行,包含1个整数,表示答案
【输入输出样例】
|
count.in |
count.out |
|
10 2 2 3 |
3 |
【数据说明】
对于60%的数据,1<=n<=106
对于另外20%的数据,m=2
对于100%的数据,1<=n<=109,0<=m<=20,1<=a[i]<=109
分析:一道比较简单的容斥原理的题.只需要dfs求出1个数的倍数有多少个,2个数的倍数有多少个......dfs暴力枚举就可以了.
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll; ll n, m, a[], ans; ll gcd(ll a, ll b)
{
if (!b)
return a;
return gcd(b, a % b);
} void dfs(int dep, int cnt, ll lcm)
{
if (dep == m + )
{
if (cnt & )
ans += (n / lcm);
else
if (cnt)
ans -= (n / lcm);
return;
}
dfs(dep + , cnt, lcm);
ll temp = lcm / gcd(lcm, a[dep]) * a[dep];
dfs(dep + , cnt + , temp);
} int main()
{
scanf("%lld%lld", &n, &m);
for (int i = ; i <= m; i++)
scanf("%lld", &a[i]);
dfs(, , );
printf("%d\n", n - ans); return ;
}
noip模拟赛 计数的更多相关文章
- NOIP模拟赛20161022
NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...
- contesthunter暑假NOIP模拟赛第一场题解
contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
- 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程
数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...
- 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
- 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...
- 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...
- CH Round #58 - OrzCC杯noip模拟赛day2
A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...
- CH Round #52 - Thinking Bear #1 (NOIP模拟赛)
A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...
随机推荐
- [Codeplus 2017] 晨跑
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=5105 [算法] 答案为三个数的最小公倍数 [代码] #include<bits ...
- 【POJ 1723】 SOLDIERS
[题目链接] http://poj.org/problem?id=1723 [算法] 中位数 [代码] #include <algorithm> #include <bitset&g ...
- linux安装 pip和setuptools
安装 setuptools wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg sh s ...
- 题目收藏夹(啥时候一遍A啥时候删)
以下题目为没有思路或代码离谱错误或看了题解才会的,间隔一周以上再做一遍A掉就删. bzoj1500 bzoj2287 codevs1358 bzoj1725
- [App Store Connect帮助]一、 App Store Connect 使用入门(3)首页概述
从首页可以访问 App Store Connect 的各个部分.您仅能访问每个部分中与您的用户职能相关联的功能. [提示]通过点按任何页面顶部的“App Store Connect”,您可以随时返回 ...
- [Swift通天遁地]九、拔剑吧-(5)创建Tab图标具有多种样式的Tab动画
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- canvas 文字转化为粒子
var canvas = document.createElement('canvas'); var cxt = canvas.getContext('2d'); var W = canvas.wid ...
- JavaScript入门二
******函数****** **函数定义** //普通函数定义 function f1() { console.log("Hello word!") } //带参数的函数 fun ...
- 【转】Java 集合系列09之 Map架构
概要 前面,我们已经系统的对List进行了学习.接下来,我们先学习Map,然后再学习Set:因为Set的实现类都是基于Map来实现的(如,HashSet是通过HashMap实现的,TreeSet是通过 ...
- Java引用jar的优化
一般java的类文件开头都是各种引用: 如 上图的引用可以写成