

两个士兵正在玩一个游戏,游戏开始的时候,第一个士兵为第二个士兵选一个正整数n。然后第二个士兵要玩尽可能多的轮数。每一轮要选择一个正整数x>1,且n要是x的倍数,然后用n/x去代替n。当n变成1的时候,游戏就结束了,第二个士兵所得的分数就是他玩游戏的轮数。
为了使游戏更加有趣,第一个士兵用 a! / b! 来表示n。k!表示把所有1到k的数字乘起来。
那么第二个士兵所能得到的最大分数是多少呢?
Input
单组测试数据。 第一行包含一个整数t (1 ≤ t ≤ 1,000,000),表示士兵玩游戏的次数。 接下来t行,每行包含两个整数a,b (1 ≤ b ≤ a ≤ 5,000,000)。
Output
对于每一组数据,输出第二个士兵能拿到的最多分数。
Input示例
2 3 1 6 3
Output示例
2 5
思路:其实就是b!....(a+1)!的每个数的素数个数
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=5000000; 4 int a[5000005]; 5 int prime[5000005]; 6 int read() 7 { 8 int x=0,f=1;char ch=getchar(); 9 while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 10 while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 11 return x*f; 12 } 13 void init() 14 { 15 a[1] = 0; 16 int pk=0; 17 for (int i = 2; i <=N; i++) 18 { 19 if (a[i] == 0) 20 { 21 prime[pk++] = i; 22 a[i] = 1; 23 } 24 for (int j = 0; j<pk&&i * prime[j] <=N; j++) 25 { 26 a[i * prime[j]] = a[i] + 1; 27 if (i % prime[j] == 0) 28 { 29 break; 30 } 31 } 32 } 33 for(int i=2;i<=N;i++) 34 a[i]+=a[i-1]; 35 return ; 36 } 37 38 39 int main(){ 40 init(); 41 int t; 42 cin>>t; 43 while(t--){ 44 int l,r; 45 r=read();l=read(); 46 printf("%d ",a[r]-a[l]); 47 } 48 return 0; 49 }