CodeForces-546D.Soldier and Number Game
2016-07-24 22:44
211 查看
D. Soldier and Number Game time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard 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.
Examples
input
2
3 1
6 3
output
2
5
#include<iostream> #include<cmath> #include<cstdio> using namespace std; #define N 5000000 int sum[N+2]; int Prime(int m)//求出m的一个因子 { double a = sqrt((double)m); for (int i = 2; i <= a; i++) { if (m%i == 0) return i; } return 0; } void Init() { sum[1] = 0; int a, b; for (int i = 2; i <= N; i++) { a = Prime(i); if (a != 0) { b = i / a; sum[i] = sum[a] + sum[b]; }//i一定大于a和b,i的因子数目为a和b的因子数目总和 else sum[i] = 1; } for (int j = 2; j <= N; j++) sum[j] = sum[j] + sum[j - 1]; } int main() { Init(); int t, a, b; scanf("%d", &t); while (t--) { scanf("%d%d", &a, &b); printf("%d\n", sum[a] - sum[b]); } return 0; }
相关文章推荐
- 简单的四则运算
- 数的奇偶性
- ACMer博客瀑布流分析
- 【CF 应用开发大赛】MZCMS内容管理系统
- ACM程序设计大赛题目分类
- 2015年acm国内排名
- 计算字符串最后一个单词长度
- win7系统登录cf穿越火线出现atl71错误的解决方法
- Win7系统登录CF不能选区怎么办?Win7系统登录CF穿越火线没显示选区界面的解决方法
- ACM网址
- 1272 小希的迷宫
- 1272 小希的迷宫
- hdu 1250 大数相加并用数组储存
- windows 7 玩不了CF 打开之后进入安全登录就自动关闭
- 矩阵的乘法操作
- 蚂蚁爬行问题
- 蚂蚁爬行问题
- 求两个数的最大公约数【ACM基础题】
- 打印出二进制中所有1的位置
- 杭电题目---一只小蜜蜂