time limit per test3 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard 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

【题目链接】:http://codeforces.com/contest/546/problem/D

【题解】



每个数字如果想让他除的次数更多,必然是每次都选择最小的质因子去除;

想想如果不是 除质因子,那个数x总是可以再分解成几个质因子的形式.

这样想之后;

a!/b!

=(b+1)(b+2)···*a

把每个数字都分解一下质因数就可以了

这个可以在做筛法求素数的时候搞定;

然后求一下前缀和就可以了;

输出的时候直接O(1)输出



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int MAXN = 5000000;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); LL v[MAXN+10],sum[MAXN+10]; int main()
{
//freopen("F:\\rush.txt","r",stdin);
for (int i = 2;i <= MAXN;i++)
if (v[i]==0)
{
for (int j = i;j <=MAXN ;j+=i)
{
int J = j;
while (J%i==0)
{
v[j]++;
J/=i;
}
}
}
rep1(i,1,MAXN)
sum[i] = sum[i-1]+v[i];
int T;
rei(T);
while (T--)
{
int a,b;
rei(a);rei(b);
printf("%I64d\n",sum[a]-sum[b]);
}
return 0;
}

最新文章

  1. Django登录访问限制 login_requeired
  2. Java的默认编码
  3. the major advances since the birth of the computer
  4. 【转】让Souce Insight支持多种语言的语法高亮:Python,Ruby,ARM汇编,windows脚本文件(bat/batch),PPC,SQL,TCL,Delphi等
  5. Suse linux 11 SP2 nginx 使用笔记
  6. EL表达式(胖先生版)
  7. BZOJ 1070 修车
  8. linux目录对照命令——meld
  9. Windows 桌面和文件夹的右键-&gt;打开命令行窗口
  10. Nginx下配置虚拟主机的三种方法
  11. 微软官网tools
  12. Docker容器运行ASP.NET Core
  13. 机器学习实战ch04 关于python版本所支持的文本格式问题
  14. json 压缩中文不转码
  15. python数字前自动补零
  16. 解决Installation failed with message Failed to finalize session : INSTALL_FAILED_INVALID_APK的问题
  17. electron安装与使用
  18. 20145302张薇《Java程序设计》第四周学习总结
  19. Openssl VS编译方法
  20. reactNative 的一些学习

热门文章

  1. [转]Linq使用心得——SelectMany替代二重foreach循环
  2. kindle paperwhite 简单笔记按名称分类
  3. ASM学习笔记--ASM 4 user guide 第一章翻译
  4. MWPhotoBrowser 属性详解 和代理解释
  5. [D3] SVG Graphics Containers and Text Elements in D3 v4
  6. vue配置路由
  7. ORA-00119: invalid specification for system parameter LOCAL_LISTENER;
  8. Android中各种drawable的使用
  9. Spring Boot应用启动原理分析(转)
  10. 【p092】分数线划定