Codeforces Round #304 (Div. 2) D. Soldier and Number Game

本文深入探讨了游戏开发和大数据开发领域的核心技术,包括游戏引擎、AI音视频处理、大数据平台等关键组件和应用实例,旨在为开发者提供深入的技术理解和实践指导。

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

 

题目大意:

 

有两个士兵在玩一个游戏,游戏规则是这样的:第一个士兵选择一个数n,然后第二个士兵每次可以任选除了1并且整除n的数字x,并且每选一次数字,n就约掉一个x,直到n1则游戏结束,问最多能选几次x。并且n等于给定的a! / b!

 

大致思路:

 

一开始看到n等于a! / b! ,而且1 ≤ b ≤ a ≤ 5000000 ,立马认为是(对于我)不可做题。后来又看到那么多人过,才重新看了下题,发现其实并不需要算出n。题目其实就是求n的质因子个数有多少个。而n又等于a! / b!,推一下就可以知道,n的质因子个数等于a的质因子个数减掉b的质因子个数。然后问题就转换成求出1~5000000所有数的质因子个数,可以用埃式筛法来做,加一点处理就可以了。算法复杂度大约是O(n)

 

埃式筛法:

 

const int maxn = 5000000 + 10;
int prime[maxn];
bool is_prime[maxn];
void sieve()
{
	fill(is_prime, is_prime+maxn, 1);
	is_prime[0] = is_prime[1] = false;
	int ans = 0;
	for( int i=2; i<maxn; ++i )
	{
		if( is_prime[i] )
		{
			prime[ans++] = i;
			for( int j=i*2; j<maxn; j+=i )
			{
				is_prime[j] = false;
			}
		}
	}
	return ;
}


两种解法(其实原理是一样的):

ps:总体的时间复杂度并没有差多少,前面这种稍微快一点。

//CF_394_D.cpp
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 5000000 + 10;
ll primeFactors[maxn];
int primeDiviser[maxn];
bool is_prime[maxn];
void sieve()
{
	fill(is_prime, is_prime+maxn, 1);
	is_prime[0] = is_prime[1] = 0;
	for( int i=2; i<maxn; i++ )
	{
		if( is_prime[i] )
		{
			primeDiviser[i] = i;
			for( int j=2*i; j<maxn; j+=i )
			{
                primeDiviser[j] = i;
				is_prime[j] = false;
			}
		}
	}
	for( int i=2; i<maxn; i++ )
		primeFactors[i] = primeFactors[i / primeDiviser[i]] + 1;
	for( int i=2; i<maxn; i++ )
		primeFactors[i] += primeFactors[i-1];
	return ;
}

int main()
{
	sieve();
	int T;
	scanf("%d", &T);
	int a, b;
	while( T-- )
	{
		scanf("%d %d", &a, &b);
		printf("%I64d\n", primeFactors[a]-primeFactors[b]);
	}

	return 0;
}


//CF_394_D.cpp
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 5000000 + 10;
ll s[maxn], k[maxn];
bool is_prime[maxn];
void sieve()
{
	fill(is_prime, is_prime+maxn, 1);
	memset(k, 0, sizeof(k));
	is_prime[0] = is_prime[1] = 0;
	for( int i=2; i<maxn; i++ )
	{
		if( is_prime[i] )
		{
			k[i]++;
			for( int j=2*i; j<maxn; j+=i )
			{
				int cnt = 0, ans = j;
				while( !(ans%i) )
                {
                    ans /= i;
                    k[j]++;
                }
				is_prime[j] = false;
			}
		}
	}
	return ;
}
void solve()
{
	sieve();
	for( int i=1; i<=maxn; i++ )
	{
		s[i] = k[i] + s[i-1];
	}
}
int main()
{
	solve();
	int T;
	scanf("%d", &T);
	int a, b;
	while( T-- )
	{
		scanf("%d %d", &a, &b);
		printf("%I64d\n", s[a]-s[b]);
	}

	return 0;
}


内容概要:本文档是一份关于交换路由配置的学习笔记,系统地介绍了网络设备的远程管理、交换机与路由器的核心配置技术。内容涵盖Telnet、SSH、Console三种远程控制方式的配置方法;详细讲解了VLAN划分原理及Access、Trunk、Hybrid端口的工作机制,以及端口镜像、端口汇聚、端口隔离等交换技术;深入解析了STP、MSTP、RSTP生成树协议的作用与配置步骤;在路由部分,涵盖了IP地址配置、DHCP服务部署(接口池与全局池)、NAT转换(静态与动态)、静态路由、RIP与OSPF动态路由协议的配置,并介绍了策略路由和ACL访问控制列表的应用;最后简要说明了华为防火墙的安全区域划分与基本安全策略配置。; 适合人群:具备一定网络基础知识,从事网络工程、运维或相关技术岗位1-3年的技术人员,以及准备参加HCIA/CCNA等认证考试的学习者。; 使用场景及目标:①掌握企业网络中常见的交换与路由配置技能,提升实际操作能力;②理解VLAN、STP、OSPF、NAT、ACL等核心技术原理并能独立完成中小型网络搭建与调试;③通过命令示例熟悉华为设备CLI配置逻辑,为项目实施和故障排查提供参考。; 阅读建议:此笔记以实用配置为主,建议结合模拟器(如eNSP或Packet Tracer)动手实践每一条命令,对照拓扑理解数据流向,重点关注VLAN间通信、路由选择机制、安全策略控制等关键环节,并注意不同设备型号间的命令差异。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值