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. chapter11_3 字符串缓冲

    逐行地读取一个文件,典型的代码是: local buff= " " for line in io.lines() do buff = buff .. line .. "\ ...

  2. MATLAB将变量存储到EXCEL

    代码如下: d = {'Time','Temperature'; 12,98; 13,99; 14,97}; xlswrite('testdata2.xls', d, 1, 'E1') 运行如下:

  3. 第四题 (List)写一个函数reverseList,该函数能够接受一个List,然后把该List 倒序排列。 例如:  List list = new ArrayList();  list.add(“Hello”);  list.add(“World”);  list.add(“Learn”); //此时list 为Hello World Learn  r

    package zuoye; import java.util.ArrayList; import java.util.List; public class Reverse01 { public st ...

  4. nginx: 响应体太大

    如果做proxy,可以将proxy配置修改buffer长度,或者直接关闭buffer.http { proxy_buffer_size 128k; proxy_buffers 4 256k; prox ...

  5. linux下ClamAV使用

    第一步:Clamav下载http://www.clamav.net/downloads#yuminstall wget –y第二步:创建clamav用户和组groupaddclamav   (创建cl ...

  6. C++ 空类默认产生的类成员函数

    C++的空类有哪些成员函数:. 缺省构造函数.. 缺省拷贝构造函数.. 缺省析构函数.. 缺省赋值运算符.. 缺省取址运算符.. 缺省取址运算符 const.     注意:有些书上只是简单的介绍了前 ...

  7. Apriori算法-java

    package com.yang; import java.util.*; public class Apriori { private double minsup = 0.2;// 最小支持度   ...

  8. C# var 隐式类型 var 用法 特点

    var 关键字是C# 3.0 开始,在方法范围中声明的变量: var有以下特点: * 1.var在编译器编译的时候根据初始值推断出其的类型          * 2.不能赋值除了初始值类型之外的其他类 ...

  9. Chapter 1 First Sight——36

    The door opened again, and the cold wind suddenly gusted through the room, rustling the papers on th ...

  10. Eclipse的WorkingSet使用(转载)

    Eclipse作为一款流行的JavaIDE开发工具,其有很多好用的功能为我们的开发提供帮助.但我们的工作空间中有很多项目时,管理起来就很头疼了. 但是我们又不想更换工作区间,所以我们需要一个更加有效的 ...