您的位置:首页 > 其它

CodeForces-546D.Soldier and Number Game

2016-07-24 22:44 211 查看
D. Soldier and Number Game
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

#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
#define N 5000000
int sum[N+2];
int Prime(int m)//求出m的一个因子
{
double a = sqrt((double)m);
for (int i = 2; i <= a; i++)
{
if (m%i == 0)
return i;
}
return 0;
}
void Init()
{
sum[1] = 0;
int a, b;
for (int i = 2; i <= N; i++)
{
a = Prime(i);
if (a != 0)
{
b = i / a;
sum[i] = sum[a] + sum[b];
}//i一定大于a和b,i的因子数目为a和b的因子数目总和
else
sum[i] = 1;
}
for (int j = 2; j <= N; j++)
sum[j] = sum[j] + sum[j - 1];
}
int main()
{
Init();
int t, a, b;
scanf("%d", &t);
while (t--)
{
scanf("%d%d", &a, &b);
printf("%d\n", sum[a] - sum[b]);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  CF ACM