题目传送门

 /*
题意:b+1,b+2,...,a 所有数的素数个数和
DP+埃氏筛法:dp[i] 记录i的素数个数和,若i是素数,则为1;否则它可以从一个数乘以素数递推过来
最后改为i之前所有素数个数和,那么ans = dp[a] - dp[b];
详细解释:http://blog.csdn.net/catglory/article/details/45932593
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
#include <cmath>
using namespace std; typedef long long ll; const int MAXN = 5e6 + ;
const int INF = 0x3f3f3f3f;
int prime[MAXN];
bool is_prime[MAXN];
ll dp[MAXN]; int seive(void)
{
for (int i=; i<=5e6; ++i) is_prime[i] = true;
is_prime[] = is_prime[] = false;
int p = ;
for (int i=; i<=5e6; ++i)
{
if (is_prime[i])
{
prime[++p] = i;
for (int j=*i; j<=5e6; j+=i) is_prime[j] = false;
}
} return p;
} void solve(void)
{
int p = seive ();
for (int i=; i<=5e6; ++i)
{
if (is_prime[i]) {dp[i] = ; continue;}
for (int j=; j<=p; ++j)
{
if (i % prime[j] == )
{
dp[i] = dp[i/prime[j]] + ; break;
}
}
} for (int i=; i<=5e6; ++i) dp[i] += dp[i-];
} int main(void) //Codeforces Round #304 (Div. 2) D. Soldier and Number Game
{
solve ();
int t; scanf ("%d", &t);
while (t--)
{
int a, b;
scanf ("%d%d", &a, &b);
printf ("%I64d\n", dp[a] - dp[b]);
} return ;
} /*
3
3 1
6 3
5000000 4999995
*/

最新文章

  1. sp_sys_ERPTrigger_base
  2. C 中 关于printf 函数中度剖析
  3. 如何设置table的border-radius?
  4. JavaScript API
  5. 给ThinkPHP5增加验证码功能
  6. session和cookie的辨析[阅读]
  7. sqoop使用的问题
  8. DOM Exception error 类型
  9. Vasya the Hipster
  10. 设计模式 — 工厂方法模式(Factory Method)
  11. OpenCV__type()返回的数字
  12. functions 示例
  13. 论文阅读笔记二十二:End-to-End Instance Segmentation with Recurrent Attention(CVPR2017)
  14. JavaEE XML的读写(利用JDom对XML文件进行读写)
  15. Netty1
  16. 再谈fedora下的音乐和视频播放器的安装
  17. cmder简单使用
  18. 删除文件以后,如何通过git撤销删除的文件,不提交到远端代码库
  19. c# 设计模式 之:策略模式
  20. 使用C6748和C5509A对nRF24L01驱动进行数据传输

热门文章

  1. directdraw 显示yuv
  2. scala快速学习笔记(一):变量函数,操作符,基本类型
  3. hadoop 集群搭建 配置 spark yarn 对效率的提升永无止境
  4. RabbitMQ使用简述
  5. YTU 2209: 建立链表(线性表)
  6. Go——godoc命令简介
  7. oracle:block 的 water mark问题
  8. BlueSea笔记&lt;1&gt;--Cricket初探
  9. UVA-10391(字符串检索)
  10. 【Codeforces 632D】 Longest Subsequence