D-soldier and number Game (cf546d) codeforces Round #304 (Div. 2)

Source: Internet
Author: User

D. Soldier and number Game

The soldiers is playing a game. At the beginning first of them chooses a positive integerNand 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 thatNis divisible byxand replacingNWith n?/? x . WhenNbecomes equal to1And there is no more possible valid moves the game was over and the score of the second soldier are equal to the number of R Ounds he performed.

The game more interesting, first soldier choosesNof form a!? /? b!For some positive integeraandb( a? ≥? b ). Here by k!We denote thefactorialOfkThat's defined as a product of all positive integers not large thank.

What is the maximum possible score of the second soldier?

Input

Fir St 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
23 16 3
Output
25
Test instructions: n=a! /b! Ask you the number of prime factors of N.
Train of thought: Prime number dozen table;
Reprint Please specify the Source:  looking for children & stars
Title Link: 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 M od = 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.