您的位置:首页 > 其它

Codeforces Round #304 (Div. 2) D. Soldier and Number Game

2015-06-03 16:20 309 查看
题意: a! / b!里的质因子个数

素数筛预处理+记录前缀和

D. Soldier and Number Game

time limit per test
3 seconds

memory limit per test
256 megabytes

input
standard input

output
standard 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.

Sample test(s)

Input
2
3 1
6 3


Output
2
5


#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>

using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define ls rt << 1
#define rs rt << 1 | 1
#define pi acos(-1.0)
#define eps 1e-8
#define asd puts("sdfsdfsdfsdfsdfsdf");
typedef long long ll;
typedef __int64 LL;
const int inf = 0x3f3f3f3f;
const int N = 5000010;

int pri
;

void init()
{
    pri[1] = pri[2] = 0;
    for( int i = 2; i <= N-1; ++i ) {
        if( !pri[i] ) {
            for( int j = i; j <N-2; j += i ) {
                pri[j] = pri[j/i]+1;
            }
        }
    }
    for( int i = 2; i <= N; ++i )
        pri[i] += pri[i-1];
}

int main()
{
    int a, b, tot;
    init();
    for( scanf("%d", &tot); tot--; ) {
        scanf("%d%d", &a, &b);
        printf("%d\n", pri[a] - pri[b]);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: