NEU OJ 1649 GMZ’s Pretty Number
先来一次线性素数筛,把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的更多相关文章
- NEU OJ 1651 Great number
循环节是2000000016 字符串读入,用一下高精度对2000000016取个模,用一下快速幂就可以算出答案了. #include <cstdio> #include <iostr ...
- LeetCode OJ:Excel Sheet Column Number(表格列数)
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...
- 九度oj 题目1380:lucky number
题目描述: 每个人有自己的lucky number,小A也一样.不过他的lucky number定义不一样.他认为一个序列中某些数出现的次数为n的话,都是他的lucky number.但是,现在这个序 ...
- NEU OJ 1644 Median I
优先级队列 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- 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新生 ...
- FZU 1649 Prime number or not米勒拉宾大素数判定方法。
C - Prime number or not Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- 【LEETCODE OJ】Single Number II
Problem link: http://oj.leetcode.com/problems/single-number-ii/ The problem seems like the Single Nu ...
- 【LEETCODE OJ】Single Number
Prolbem link: http://oj.leetcode.com/problems/single-number/ This prolbem can be solved by using XOR ...
- 【九度OJ】题目1040:Prime Number 解题报告
[九度OJ]题目1040:Prime Number 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1040 题目描述: Ou ...
随机推荐
- 简单的jquery ajax文件上传功能
/* * 图片上传 * 注意如果不加processData:false和contentType:false会报错 */ function uploadImage(image) { var imageF ...
- checkbox:全选与反全选
$(document).ready(function () { //全选checkbox $("#selectAll").click(function () { var check ...
- struts2.3 创建工程
1:在该网站下载struts2.3.16.3,目前为最新版.http://www.struts.apache.org/download.cgi 不妨下载“Full Distribution”版本 下载 ...
- Eclipse开发中GlassFish 4 重启页面不刷新
现在项目开发用GlassFish4做服务器,测试了几个web项目出现问题,每次编辑源代码后页面不能按照最新编辑好的代码显示. 一次重新运行web项目在服务器上看到publish,点击后运行的是新编辑的 ...
- oracle之nomount、mount、open三种状态
1.先来看下外国网站上的资料怎么说 Nomount – The database instance has been started (processes and memory structures ...
- BestCoder Round #89
过了这么久才来写-- BC的后两道题好难--(第二道题也不怎么简单--) 1001 Fxx and string 正着倒着枚举一次就ok #include<iostream> #inclu ...
- 关于设置CFileDialog的默认路径
CFileDialog d_File(FRUE, NULL,NULL,NULL,szFilter,FromHandle(m_hWnd)); // 如果写了下面这句那么每次打开都是这个设置的默认路径 ...
- 【MySQL】查询优化实例解析-延迟关联优化
[提出问题] 从数据表t通过分页查询的方式读取数据,读取时要根据a1排序.t有80万行记录,当OFFSET很大时,读取速度很慢.优化后查询速度提升很快. 下图是表的定义,一共有几十个字段,RowLen ...
- Solr搜索技术
Solr搜索技术 今日大纲 回顾上一天的内容: 倒排索引 lucene和solr的关系 lucene api的使用 CRUD 文档.字段.目录对象(类).索引写入器类.索引写入器配置类.IK分词器 查 ...
- 计算机网络课程优秀备考PPT之第四章介质访问控制层(四)
为了记录自己从2016.9~2017.1的<计算机网络>助教生涯,也为了及时梳理和整写笔记! 前期博客是, 计算机网络课程优秀备考PPT之第一章概述(一) 计算机网络课程优秀备考PPT之第 ...