先来一次线性素数筛,把1到10000000的素数都筛选出来,然后暴力跑一遍所有可能的值,打个表,查询的时候o(1)效率出解。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std; const long N = ;
long long prime[N] = {},num_prime = ;
int isNotPrime[N] = {, };
int R[+];
int ans[+];
int main()
{
memset(R,,sizeof(R));
memset(ans,,sizeof(ans));
for(long i = ; i < N ; i ++)
{
if(! isNotPrime[i])
prime[num_prime ++]=i;
//关键处1
for(long j = ; j < num_prime && i * prime[j] < N ; j ++)
{
isNotPrime[i * prime[j]] = ;
if( !(i % prime[j] ) ) //关键处2
break;
}
} for(int i=;i<num_prime;i++)
{
for(int j=i+;j<num_prime;j++)
{
if(prime[i]*prime[j]>) break;
R[prime[i]*prime[j]]=;
}
}
ans[]=;
for(int i=;i<=;i++)
{
if(R[i]==) ans[i]=ans[i-]+;
else ans[i]=ans[i-];
}
int LL,RR;
while(~scanf("%d%d",&LL,&RR))
{
printf("%d\n",ans[RR]-ans[LL-]);
}
return ;
}

NEU OJ 1649 GMZ’s Pretty Number的更多相关文章

  1. NEU OJ 1651 Great number

    循环节是2000000016 字符串读入,用一下高精度对2000000016取个模,用一下快速幂就可以算出答案了. #include <cstdio> #include <iostr ...

  2. LeetCode OJ:Excel Sheet Column Number(表格列数)

    Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...

  3. 九度oj 题目1380:lucky number

    题目描述: 每个人有自己的lucky number,小A也一样.不过他的lucky number定义不一样.他认为一个序列中某些数出现的次数为n的话,都是他的lucky number.但是,现在这个序 ...

  4. NEU OJ 1644 Median I

    优先级队列 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  5. Solve Equation gcd(x,y)=gcd(x+y,lcm(x,y)) gcd(x,y)=1 => gcd(x*y,x+y)=1

    /** 题目:Solve Equation 链接:http://acm.hnust.edu.cn/JudgeOnline/problem.php?id=1643 //最终来源neu oj 2014新生 ...

  6. FZU 1649 Prime number or not米勒拉宾大素数判定方法。

    C - Prime number or not Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  7. 【LEETCODE OJ】Single Number II

    Problem link: http://oj.leetcode.com/problems/single-number-ii/ The problem seems like the Single Nu ...

  8. 【LEETCODE OJ】Single Number

    Prolbem link: http://oj.leetcode.com/problems/single-number/ This prolbem can be solved by using XOR ...

  9. 【九度OJ】题目1040:Prime Number 解题报告

    [九度OJ]题目1040:Prime Number 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1040 题目描述: Ou ...

随机推荐

  1. underScore学习1:匿名函数中call(this)的作用

    匿名函数中(function(){}).call(this) 中的.call(this) 有什么用? 我们都知道,.call()可以改变函数执行时的context,即this的指向,源码中的.call ...

  2. FORM提交请求后自动打开输出EDITOR_PKG.REPORT

    DECLARE p_mode_request_id number := 1; p_ERRBUF VARCHAR2(250); p_RETCODE NUMBER; lv_msg varchar2(50) ...

  3. Python入门学习

    1.访问www.python.org/download下载并安装Python3版本 2.命令行输入python启动交互式命令shell,>>>代表当前行用户的输入 3.基本算数运算: ...

  4. eclipse 发布web工程,修改tomcat端口

    如果想修改tomcat发布的端口,有两种方法: 1.用记事本打开tomcat安装目录下的conf文件夹下的server.xml,找到<Connector port="8080" ...

  5. 15个实用find命令

    除了在一个目录结构下查找文件这种基本的操作,你还可以用find命令实现一些实用的操作,使你的命令行之旅更加简易. 本文将介绍15种无论是于新手还是老鸟都非常有用的Linux find命令. 1. 用文 ...

  6. 变更mysql数据库文件目录 Linux

    本次需要将mysql默认的数据库文件路径/var/lib/mysql 改为新挂载的目录/data/mysql上,需要做以下修改 1.停止mysql服务 service mysqld stop 2.复制 ...

  7. windows 激活等命令

    Win+R 输入:slmgr.vbs -dlv 显示:最为详尽的激活信息,包括:激活ID.安装ID.激活截止日期slmgr.vbs -dli 显示:操作系统版本.部分产品密钥.许可证状态slmgr.v ...

  8. JQuery中$.ajax()方法参数详解及应用

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

  9. ubuntu下百度云安装

    1.安装 在github上下载 .deb 安装包 下载地址 https://github.com/LiuLang/bcloud-packages 下载完成双击安装文件安装成功 2.解决验证码问题 (1 ...

  10. Distributing Parts

    Distributing Parts 题目链接:http://codeforces.com/problemset/problem/496/E 贪心 将音乐和人都以低音升序排序,贪心处理低音更低的音乐, ...