How many integers can you find HDU - 1796_容斥计数
Code:
#include<cstdio>
using namespace std;
typedef long long ll;
const int R=13;
ll a[R];
ll n,ans;
int m,cnt=0;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
void dfs(int cur,ll lcm,int id){
if(cur>cnt)return;
lcm=a[cur]/gcd(a[cur],lcm)*lcm; if(id)ans+=(n-1)/lcm;
else ans-=(n-1)/lcm;
for(int i=cur+1;i<=cnt;++i)
dfs(i,lcm,!id);
}
int main(){
while(scanf("%lld%d",&n,&m)!=EOF)
{
ans=cnt=0;
for(int i=1;i<=m;++i){
ll k;
scanf("%lld",&k);
if(k)a[++cnt]=k;
}
for(int i=1;i<=cnt;++i)
dfs(i,a[i],1);
printf("%lld\n",ans);
}
return 0;
}
How many integers can you find HDU - 1796_容斥计数的更多相关文章
- Co-prime HDU - 4135_容斥计数
Code: #include<cstdio> #include<cstring> #include<cmath> #include<iostream> ...
- HDU 4135 容斥
问a,b区间内与n互质个数,a,b<=1e15,n<=1e9 n才1e9考虑分解对因子的组合进行容斥,因为19个最小的不同素数乘积即已大于LL了,枚举状态复杂度不会很高.然后差分就好了. ...
- HDU 2841 容斥 或 反演
$n,m <= 1e5$ ,$i<=n$,$j<=m$,求$(i⊥j)$对数 /** @Date : 2017-09-26 23:01:05 * @FileName: HDU 284 ...
- HDU 1695 容斥
又是求gcd=k的题,稍微有点不同的是,(i,j)有偏序关系,直接分块好像会出现问题,还好数据规模很小,直接暴力求就行了. /** @Date : 2017-09-15 18:21:35 * @Fil ...
- HDU 4059 容斥初步练习
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...
- hdu 1220 容斥
http://acm.hdu.edu.cn/showproblem.php?pid=1220 Cube Time Limit: 2000/1000 MS (Java/Others) Memory ...
- 题解报告:hdu 4135 Co-prime(容斥定理入门)
Problem Description Given a number N, you are asked to count the number of integers between A and B ...
- HDU How many integers can you find 容斥
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1796How many integers can you find(简单容斥定理)
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
随机推荐
- 5、Linux的常用命令
ls 查看当面目录结构 ls -l 列表查看当前目录 cd:切换目录 pwd:显示目前的目录 mkdir:创建一个新的目录 rmdir:删除一个空的目录 cp: 复制文件或目录 rm: 移除文件或目录 ...
- tp5 前置方法
Route::any('adminapi/v1/login','adminapi/v1.login/login');Route::any('adminapi/v1/first','adminapi/v ...
- python 实现kmeans聚类
编程中在做数值相等判断的时候,直接使用==判断并不可靠.实际上经过运算后的两个值(浮点型)并不可能完全一致,可能会因为小数点后的些许差异导致判断为false. 比如: 1 print 1e-5 == ...
- isap算法模板poj 1273gap+弧优化 最大流
几个比较好的博客 http://www.renfei.org/blog/isap.html http://kenby.iteye.com/blog/945454 http://blog.csdn.ne ...
- 【Storm】storm安装、配置、使用以及Storm单词计数程序的实例分析
前言:阅读笔记 storm和hadoop集群非常像.hadoop执行mr.storm执行topologies. mr和topologies最关键的不同点是:mr执行终于会结束,而topologies永 ...
- spring中abstract bean的使用方法
什么是abstract bean?简单来说.就是在java中的继承时候,所要用到的父类. 案例文件结构: 当中Person类为父类.Student类为子类,其详细类为: package com.tes ...
- Eclipse打开ftl文件,高亮显示
解决方式一:下载eclipse相关的freemarker插件 解决方式二:原生解决方式,方法特点无需下载插件,和eclipse编辑html和jsp文件一模一样 步骤: 1:windows---pref ...
- 轻快的vim(二):插入
上一节我们讲到了VIM中的移动,既然已经能够在屏幕和光标间游刃有余了 那么,现在就来谈谈插入命令 不知道有多少VIM新手和我当年(去年)一样,信誓旦旦的以为只有i可以插入 唉,现在想想都觉得可笑,都是 ...
- android的低内存管理器【转】
本文转载自:http://blog.csdn.net/haitaoliang/article/details/22092321 版权声明:本文为博主原创文章,未经博主允许不得转载. 安卓应用不用太在意 ...
- ffmpeg实现
最近做一个小项目,要在线播放录制的 MP4 视频,想开源的 flash player 或 html 5 可以播放.可,虽然 MP4 是 H.264 编码,但就是播放不了.可能是封装方式(PS 方式)不 ...