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

D. Soldier and Number Game

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
 
   
题意:n=a!/b!问你n的素数因子的个数。

思路:素数打表;

转载请注明出处:寻找&星空の孩子

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

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <list>
#include <algorithm>
#include <climits>
using namespace std;

#define lson 2*i
#define rson 2*i+1
#define LS l,mid,lson
#define RS mid+1,r,rson
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define LL long long
#define N 5000005
#define INF 0x3f3f3f3f
#define EXP 1e-8
#define lowbit(x) (x&-x)
const int mod = 1e9+7;
int p[N];
bool v[N]; 
int a[N];
int prime[N/10];
LL sum[N];
void init()
{
    for(int i=2; i<N; ++i)
        a[i] = i;
    int num=-1;
    for(int i=2; i<N; ++i)
    {
        if(!v[i]) prime[++num] = i;
        for(int j=0; j<=num && i*prime[j] < N; ++j)
        {
            int t = i*prime[j];
            v[t] =1;
            if(a[t] > prime[j]) a[t] = prime[j];
            if(i%prime[j] == 0) break;
        }
    }
    p[2] = 1;
    for(int i=3; i <N; ++i)
        p[i] = p[i/a[i]] + 1;
}
int main()
{
    int i,j,k;
    init();
    sum[1] = 0;
    for(i = 2; i<=5000000; i++)
    {
        sum[i] = sum[i-1]+p[i];
    }
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&i,&j);
        if(i == j)
            printf("0\n");
        else
            printf("%I64d\n",sum[i]-sum[j]);
    }

    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值