题意:输入两个正整数L、U(L<=U<1012),统计区间[L,U]的整数中有多少个数满足:它本身不是素数,但只有一个素因子。

分析:

1、满足条件的数是素数的倍数。

2、枚举所有的素数,以及其倍数,将满足条件且小于等于n的个数计算出来,solve(u) - solve(l - 1)即可。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b) {
if(fabs(a - b) < eps) return 0;
return a < b ? -1 : 1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 1e6 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int vis[MAXN];
vector<LL> prime;
void init(){
for(int i = 2; i < MAXN; ++i){
if(!vis[i]){
prime.push_back(i);
for(int j = 2 * i; j < MAXN; j += i){
vis[j] = 1;
}
}
}
}
LL solve(LL n){
LL ans = 0;
int len = prime.size();
for(int i = 0; i < len; ++i){
LL tmp = prime[i] * prime[i];
if(tmp > n) break;
while(tmp <= n){
++ans;
tmp *= prime[i];
}
}
return ans;
}
int main(){
init();
int T;
scanf("%d", &T);
while(T--){
LL l, u;
scanf("%lld%lld", &l, &u);
printf("%lld\n", solve(u) - solve(l - 1));
}
return 0;
}

  

最新文章

  1. rootkit后门检查工具RKHunter
  2. 区分debug和release生成文件的名称
  3. 《2016ThoughtWorks技术雷达峰会----变革的原因》
  4. MVC升级以后出现&quot;当前上下文中不存在ViewBag&quot;的问题解决
  5. BDC、CATT批量数据维护
  6. Objective-c——UI基础开发第七天(自定义UITableView)
  7. FIR系统的递归与非递归实现
  8. 状压DP
  9. 关于sublime text
  10. chmod -x chmod的N种解法
  11. 万恶DevExpress
  12. ReplaceGoogleCDN:将 Google CDN 更换国家
  13. @synthesize和@dynamic
  14. 01-01_环境准备_pyenv
  15. 使用.NET Hardware Intrinsics API加速机器学习场景
  16. 【mysql】mysql触发器使用示例
  17. python 关于文件的操作
  18. Bootstrap模态框(一个页面显示多个)的使用
  19. Docker dockerfile镜像编码
  20. 在Maven仓库中添加Oracle数据库的JDBC驱动依赖

热门文章

  1. 第1节 storm日志告警:1、 - 5、日志监控告警业务需求、代码、集群运行、总结
  2. MariaDB——数据库基础与sql语句
  3. (编辑状态下)Reset及OnValidate使用
  4. 吴裕雄--天生自然JAVAIO操作学习笔记:System类对IO的支持和BuffereRead
  5. 吴裕雄--天生自然JAVA数据库编程:SQL常用语句基础
  6. SciPy 优化
  7. hello程序的运行过程-从计算机系统角度
  8. CSS样式表——样式
  9. java List 去重方式及效率对比
  10. class(二)--派生类的继承