CodeForces 546D (质因子打表法)
来源:互联网 发布:上海期货交易软件下载 编辑:程序博客网 时间:2024/06/07 07:39
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
**题意:**a! / b! 后的数最多能除多少个数才能到 1
问你一个数最多能除多少次的时候就要用上质因子打表了~~~,再求出前缀和
#include <cstdio>#include <cstring>#define M 5000050#define LL long longbool isprime[M];LL num[M];void bymeter(){ memset(num, 0, sizeof(num)); memset(isprime, true, sizeof(isprime)); isprime[1] = false; for(int i=2; i<M; i++)//质因子打表 { if(isprime[i]) { for(int j=i; j<M; j+=i) { int temp = j; while(temp % i == 0) { temp /= i; num[j]++; } isprime[j] = false; } } } for(int i=1; i<M; i++)//求前缀和 { num[i] += num[i-1]; }}int main(){ int t, a, b; scanf("%d", &t); bymeter(); while(t--) { scanf("%d%d", &a, &b); printf("%lld\n", num[a] - num[b]); } return 0;}
- CodeForces 546D (质因子打表法)
- Codeforces 546D. Soldier and Number Game(找所有数质因子数量)
- codeforces-546D-Soldier and Number Game【思维】(求质因子个数)
- CodeForces 546D (求素因子个数)
- Codeforces 155D(分解质因子+预处理)
- codeforces 546D Soldier and Traveling(求一个数的质因子个数)
- Codeforces Round #304 (Div. 2) 546D Soldier and Number Game 质因子个数
- Codeforces-546D Soldier and Number Game 【质因子分解+打表+DP】
- CodeForces 546D Soldier and Number Game(求素因子+数学+前缀和)
- Codeforces 546D Soldier and Number Game【分解素因子+前缀和】
- Codeforces Round #338 (Div. 2) D. Multipliers (求因子积)
- Codeforces 632D Longest Subsequence 【求因子和变形】
- CodeForces 623B【质因子预处理+DP】
- codeforces 546D
- codeforces 546 D
- Codeforces#304-D - Soldier and Number Game-求因子个数/数学
- Codeforces Round #428 (Div. 2) B 细节 D gcd预处理因子+容斥
- codeforces 546D (数学 水)
- linux---我电脑把给ubuntu分区删了开机就是什么grub rescue怎么办
- 算法题:字符串分隔填充
- #98 Sort List
- Js中调用new方法生成对象的过程
- CentOS6.5 安装 Mysql
- CodeForces 546D (质因子打表法)
- iOS开发 - 屏幕适配之VFL语言
- Java 中 Comparable 和 Comparator 比较
- iOS之NSURLConnection
- 关于视频剪辑算法的简单实现
- STS设置在其他文档上使用HTML验证的方法
- Python快速学习第四天
- 史上最全最强SpringMVC详细示例实战教程
- Mysql 服务无法启动 的解决办法