Description

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.

Sample Input
Input Output

题目链接:http://codeforces.com/problemset/problem/546/D

********************************************

分析:用到一个公式

primefactors[a] = primefactors[a / primediviser[a]] + 1,

primefactor[a]表示a因数中素数的个数。

只要把a,b的primefactor[]算出来,减一下就行了。

AC代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
using namespace std; #define N 5000000
#define INF 0x3f3f3f3f int c[N]; void p()
{
memset(c,,sizeof(c));
int i,j;
for(i=;i<=N;i++)
{
if(c[i]==)
{
for(j=;j*i<=N;j++)
c[j*i]=c[j]+;
}
}
for(i=;i<=N;i++)
c[i]+=c[i-];
} int main()
{
int T,a,b;
p();
scanf("%d", &T); while(T--)
{
scanf("%d%d", &a,&b);
printf("%d\n", c[a]+a-c[b]-b);
}
return ;
}

最新文章

  1. EasyPR--开发详解(6)SVM开发详解
  2. windows server 2012 r2 远程桌面连接指南
  3. [POJ2420]A Star not a Tree?(模拟退火)
  4. Windows Driver Frameworks
  5. 一个ORM的实现(附源代码)
  6. ThinkPHP框架表单验证
  7. Reactor模式详解
  8. C++位操作符总结
  9. vitrualbox虚拟机64位安装报错解决
  10. seajs常用API整理
  11. The requested page cannot be accessed because the related configuration data for the page is invalid
  12. Unix,windows和Mac中的换行
  13. emeditor 配置教程
  14. (1)Two Sum--求数组中相加为指定值的两个数
  15. zoj 1539 Lot 简单DP 记忆化
  16. CentOS 5.x 多个ISO文件 安装方法(VMware)
  17. [Codeforces 940E]Cashback
  18. iOS 图片裁剪与修改
  19. Git漏洞允许任意代码执行(CVE-2018-17456)复现
  20. UGUI合批原理笔记

热门文章

  1. G - 小晴天老师系列——可恶的墨水瓶
  2. SPI模式下MCU对SD卡的控制及操作命令(转)
  3. js导入的注意.txt
  4. HDU 5778 abs
  5. HDU 5777 domino
  6. VBS获取Ini配置文件一个节点下的所有字段的值
  7. IP相关常识
  8. linux中iptables配置文件及命令详解详解
  9. Chapter 2 Open Book——20
  10. 百度地图与融云的“冲突”(APP的.so手机架构目录,与Library的.so的手机架构目录冲突)