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

Input
2
3 1
6 3
Output
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(筛区间素数因子个数和)的更多相关文章

  1. codeforces Soldier and Number Game(dp+素数筛选)

    D. Soldier and Number Game time limit per test3 seconds memory limit per test256 megabytes inputstan ...

  2. Easy Number Challenge(暴力,求因子个数)

    Easy Number Challenge Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  3. HDOJ(HDU) 2521 反素数(因子个数~)

    Problem Description 反素数就是满足对于任意i(0< i < x),都有g(i) < g(x),(g(x)是x的因子个数),则x为一个反素数.现在给你一个整数区间[ ...

  4. CodeForces-546D Soldier and Number Game 筛法+动态规划

    题目链接:https://cn.vjudge.net/problem/CodeForces-546D 题意 抱歉,我给忘了,现在看题目又看不懂: P 思路 筛法+dp 话说这个函数应该是积性函数,然后 ...

  5. CodeForces 546 D. Soldier and Number Game(素数有关)

    Description Two soldiers are playing a game. At the beginning first of them chooses a positive integ ...

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

  7. Codeforces J. Soldier and Number Game(素数筛)

    题目描述: Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes inpu ...

  8. Help Hanzo (LightOJ - 1197) 【简单数论】【筛区间质数】

    Help Hanzo (LightOJ - 1197) [简单数论][筛区间质数] 标签: 入门讲座题解 数论 题目描述 Amakusa, the evil spiritual leader has ...

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

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

随机推荐

  1. LINUX下面NetworkManager和network冲突的问题

    https://blog.csdn.net/ID_EAGLE/article/details/74085409

  2. I.Tower Defense

    给你p个重塔,q个轻塔,把这些塔放在n*m的图中,这些塔会相互攻击同行同列的,轻塔不能受到攻击,重塔能承受一个塔的攻击, 问放的方法数. 先假定n < m. 可以先枚举放轻塔的个数为s,显然,方 ...

  3. 洛谷——P3576 [POI2014]MRO-Ant colony

    P3576 [POI2014]MRO-Ant colony 题目描述 The ants are scavenging an abandoned ant hill in search of food. ...

  4. 关于get请求的乱码问题

    1.使用getBytes() 页面跳转时,参数中含有中文,特殊符号,tomcat的默认编码为ios-8859-1,后台接受中文编码时,使用如下转码 //获取参数 String bname = requ ...

  5. android Activity生命周期的例子

    package com.example.yanlei.yl2; import android.app.AlertDialog; import android.content.DialogInterfa ...

  6. 【转】 C++ 简单的 Tcp 实现[socket] 客户端与客户端通信

    //  服务器端代码 // Server.cpp : Defines the entry point for the console application.// #include "std ...

  7. 文件重定向,getline()获取一样,屏幕输出流,格式控制符dec,oct,hex,精度控制setprecision(int num),设置填充,cout.width和file(字符),进制输入

     1.在window下的命令重定向输出到文件里 2.将内容输入到某个文件里的方式:命令<1.txt (使用1.txt中的命令) 3.读取文件里的名,然后将命令读取最后输出到文件里.命令< ...

  8. AAuto如何发布EXE文件

    1 如下图所示,谷歌翻译是AAuto提供的源码,我们现在把它做成软件.点击编译,注意看底部状态栏提示,编译之后的谷歌翻译还是aau格式的,双击可以直接运行.但是体积变大了,而且已经是二进制文件,无法再 ...

  9. SAP 锁对象 基本概念与基本操作 SE11

      一.SAP为什么要设置锁:     1,保持数据的一致性     假设几个用户要訪问相同的资源,须要找到一种同步訪问的方法去保持数据的一致性.比方说,在航班预订系统中,须要检查还有没有空座位,当检 ...

  10. cocos2d-x触摸事件优先级

     CCTouchDispatcher是管理cocos2d-x中全部Touch事件派发的类, CCTouchDispatcher中包括了两个CCTouchHandler的列表, 分别存储Standa ...