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.

Examples
Input
2
3 1
6 3
Output
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 素数打表+质因数分解的更多相关文章

  1. DP+埃氏筛法 Codeforces Round #304 (Div. 2) D. Soldier and Number Game

    题目传送门 /* 题意:b+1,b+2,...,a 所有数的素数个数和 DP+埃氏筛法:dp[i] 记录i的素数个数和,若i是素数,则为1:否则它可以从一个数乘以素数递推过来 最后改为i之前所有素数个 ...

  2. 数学+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;再来一个前缀和 */ /***************** ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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, 问你最多可以操作多少次 ...

  7. queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards

    题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...

  8. 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges

    题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...

  9. 水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas

    题目传送门 /* 水题:ans = (1+2+3+...+n) * k - n,开long long */ #include <cstdio> #include <algorithm ...

随机推荐

  1. Salty Fish(区间和)

    Problem 2253 Salty Fish Accept: 35    Submit: 121Time Limit: 1000 mSec    Memory Limit : 32768 KB Pr ...

  2. 新手之使用git

    本篇博客针对不会Git的小童鞋,大神们可以绕过,错误之处谢谢指正: 关于GitHub的强大此处不在说明,知道GitHub也有一段时间了,但是一直苦于不会使用. 本篇文章介绍的是如何将工程代码托管到上面 ...

  3. python系列五:Python3列表list

    #!usr/bin/python#-*-coding:gbk-*-#列表list'''可以看到a b c 三个是同一id值,当改变当中任一列表元素的值后,三者会同步改变.但d的元素值不会变,改变d的元 ...

  4. XShell安装(五)

    Xshell就是一个远程控制Centos的软件:(用XShell比较方便,试用的都知道,界面也人性化) 详细介绍请看 百度百科 我随便百度下载了一个中文版的 给下地址  http://rj.baidu ...

  5. js验证表单大全3

    2 >表单提交验证类  2.1 表单项不能为空 <scriptlanguage="javascript"> <!-- function CheckForm( ...

  6. django实现密码加密的注册(数据对象插入)-结合forms表单实现表单验证

    forms表单 #_*_coding:utf-8_*_ from django import forms class regis(forms.Form): username = forms.CharF ...

  7. Docker容器/镜像查看及删除操作

    列出所有正在运行的容器 docker ps 暂停容器 docker stop <name> 删除容器 docker rm <name> 停止所有container docker ...

  8. python面试题(五)

    1 谈谈你对面向对象的理解? 面向对象的编程---object oriented programming,简称:OOP,是一种编程的思想.OOP把对象当成一个程序的基本单元,一个对象包含了数据和操作数 ...

  9. 2.2 使用ARDUINO控制MC20发短信

    需要准备的硬件 MC20开发板 1个 https://item.taobao.com/item.htm?id=562661881042 GSM/GPRS天线 1根 https://item.taoba ...

  10. "深入理解C语言" 指针

    本文对coolshell中的"深入理解C语言"这篇文章中提到的指针问题, 进行简要的分析. #include <stdio.h> int main(void){ ]; ...