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
Give a n,n start is a!/b!, each time with an X to divide N to get a new N, and finally when N becomes 1 after a few rounds of scoring is the number of rounds, the maximum score is required
Ideas:
Obviously, is a question of the number of integer factors, factorial we do not need to calculate, we know that in the a>b time, the b! are about to drop, then we just have to pressure calculate each number of the qualitative factor has a few, and then calculate the 1~n of the quality factor of the sum, then you can quickly get the answer
#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];//How many prime factor bool V[n] per number; Whether it is a prime number int a[n];//the smallest prime factor int prime[n/10];//primes table 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;}
Codeforces546d:soldier and Numbers Game (number of qualitative factors)