Description
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 Input
Input 2 3 1 6 3 Output 2 5 虽然做出来了,但用了一个多小时时间思考,过后想想其实思路很简单的,还是自己太渣,唉 这道题其实是还是用到了素数筛选的思想,注意打表就行了,不然会超时,详细见代码: #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #define N 5000100 #define INF 999999999 using namespace std; int a[N],f[N]; void flag() { int i,j; for(i=1; i<=N; i++) a[i]=1; int m=sqrt(N); for(i=2; i<=m; i++)//这里注意循环到根号N就行了; for(j=i*i; i<=N; j+=i)//按照倍数进行筛选,类似素数筛选的方法 { if(j>N) break; a[j]=a[i]+a[j/i];//这里是关键 } int sum=0; for(i=1;i<=N;i++)//注意这里将和打表,不要一个个的进行循环计算,会超时的; { sum+=a[i]; f[i]=sum; } } int main() { int m,n,t,ans; flag(); scanf("%d",&t); while(t--) { ans=0; scanf("%d%d",&n,&m);//(n!/m!等于n*(n-1)*(n-2)*.....*m+1) ans=f[n]-f[m];//ans等于f[n]-f[m+1-1]; printf("%d\n",ans); } return 0; }