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

CodeForces 546 D. Soldier and Number Game(素数有关)的更多相关文章

  1. Codeforces Round #304 (Div. 2) D. Soldier and Number Game 素数打表+质因数分解

    D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input s ...

  2. 【codeforces 546D】Soldier and Number Game

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

  3. Codeforces D546:Soldier and Number Game

    题目链接 输入t对数 a, b 求(b,a]内的每个数拆成素因子的个数和 这里每个数都可以写成素数的乘积,可以写成几个素数的和就有几个素因子,这里求的是(b,a]内的素因子和 思路: 素数的素因子个数 ...

  4. codeforces Soldier and Number Game(dp+素数筛选)

    D. Soldier and Number Game time limit per test3 seconds memory limit per test256 megabytes inputstan ...

  5. Codeforces J. Soldier and Number Game(素数筛)

    题目描述: Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes inpu ...

  6. Codeforces Round #304 (Div. 2) D. Soldier and Number Game 数学 质因数个数

    D. Soldier and Number Game Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  7. DP+埃氏筛法 Codeforces Round #304 (Div. 2) D. Soldier and Number Game

    题目传送门 /* 题意:b+1,b+2,...,a 所有数的素数个数和 DP+埃氏筛法:dp[i] 记录i的素数个数和,若i是素数,则为1:否则它可以从一个数乘以素数递推过来 最后改为i之前所有素数个 ...

  8. Codeforces Round #304 (Div. 2)-D. Soldier and Number Game,素因子打表,超时哭晕~~

    D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input s ...

  9. 数学+DP Codeforces Round #304 (Div. 2) D. Soldier and Number Game

    题目传送门 /* 题意:这题就是求b+1到a的因子个数和. 数学+DP:a[i]保存i的最小因子,dp[i] = dp[i/a[i]] +1;再来一个前缀和 */ /***************** ...

随机推荐

  1. java抽象类的特点

    抽象类 抽象类的特点: 1.抽象类的方法可以是抽象的,也可以是不抽象的. 2.抽象类的方法可以全是抽象的,也可以全是不抽象的. 3.有抽象方法的类必须是抽象类,或者是接口(但是接口的方法定义必须是pu ...

  2. PureLayout

    PureLayout 是 iOS & OS X Auto Layout 的终极 API——非常简单,又非常强大.PureLayout 通过一个全面的Auto Layout API 扩展了 UI ...

  3. drupal中安装CKEditor文本编辑器,并配置图片上传功能

    一.下载: 1.CKEditor模块 2.IMCE模块 二.安装       1.复制: 下载完上面两个模块之后,解压,将解压后整个文件夹,复制粘贴,放到 sites\all\modules下面,个人 ...

  4. Docker: Usage instruction

    Install docker from official site, in windows. or install docker from repo as official site told, in ...

  5. 瑞游天翼客户端win7,win8,win10

    以管理员身份运行即可, 链接: http://pan.baidu.com/s/1kTw7VH9 密码: vttq

  6. 第四十一节,xml处理模块

    XML是实现不同语言或程序之间进行数据交换的协议,XML文件格式如下 读xml文件 <data> <country name="Liechtenstein"> ...

  7. Java中String转换Double类型 Java小数点后留两位

    Java中String转换Double类型 double num1 = 0.0; String qq = "19.987"; num1 = Double.valueOf(qq.to ...

  8. js获取不同浏览器盒子宽度高度

    DTD 已声明 IE document.documentElement.scrollHeight 浏览器所有内容高 度 ,document.body.scrollHeight 浏览器所有内容高度 do ...

  9. javascript: 字符串拼接有问题

    点击某个链接,出现js错误:Uncaught SyntaxError: Unexpected token ILLEGAL 原因: $str .= sprintf('&nbsp&nbsp ...

  10. MinGW 运行C++程序的方法

    1:安装好 MinGW 及 GCC 编译器后 , 当然 MinGW 全安装最保险了,不会太费劲 2:配置环境变量(注:可能需要重启后生效) 计算机 --> 属性 --> 高级系统设置 -- ...