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;
}

【codeforces 546D】Soldier and Number Game的更多相关文章

  1. 【codeforces 546E】Soldier and Traveling

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. 【codeforces 546C】Soldier and Cards

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【codeforces 546A】Soldier and Bananas

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【codeforces 514A】Chewbaсca and Number

    [题目链接]:http://codeforces.com/contest/514/problem/A [题意] 允许你把每个数字翻转 ->x变成9-x 然后问你能够变成的最小的数字是什么; 不能 ...

  5. 【codeforces 546B】Soldier and Badges

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【 CodeForces - 392C】 Yet Another Number Sequence (二项式展开+矩阵加速)

    Yet Another Number Sequence Description Everyone knows what the Fibonacci sequence is. This sequence ...

  7. 【11.61%】【codeforces 670F】Restore a Number

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【CodeForces - 546C】Soldier and Cards (vector或队列)

    Soldier and Cards 老样子,直接上国语吧  Descriptions: 两个人打牌,从自己的手牌中抽出最上面的一张比较大小,大的一方可以拿对方的手牌以及自己打掉的手牌重新作为自己的牌, ...

  9. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

随机推荐

  1. 有关Canvas的一点小事—canvas数据和像素点

    1.  canvas生成base64数据 canvas.toDataURL()生成的数据可以直接给image对象使用作为<img>显示在前端,也可以传给后台生成图片保存.前端生成保存图片的 ...

  2. Web应用开发(Servlet+html+Mysql)入门小示例

    在安装好eclipse并配置完安装环境.安装好tomcat的前提下: 1.新建Dynamic Web Project,选择好运行的tomcat服务器版本等:2.在WebContent下:   新建fo ...

  3. Jquery+Ajax+Bootstrap Paginator实现分页的拼接

    效果图如下 jsp页面引入bootstrap样式,jquery和bootstrap-paginator.js <link type="text/css" rel=" ...

  4. sampleviewer add menu item error 'assert'

    可以跟踪到 mfc提供的源代码内部,(注:如果打开了mfc源代码,设置了断点,但是跟不进去,那就需要更新PDB文件,具体网上搜)打开 wincore.cpp文件(D:\Program Files\Mi ...

  5. 【例题 7-9 UVA-1601】The Morning after Halloween

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 对于没有出现的,当成0节点就好. 所以总是认为有3个人需要走到各自的终点. 将平面图转成点边图.这样比较好枚举. (二维变成一维,模 ...

  6. Android Material风格的应用(五)--CollapsingToolbar

    Collapsing Toolbar Android Material风格的应用(一)--AppBar TabLayoutAndroid Material风格的应用(二)--RecyclerViewA ...

  7. 边缘独立(marginal independent)的理解及举例

    1. 定义 ∀xi∈dom(X),yj∈dom(Y),yk∈dom(Y),如果满足, P(X=xi|Y=yj)==P(X=xi|Y=yk)P(X=Xi) 则称随机变量 X 边缘独立于随机变量 Y. 理 ...

  8. C#中防止程序多次运行

    C#中如何防止程序多次运行?只要在程序入口点函数Main()中的开始部分添加如注释部分的代码,就能快捷实现.   示例代码如下: using System; using System.Collecti ...

  9. 学习Java必看书籍和步骤

    Java语言基础  谈到Java语言基础学习的书籍,大家肯定会推荐Bruce Eckel的<ThinkinginJava>.它是一本写的相当深刻的技术书籍,Java语言基础部分基本没有其它 ...

  10. Altium Designer中距离的测量

    Ctrl+M 清除测量标签:点击右下角的清除按键