Codeforces Round #304 (Div. 2) D. Soldier and Number Game
2015-06-03 16:20
309 查看
题意: a! / b!里的质因子个数
素数筛预处理+记录前缀和
D. Soldier and Number Game
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 test(s)
Input
Output
素数筛预处理+记录前缀和
D. Soldier and Number Game
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 test(s)
Input
2 3 1 6 3
Output
2 5
#include <map> #include <set> #include <queue> #include <stack> #include <vector> #include <string> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> #include <algorithm> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 #define ls rt << 1 #define rs rt << 1 | 1 #define pi acos(-1.0) #define eps 1e-8 #define asd puts("sdfsdfsdfsdfsdfsdf"); typedef long long ll; typedef __int64 LL; const int inf = 0x3f3f3f3f; const int N = 5000010; int pri ; void init() { pri[1] = pri[2] = 0; for( int i = 2; i <= N-1; ++i ) { if( !pri[i] ) { for( int j = i; j <N-2; j += i ) { pri[j] = pri[j/i]+1; } } } for( int i = 2; i <= N; ++i ) pri[i] += pri[i-1]; } int main() { int a, b, tot; init(); for( scanf("%d", &tot); tot--; ) { scanf("%d%d", &a, &b); printf("%d\n", pri[a] - pri[b]); } return 0; }
相关文章推荐
- 安卓手机连接蓝牙打印机实现打印功能 (转载)
- WTL 通过IWebBrowser2接口使WebBrowser控件在自己的窗口打开网页
- <转帖>GCD 深入理解:第二部分
- 【Android笔记】EditText密码框中字体和普通输入框不同
- JAX-WS WebService发布
- eclipse设置文件默认打开方式
- Android DrawerLayout 抽屉
- PowerDesigner使用教程
- (转)UIWebView的基本用法
- JFinal调用Mysql存储过程方法
- oracle数据泵的备份与恢复
- Android 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果 (转载)
- 微博转发的内容如何实现点击人名跳转到个人主页
- 什么是数据库引擎
- <转帖>GCD 深入理解:第一部分
- python中的enumerate学习
- iOS错误堆栈查找崩溃原因的方法
- opencv源码解读读书笔记:负样本的有关源代码
- robotium常用API
- 设计模式之原型模式