CodeForces546D:Soldier and Number Game(筛区间素数因子个数和)
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.
Example
2
3 1
6 3
2
5
题意:求A!/B!最多可以除多少次,即(B+1)*(B+2)...*A的乘积的素数分解个数。
思路:筛法得到所有数的分解素数个数,然后前缀和一下即可。
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
int p[maxn+],cnt,vis[maxn+],num[maxn+];
void choose()
{
for(int i=;i<=maxn;i++){
if(!vis[i]) p[++cnt]=i,num[i]=;
for(int j=;j<=cnt&&i*p[j]<=maxn;j++){
vis[i*p[j]]=,num[i*p[j]]=num[i]+;
if(i%p[j]==) break;
}
}
for(int i=;i<=maxn;i++) num[i]+=num[i-];
}
int main()
{
int a,b,T;
choose();
scanf("%d",&T);
while(T--){
scanf("%d%d",&a,&b);
printf("%d\n",num[a]-num[b]);
}
return ;
}
CodeForces546D:Soldier and Number Game(筛区间素数因子个数和)的更多相关文章
- codeforces Soldier and Number Game(dp+素数筛选)
D. Soldier and Number Game time limit per test3 seconds memory limit per test256 megabytes inputstan ...
- Easy Number Challenge(暴力,求因子个数)
Easy Number Challenge Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- HDOJ(HDU) 2521 反素数(因子个数~)
Problem Description 反素数就是满足对于任意i(0< i < x),都有g(i) < g(x),(g(x)是x的因子个数),则x为一个反素数.现在给你一个整数区间[ ...
- CodeForces-546D Soldier and Number Game 筛法+动态规划
题目链接:https://cn.vjudge.net/problem/CodeForces-546D 题意 抱歉,我给忘了,现在看题目又看不懂: P 思路 筛法+dp 话说这个函数应该是积性函数,然后 ...
- CodeForces 546 D. Soldier and Number Game(素数有关)
Description Two soldiers are playing a game. At the beginning first of them chooses a positive integ ...
- 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 J. Soldier and Number Game(素数筛)
题目描述: Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes inpu ...
- Help Hanzo (LightOJ - 1197) 【简单数论】【筛区间质数】
Help Hanzo (LightOJ - 1197) [简单数论][筛区间质数] 标签: 入门讲座题解 数论 题目描述 Amakusa, the evil spiritual leader has ...
- DP+埃氏筛法 Codeforces Round #304 (Div. 2) D. Soldier and Number Game
题目传送门 /* 题意:b+1,b+2,...,a 所有数的素数个数和 DP+埃氏筛法:dp[i] 记录i的素数个数和,若i是素数,则为1:否则它可以从一个数乘以素数递推过来 最后改为i之前所有素数个 ...
随机推荐
- 树莓派用gobot测试舵机的使用
package main import ( "gobot.io/x/gobot" "gobot.io/x/gobot/drivers/gpio" "g ...
- Fast I/O 模板
[来源:2017 Multi-University Training Contest - Team 1] //面包有毒:P #define BUF_SIZE 100000 //fread -> ...
- Mybatis详解
SqlSession(SqlSessionDaoSupport类) SqlSessionDaoSupportSqlSessionDaoSupport是一个抽象的支持类,用来为你提供SqlSession ...
- 问题:typedef char *pstring????
typedef char *pstring; const pstring cstr = 0; //cstr是指向char的常量指针: const pstring *ps; //ps是一个指针,它的对象 ...
- ExtNet配置webconfig
<?xml version="1.0" encoding="utf-8"?> <!-- 有关如何配置 ASP.NET 应用程序的详细信息,请访 ...
- LayUI后台管理与综合示例
一.LayUI介绍 layui(谐音:类UI) 是一款采用自身模块规范编写的前端 UI 框架,遵循原生 HTML/CSS/JS 的书写与组织形式,门槛极低,拿来即用.其外在极简,却又不失饱满的内在,体 ...
- K8S label 操作
在部署完成 node 节点集群之后,为了更灵活的操控 node 节点,有时候需要对 node 节点进行对各个 node 节点进行 lable 标签标记. 查看各个节点的信息 [root@porxy02 ...
- Base64的空格 + 问题...
BASE64 通过url传递到后台 加号变空格的处理方法 解决方法: 前台处理:str.replace("+", "%2B"); (错误) <scrip ...
- booth乘法器原理
在微处理器芯片中,乘法器是进行数字信号处理的核心,同一时候也是微处理器中进行数据处理的wd=%E5%85%B3%E9%94%AE%E9%83%A8%E4%BB%B6&hl_tag=textli ...
- IOS自己主动布局中的浮动布局(6)----MyFloatLayout横空出世
https://github.com/youngsoft/MyLinearLayout 前言 在MyLayout的6大布局中,每种布局都有不同的应用场景. 且每种布局的子视图的约束机制不一样:线性布局 ...