码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-06-18 19:49:48      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:soldier and number g   cf546d   codeforces round #30   素数个数   

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


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

标签:soldier and number g   cf546d   codeforces round #30   素数个数   

原文地址:http://blog.csdn.net/u010579068/article/details/46550343

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!