D. Soldier and Number Game
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the second soldier. Then the second one tries to make maximum possible number of rounds. Each round consists of choosing a positive integer x > 1, such that n is divisible by x and replacing n with n / x. When n becomes equal to 1 and there is no more possible valid moves the game is over and the score of the second soldier is equal to the number of rounds he performed.

To make the game more interesting, first soldier chooses n of form a! / b! for some positive integer a and b (a ≥ b). Here by k! we denote the factorial of k that is defined as a product of all positive integers not large than k.

What is the maximum possible score of the second soldier?

Input

First line of input consists of single integer t (1 ≤ t ≤ 1 000 000) denoting number of games soldiers play.

Then follow t lines, each contains pair of integers a and b (1 ≤ b ≤ a ≤ 5 000 000) defining the value of n for a game.

Output

For each game output a maximum score that the second soldier can get.

Examples
Input
2
3 1
6 3
Output
2
5
题意:求[b+1,a]区间内的所有数质因数分解的得到的的质数个数;
思路:素数打表+质因数分解求前缀和,这题nsqrt(n)不知道能不能过;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define esp 1e-10
const int N=1e6+,M=1e6+,mod=1e9+,inf=1e9+;
const int MAXN=;
int prime[MAXN];
bool vis[MAXN];
int sum[MAXN];
int Prime(int n)
{
int cnt=;
memset(vis,,sizeof(vis));
for(int i=;i<n;i++)
{
if(!vis[i])
prime[cnt++]=i;
for(int j=;j<cnt&&i*prime[j]<n;j++)
{
vis[i*prime[j]]=;
if(i%prime[j]==)
break;
}
}
return cnt;
}
int main()
{
int x,y,z,i,t;
int cnt=Prime(MAXN);
for(i=;i<MAXN;i++)
{
int flag=i;
for(t=;t<cnt;t++)
{
if(flag==)
break;
if(!vis[flag])
{
sum[i]++;
break;
}
while(flag%prime[t]==)
{
flag/=prime[t];
sum[i]++;
}
}
sum[i]+=sum[i-];
}
int T;
scanf("%d",&T);
while(T--)
{
int a,b;
scanf("%d%d",&a,&b);
printf("%d\n",sum[a]-sum[b]);
}
return ;
}

最新文章

  1. Spring 5 新特性:函数式Web框架
  2. PHP-redis中文文档介绍(转自http://www.jb51.net/article/33887.htm)
  3. [原创] hadoop学习笔记:hadoopWEB监控
  4. crackme_zapline分析
  5. 有关AES加密的问题
  6. 对CURL的一些研究
  7. C++发送邮件和附件
  8. TensorFlow conv2d原理及实践
  9. hdu 5274 Dylans loves tree(LCA + 线段树)
  10. js隐藏字符串中间部分
  11. react 组件列表
  12. JVM:从实际案例聊聊Java应用的GC优化
  13. Unable to open socket file: target process not responding or HotSpot VM not loaded
  14. mint18.3 升级linux-libc-dev_4.4.0-102.132 导致外接显示屏无法旋转,设置分辨率
  15. Java按值传递、按引用传递
  16. struct和typedef struct区别
  17. Vue.js 上传文件(后台使用.net)
  18. FastReport.Net使用:[9]多栏报表(多列报表)
  19. 设计模式之策略模式(php实现)
  20. 在网页中显示PDF文件及vue项目中弹出PDF

热门文章

  1. 《从零开始学Swift》学习笔记(Day43)——构造函数继承
  2. MVC5学习系列
  3. tomcat单应用多实例部署报错 应用jar不存在
  4. 2014-08-28——Android和IOS的简单嗅探,以及横竖屏的捕获思路
  5. python并发编程&amp;多线程(二)
  6. A Simple Web Server
  7. python 报错——Python TypeError: &#39;module&#39; object is not callable 原因分析
  8. open函数and文件处理
  9. JavaWeb:JSP标准标签库
  10. Linux系统资源查询命令(cpu、io、mem)