HDU 1796
呃,我竟然傻了,同时被a且b整除的个数为n/(a*b)。
其实应该是n/[a,b]才对,是他们的最小公倍数啊。。。
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- __int64 ans;
- __int64 set[30];
- __int64 n;
- int m;
- __int64 gcd(__int64 a,__int64 b){
- if(b==0) return a;
- return gcd(b,a%b);
- }
- void dfs(int i,int num,__int64 tmp){
- if(i>=m){
- if(num==0){
- ans=0;
- }
- else {
- if(num&1){
- ans=(ans+n/tmp);
- }
- else{
- ans=ans-n/tmp;
- }
- }
- return ;
- }
- dfs(i+1,num,tmp);
- dfs(i+1,num+1,tmp*set[i]/gcd(tmp,set[i]));
- }
- int main(){
- bool flag;
- while(scanf("%I64d%d",&n,&m)!=EOF){
- n--;
- flag=true;
- int k=0;
- for(int i=0;i<m;i++){
- scanf("%I64d",&set[i]);
- if(set[i])
- set[k++]=set[i];
- }
- m=k;
- ans=0;
- dfs(0,0,1);
- printf("%I64d\n",ans);
- }
- return 0;
- }
HDU 1796的更多相关文章
- HDU 1796 How many integers can you find (状态压缩 + 容斥原理)
题目链接 题意 : 给你N,然后再给M个数,让你找小于N的并且能够整除M里的任意一个数的数有多少,0不算. 思路 :用了容斥原理 : ans = sum{ 整除一个的数 } - sum{ 整除两个的数 ...
- HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举)
HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举) 题意分析 求在[1,n-1]中,m个整数的倍数共有多少个 与 UVA.10325 ...
- HDU 1796 容斥原理 How many integers can you find
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1796 处男容斥原理 纪念一下 TMD看了好久才明白DFS... 先贴代码后解释 #includ ...
- HDU 1796 How many integers can you find(容斥原理)
题目传送:http://acm.hdu.edu.cn/diy/contest_showproblem.php?cid=20918&pid=1002 Problem Description ...
- 容斥原理学习(Hdu 4135,Hdu 1796)
题目链接Hdu4135 Co-prime Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 1796 容斥原理
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
容斥原理!! 这题首先要去掉=0和>=n的值,然后再使用容斥原理解决 我用的是数组做的…… #include<iostream> #include<stdio.h> #i ...
- HDU 1796 Howmany integers can you find (容斥原理)
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1796 (容斥原理)
容斥原理练习题,忘记处理gcd 和 lcm,wa了几发0.0. #include<iostream> #include<cstdio> #include<cstring& ...
随机推荐
- 结束QQ即时通信垄断,开辟即时通信互联互通instantnet时代
结束QQ即时通信垄断,开辟即时通信互联互通instantnet时代 蓬勃发展的即时通信产业 即时通信(IM)是指可以即时发送和接收互联网消息等的业务. 即时通信.就是瞬间把信息发送给对方,假设不是即时 ...
- Linux系统编程——进程替换:exec 函数族
在 Windows 平台下,我们能够通过双击运行可运行程序,让这个可运行程序成为一个进程.而在 Linux 平台.我们能够通过 ./ 运行,让一个可运行程序成为一个进程. 可是.假设我们本来就执行着一 ...
- Spring-SpringJdbcTemlate配置介绍
使用spring的jdbcTemplate进一步操作JDBC 一.普通配置 SpringJdbcTemplate连接数据库并操作数据 1.applicationContext.xml 1.1 建立D ...
- Pixhawk---基于NSH的Firmware开发与调试
1 相关知识了解 1.1 Nuttx系统 嵌入式实时操作系统(RTOS). 强调标准兼容和小型封装,具有从8位到32位微控制器环境的高度可扩展性.NuttX 主要遵循 Posix 和 ANSI 标 ...
- 深刻理解Java中的String、StringBuffer和StringBuilder的差别
声明:本博客为原创博客,未经同意.不得转载!小伙伴们假设是在别的地方看到的话,建议还是来csdn上看吧(链接为http://blog.csdn.net/bettarwang/article/detai ...
- HDU 1113 Word Amalgamation (map 容器 + string容器)
http://acm.hdu.edu.cn/showproblem.php?pid=1113 Problem Description In millions of newspapers across ...
- edit filter rules in sql source control
https://documentation.red-gate.com/soc6/common-tasks/exclude-objects-using-filters 如果有人上传了filter,nam ...
- CGContext含义
代码 含义 CGContextRef context = UIGraphicsGetCurrentContext(); 设置上下文 CGContextMoveToPoint 开始画线 CGContex ...
- 知网下载pdf文件的方法
title: 知网下载pdf文件的方法 toc: false date: 2018-11-02 17:54:43 categories: methods tags: 知网 平时我们使用的是国内版的知网 ...
- sdwebimage缓存图片
当使用SDWebImage时,如果用相同图片名的图片替换掉了原始缓存的图片,当再次请求的时候,还是使用的缓存图片,图片不会发生改变 原因:图片在NSCache中是以absolute url作为key存 ...