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
题意:有t 组,每组有两个数 a, b, 求a ~ b+1所有数的质因子总和;
例如 a = 6, b = 3, 那么 结果 = 2(4=2*2) + 1(5=5) + 2(6=2*3) = 5
先把 1~ N 所有数的质因子都算出来,再求一下前缀和就可以了,打表打一下就好了。
代码如下:
#include<cstdio>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
using namespace std;
const int N = 5000;
queue<int>p;
queue<int>q;
int vis[N][N], ans;
void init()
{
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
vis[i][j] = 0;
}
ans = 0;
}
int main()
{
int n = 0, h1 = 0, h2 = 0;
int k1, k2, a, b;
while(~scanf("%d", &n))
{
while(!p.empty()) p.pop();
while(!q.empty()) q.pop();
scanf("%d", &k1);
for(int i = 1; i <= k1; i++)
{
scanf("%d", &a);
p.push(a);
h1 = h1 * 10 + a;
}
scanf("%d", &k2);
for(int i = 1; i <= k2; i++)
{
scanf("%d", &b);
q.push(b);
h2 = h2 * 10 + b;
}
init();
while(1)
{
int u = p.front(); p.pop();
int v = q.front(); q.pop();
ans++;
if(u > v)
{
p.push(v);
p.push(u);
}
else
{
q.push(u);
q.push(v);
}
if(p.size() == 0)
{
printf("%d 2\n", ans);
break;
}
if(q.size() == 0)
{
printf("%d 1\n", ans);
break;
}
if(ans > 10000000)
{
printf("-1\n"); break;
}
}
}
return 0;
}
本文深入探讨了游戏开发领域的核心技术,包括游戏引擎、动画、视觉特效等,为开发者提供全面的技术指南。

748

被折叠的 条评论
为什么被折叠?



