容斥原理——hdu2204dfs深搜
/*
枚举素数幂p
然后求k^p<=n 的 k的个数
因为 k^p1*p2==k^p2*p1,所以这两种情况是多算的,所以要进行容斥
减去两个质数幂相乘的,再加上三个质数幂相乘的
因为2*3*5*7>60,所以最多容斥两次就可以
枚举pi最为起点进行深搜,只搜比pi大的
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int p[]={,,,,,,,,,,,,,,,,};
ll ans,n;
//素数下标pos,当前幂e,容斥标记(质数幂个数cnt)
void dfs(int pos,ll e,int cnt){
ll k=(ll)pow(n,1.0/e);
if(cnt%)ans+=k-;//k=1时不算
else ans-=k-;
if(cnt>)return;//不用往下搜了
for(int i=pos+;i<;i++)
dfs(i,e*p[i],cnt+);
}
int main(){
while(cin>>n){
ans=;
for(int i=;i<;i++)dfs(i,p[i],);
cout<<ans<<endl;
}
}
容斥原理——hdu2204dfs深搜的更多相关文章
- BZOJ_2393_Cirno的完美算数教室&&BZOJ_1853_[Scoi2010]幸运数字 _深搜+容斥原理
BZOJ_2393_Cirno的完美算数教室&&BZOJ_1853_[Scoi2010]幸运数字 _深搜+容斥原理 题意: ~Cirno发现了一种baka数,这种数呢~只含有2和⑨两种 ...
- Bzoj 2393: Cirno的完美算数教室 容斥原理,深搜
2393: Cirno的完美算数教室 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 287 Solved: 175[Submit][Status][ ...
- Bzoj 1853: [Scoi2010]幸运数字 容斥原理,深搜
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 1774 Solved: 644[Submit][Status] ...
- HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?
这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others) ...
- 利用深搜和宽搜两种算法解决TreeView控件加载文件的问题。
利用TreeView控件加载文件,必须遍历处所有的文件和文件夹. 深搜算法用到了递归. using System; using System.Collections.Generic; using Sy ...
- 2016弱校联盟十一专场10.3---Similarity of Subtrees(深搜+hash、映射)
题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52310 problem description Define the depth of a ...
- 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)
题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem description In ICPCCamp, there ar ...
- 2015暑假多校联合---Cake(深搜)
题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...
- 深搜+回溯 POJ 2676 Sudoku
POJ 2676 Sudoku Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17627 Accepted: 8538 ...
随机推荐
- class10_Frame 框架
最终运行效果图(程序见序号2): #!/usr/bin/env python # -*- coding:utf-8 -*- # ---------------------------------- ...
- AtCoder ABC 128E Roadwork
题目链接:https://atcoder.jp/contests/abc128/tasks/abc128_e 题目大意 在一条路上(这条路可以看做坐标轴 x 轴从 0 开始方向为正无穷方向的射线),有 ...
- RoHS
RoHS是<电气.电子设备中限制使用某些有害物质指令>(the Restriction of the use of certain hazardous substances in elec ...
- storm0.91集群部署
事先配置2台服务器配置好zookeeper,在配置文件中用zookeeper管理集群,配置文件如下 配置文件/conf/storm.yaml supervisor.slots.ports: 对于每个S ...
- python学习7—函数定义、参数、递归、作用域、匿名函数以及函数式编程
python学习7—函数定义.参数.递归.作用域.匿名函数以及函数式编程 1. 函数定义 def test(x) # discription y = 2 * x return y 返回一个值,则返回原 ...
- python学习2—python3特性与各种运算符
python学习2—python3特性与各种运算符 python3与python2相比具有的新特性 在python2中可以使用__future__模块调用python3的特性 print()函数必须带 ...
- Django开发学习BUG记录--RemovedInDjango19Warning:Model class apps.user.models.User doesn't declare an explicit app_label
报错信息: /home/python/PycharmProjects/dailyfresh/apps/user/models.py:8: RemovedInDjango19Warning: Model ...
- 【ASP.Net Core】不编译视图文件
原文:[ASP.Net Core]不编译视图文件 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/aqtata/article/details/818 ...
- 和Excel函数date同样功能的VBA函数DateSerial用法
Sub 日期别()On Error Resume Nextlastrow = Sheets("运营日报").Range("a1048576").End(xlUp ...
- boost multi_index 插入返回值
boost multi_index 对象插入函数emplace() 的返回值,是一个std::pair<iterator, bool>该pair 的first 是一个插入成功的位置,第二个 ...