Codeforces Round #304 (Div. 2) D. Soldier and Number Game 数学 质因数个数
2015-05-23 03:37
531 查看
D. Soldier and Number Game
Time Limit: 20 Sec Memory Limit: 256 MB题目连接
http://codeforces.com/contest/546/problem/DDescription
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.
[b]Output[/b]
For each game output a maximum score that the second soldier can get.
Sample Input
2 3 1 6 3
Sample Output
2 5
HINT
[b]题意 [/b]给你 a,b,求a到b的数的质因数个数和
[b]题解:[/b]
线性筛法,类似与dp的一种筛法
[b]代码:[/b]
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define maxn 5000001 #define mod 10007 #define eps 1e-9 int Num; char CH[20]; //const int inf=0x7fffffff; //нчоч╢С const int inf=0x3f3f3f3f; /* inline void P(int x) { Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts(""); } */ inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } inline void P(int x) { Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts(""); } //************************************************************************************** int cnt[maxn]; long long sum[maxn]; void init() { for(int i=2;i<maxn;i++) if(!cnt[i]) for(int j=i,c=1;j<maxn;j+=i,c++) { int t=c; while(1) { cnt[j]++; if (t%i) break; t/=i; } } for(int i=2;i<=maxn;i++) sum[i]=sum[i-1]+cnt[i]; } int main() { init(); int t,a,b; scanf("%d",&t); while(t--) { scanf("%d %d",&a,&b); printf("%d\n",sum[a]-sum[b]); } }
相关文章推荐
- D-Soldier and Number Game(CF546D) Codeforces Round #304 (Div. 2)
- Codeforces Round #304 (Div. 2) D. Soldier and Number Game
- Codeforces Round #304 (Div. 2) D. Soldier and Number Game(筛选素因子,前缀和)
- Codeforces#304-D - Soldier and Number Game-求因子个数/数学
- Codeforces Round #304 (Div. 2)-D. Soldier and Number Game,素因子打表!
- Codeforces Round #304 (Div. 2) D. Soldier and Number Game 数论 筛表法
- Codeforces Round #304 (Div. 2)D. Soldier and Number Game
- Codeforces Round #304 (Div. 2)——D素数筛+dp——Soldier and Number Game
- 数学+DP Codeforces Round #304 (Div. 2) D. Soldier and Number Game
- CodeForces 828D Soldier and Number Game(数学)
- DP+埃氏筛法 Codeforces Round #304 (Div. 2) D. Soldier and Number Game
- Codeforces Round #304 (Div. 2) D - Soldier and Number Game
- Codeforces Round #304 (Div. 2) D Soldier and Number Game
- [Codeforces546D]Soldier and Number Game[dp][实现][素数筛][分解整数][数学]
- Codeforces Round #304 (Div. 2) D. Soldier and Number Game
- Soldier and Number Game
- Codeforces Round #228 (Div. 2)A.Fox and Number Game
- 【codeforces 546D】Soldier and Number Game
- 【CodeForces】546D - Soldier and Number Game(线性筛法)
- Codeforces Round #228 (Div. 2), problem: (A) Fox and Number Game