题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1853

dfs实现容斥原理即可。

注意:若在init中写“cnt++”,则出来后需要先cnt--再继续!!

代码如下:

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll l,r,a[],b[],ans,cnt,ct;
bool del[];
void init(ll x)
{
if(x>r)return;
a[cnt++]=x;
init(*x+);
init(*x+);
}
ll gcd(ll x,ll y)
{
return x%y==?y:gcd(y,x%y);
}
void dfs(ll x,ll y,ll z)
{
if(x>ct)
{
if(y&)ans+=r/z-(l-)/z;
else if(y)ans-=r/z-(l-)/z;
return;
}
dfs(x+,y,z);
ll tmp=z/gcd(a[x],z);
if((double)a[x]*tmp<=r)dfs(x+,y+,a[x]*tmp);
}
int main()
{
scanf("%lld%lld",&l,&r);
init();
cnt--;//!!!
sort(a+,a+cnt+);
for(ll i=;i<=cnt;i++)
{
if(del[i])continue;
for(ll j=i+;j<=cnt;j++)
if(a[j]%a[i]==)del[j]=;
b[++ct]=a[i];
}
for(ll i=;i<=ct;i++)//倒序!
a[i]=b[ct-i+];
dfs(,,);
printf("%lld",ans);
return ;
}

最新文章

  1. ssh整合问题总结--在添加商品模块实现图片(文件)的上传
  2. slideDoor(学习某编程网站的,仅作记录和学习)
  3. Caffe proto閱讀
  4. php性能分析工具 - xhprof的安装使用
  5. 使用python来调试串口
  6. bootstrap static popover
  7. spring校验和文件上传
  8. Linq--扩展方法
  9. Egret的VS环境搭配
  10. SQL中数据类型转换
  11. 子查询 此处该用AND 而不是 WHERE
  12. Win7+QTP10.0+IE9无法启动IE的解决方法
  13. [算法] kmp实现
  14. Windows Graphics Programming Win32 GDI and DirectDraw第六章疑问
  15. obj-c编程19:关联对象
  16. python图形用户
  17. Shell编程基础知识(一)
  18. 萨塔尼亚的期末考试(fail)
  19. 第三个Sprint冲刺总结
  20. 基音检测算法的性能:Performance Evaluation of Pitch Detection Algorithms

热门文章

  1. SpringMvc aop before
  2. java eclipse使用不同jdk版本
  3. 利用树的先序和后序遍历打印 os 中的目录树
  4. 常见 WEB 安全漏洞(转)
  5. 九度OJ 1016:火星A+B (进制转换)
  6. php验证身份证号码有效性
  7. When Programmers and Testers Collaborate
  8. No provisioned iOS devices are available with a compatible iOS version. Connect an iOS device with a
  9. CF(439E - Devu and Birthday Celebration)莫比乌斯容斥
  10. ABAP alv report