Codeforces Round #304 (Div. 2) D. Soldier and Number Game 素数打表+质因数分解
3 seconds
256 megabytes
standard input
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?
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.
For each game output a maximum score that the second soldier can get.
2
3 1
6 3
2
5
题意:求[b+1,a]区间内的所有数质因数分解的得到的的质数个数;
思路:素数打表+质因数分解求前缀和,这题nsqrt(n)不知道能不能过;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define esp 1e-10
const int N=1e6+,M=1e6+,mod=1e9+,inf=1e9+;
const int MAXN=;
int prime[MAXN];
bool vis[MAXN];
int sum[MAXN];
int Prime(int n)
{
int cnt=;
memset(vis,,sizeof(vis));
for(int i=;i<n;i++)
{
if(!vis[i])
prime[cnt++]=i;
for(int j=;j<cnt&&i*prime[j]<n;j++)
{
vis[i*prime[j]]=;
if(i%prime[j]==)
break;
}
}
return cnt;
}
int main()
{
int x,y,z,i,t;
int cnt=Prime(MAXN);
for(i=;i<MAXN;i++)
{
int flag=i;
for(t=;t<cnt;t++)
{
if(flag==)
break;
if(!vis[flag])
{
sum[i]++;
break;
}
while(flag%prime[t]==)
{
flag/=prime[t];
sum[i]++;
}
}
sum[i]+=sum[i-];
}
int T;
scanf("%d",&T);
while(T--)
{
int a,b;
scanf("%d%d",&a,&b);
printf("%d\n",sum[a]-sum[b]);
}
return ;
}
Codeforces Round #304 (Div. 2) D. Soldier and Number Game 素数打表+质因数分解的更多相关文章
- DP+埃氏筛法 Codeforces Round #304 (Div. 2) D. Soldier and Number Game
题目传送门 /* 题意:b+1,b+2,...,a 所有数的素数个数和 DP+埃氏筛法:dp[i] 记录i的素数个数和,若i是素数,则为1:否则它可以从一个数乘以素数递推过来 最后改为i之前所有素数个 ...
- 数学+DP Codeforces Round #304 (Div. 2) D. Soldier and Number Game
题目传送门 /* 题意:这题就是求b+1到a的因子个数和. 数学+DP:a[i]保存i的最小因子,dp[i] = dp[i/a[i]] +1;再来一个前缀和 */ /***************** ...
- Codeforces Round #304 (Div. 2) D. Soldier and Number Game 数学 质因数个数
D. Soldier and Number Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...
- Codeforces Round #304 (Div. 2) D - Soldier and Number Game
D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #304 (Div. 2)-D. Soldier and Number Game,素因子打表,超时哭晕~~
D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #304 (Div. 2)(CF546D) Soldier and Number Game(线性筛)
题意 给你a,b(1<=b<=a<=5000000)表示a!/b!表示的数,你每次可以对这个数除以x(x>1且x为这个数的因子)使他变成a!/b!/x, 问你最多可以操作多少次 ...
- queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards
题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...
- 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges
题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...
- 水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas
题目传送门 /* 水题:ans = (1+2+3+...+n) * k - n,开long long */ #include <cstdio> #include <algorithm ...
随机推荐
- iframe脸面的页面和父页面之间的交互方法
1.iframe父页面修改iframe中的页面的信息 var obj = document.getElementById("iframeId").contentWindow; ...
- Machine Learning - week 2 - Multivariate Linear Regression
Multiple Features 上一章中,hθ(x) = θ0 + θ1x,表示只有一个 feature.现在,有多个 features,所以 hθ(x) = θ0 + θ1x1 + θ2x2 + ...
- 使用QFuture类监控异步计算的结果
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Amnes1a/article/details/65630701在Qt中,为我们提供了好几种使用线程的 ...
- Python3.6全栈开发实例[024]
24.文件a1.txt内容(注意每行中的空格是不一样的,需要对空格进行处理)序号 部门 人数 平均年龄 备注 1 python 30 26 单身狗 2 Linu ...
- Scilab 的画图函数(2)
一幅图是由很多元素组成的. 包含图标题.x轴标签.y轴标签,刻度线等.图1给出了各个元素的一个示意图. 这些全部的元素在scilab中都是能够用代码控制的. 标题 上个笔记上介绍了用xtitle()函 ...
- SQL2008 R2直接恢复 mdf后缀数据文件
数据库默认存储地址为 C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA ,那么我首先把朋友给的,md ...
- ABAP rfc 发布webservice 错误
一.SICF 测试服务报错: 哎呀,找不到网页! 网站在检索此网址时出现错误.托管此网站的服务器可能关闭进行维护或配置不正确. HTTP ERROR 500
- Python进阶(3)_进程与线程中的lock(线程中互斥锁、递归锁、信号量、Event对象、队列queue)
1.同步锁 (Lock) 当全局资源(counter)被抢占的情况,问题产生的原因就是没有控制多个线程对同一资源的访问,对数据造成破坏,使得线程运行的结果不可预期.这种现象称为“线程不安全”.在开发过 ...
- input propertychange(1)
input type=“text” 通过js改变输入框的value值是不会出发input propertychange事件
- 十位用户唯一ID生成策略
新浪微博和twitter 等系统都有一窜数字ID来标示一个唯一的用户,这篇文章就是记录如何实现这种唯一数字ID 原理:使用MYSQL 自增ID 拼接任意字符..然后使用进制转换打乱规则 一般来说实现唯 ...