5458. 【NOIP2017提高A组冲刺11.7】质数
5458. 【NOIP2017提高A组冲刺11.7】质数
(File IO): input:prime.in output:prime.out
Description
在小X 的认知里,质数是除了本身和1 以外,没有其他因数的数字。
但由于小X 对质数的热爱超乎寻常,所以小X 同样喜欢那些虽然不是质数,但却是由两个质数相乘得来的数。
于是,我们定义,一个数是小X 喜欢的数,当且仅当其是一个质数,或是两个质数的乘积。
而现在,小X 想要知道,在L 到R 之间,有多少数是他喜欢的数呢?
Input
接下来Q 行。包含两个正整数L 和R。保证L≤R。
Output
Sample Input
输入1:
1
1 6 输入2:
10
282 491
31 178
645 856
227 367
267 487
474 697
219 468
582 792
315 612
249 307 输入3:
10
20513 96703
15236 86198
23185 78205
40687 48854
42390 95450
63915 76000
36793 92543
35347 53901
44188 76922
82177 90900
Sample Output
输出1:
5
样例1解释:
6以内的质数有2,3,5,而4=2*2,6=2*3。因此2,3,4,5,6都是小X 喜欢的数,而1 不是。 输出2:
97
78
92
65
102
98
114
90
133
29 输出3:
24413
23001
17784
2669
16785
3833
17712
6028
10442
2734
#include <cstdio>
#include <cstring>
#include <iostream>
#define N 10000020
using namespace std;
int q, zs[N / ], qzh[N], n;
bool b[N], v[N]; void Pre_work()
{
memset(qzh, , sizeof(qzh));
for (int i = ; i <= N - ; i++)
{
if (!b[i])
{
zs[++zs[]] = i;
v[i] = ;
for (int j = ; j <= zs[]; j++)
if (i * zs[j] > N - ) break;
else v[i * zs[j]] = , b[i * zs[j]] = ;
}
else
{
for (int j = ; j <= zs[]; j++)
if (i * zs[j] > N - ) break;
else b[i * zs[j]] = ;
}
} for (int i = ; i <= N - ; i++)
qzh[i] += qzh[i - ] + v[i];
} int main()
{
freopen("prime.in", "r", stdin);
freopen("prime.out", "w", stdout);
Pre_work();
scanf("%d", &n);
int x, y;
for (; n; n--)
{
scanf("%d%d", &x, &y);
printf("%d\n", qzh[y] - qzh[x - ]);
}
}
5458. 【NOIP2017提高A组冲刺11.7】质数的更多相关文章
- JZOJ 5462. 【NOIP2017提高A组冲刺11.8】好文章
5462. [NOIP2017提高A组冲刺11.8]好文章 (File IO): input:article.in output:article.out Time Limits: 1000 ms M ...
- JZOJ 5456. 【NOIP2017提高A组冲刺11.6】奇怪的队列
5456. [NOIP2017提高A组冲刺11.6]奇怪的队列 (File IO): input:queue.in output:queue.out Time Limits: 1000 ms Mem ...
- JZOJ 5459. 【NOIP2017提高A组冲刺11.7】密室
5459. [NOIP2017提高A组冲刺11.7]密室 (File IO): input:room.in output:room.out Time Limits: 1000 ms Memory L ...
- JZOJ 5455. 【NOIP2017提高A组冲刺11.6】拆网线
455. [NOIP2017提高A组冲刺11.6]拆网线 (File IO): input:tree.in output:tree.out Time Limits: 1000 ms Memory L ...
- JZOJ 5461. 【NOIP2017提高A组冲刺11.8】购物
5461. [NOIP2017提高A组冲刺11.8]购物 (File IO): input:shopping.in output:shopping.out Time Limits: 1000 ms ...
- [JZOJ5455]【NOIP2017提高A组冲刺11.6】拆网线
Description 企鹅国的网吧们之间由网线互相连接,形成一棵树的结构.现在由于冬天到了,供暖部门缺少燃料,于是他们决定去拆一些网线来做燃料.但是现在有K只企鹅要上网和别人联机游戏,所以他们需要把 ...
- 【NOIP2017提高A组冲刺11.8】好文章
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> us ...
- 【NOIP2017提高A组冲刺11.6】拆网线
和syq大兄弟吐槽题目不小心yy出了正解.. 最优的选法就是选两个两个相互独立的,欸这不就是最大匹配吗?那多的企鹅就新加一条边呗?不够的就除以2上取整呗? 欸?AC了? 树也是一个二分图,最大匹配=最 ...
- 【NOIP2017提高A组冲刺11.8】购物
这个范围对DP不友好,和CF的一道C题非常像,贪心+后悔. 先使用k个优惠券购买k个q最小的(钱不购买则退出),同时把这k个p[i]-q[i]放入小根堆,然后将剩下的n-k个按p升序排序,记小根堆堆顶 ...
随机推荐
- Java修饰符/关键字
修饰符分类: 权限修饰符:public.protected.default.private 其他修饰符:abstract.static.final.transient.volatile.native. ...
- IE6下float双边距问题
当浮动元素的方向和设置margin的方向相同时,就会出现双边距问题,解决方法是: 删除浮动,改成display:inline-block _display:inline; _zoom:1;
- spring-boot整合shiro作权限认证
spring-shiro属于轻量级权限框架,即使spring-security更新换代,市场上大多数企业还是选择shiro 废话不多说 引入pom文件 <!--shiro集成spring--& ...
- The eighth day
time n(名词):时间:次,时代,时刻: vt(及物动词):为...安排时间:测定...的时间:调准(机械的速度): vi(不及物动词):合拍,和谐,打拍子 files (原型是fly) vi(不 ...
- C#cmd执行命令隐藏窗口,并保持程序一直运行
把要执行的cmd命令放入一个bat文件里,然后执行: //Process p = Process.Start(bPath); Process pro = new Process();pro.Start ...
- Shape详解
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http: ...
- VS功能扩展--扩展介绍
使用Eclipse的朋友都知道Eclipse是一个完全可扩展的IDE,那么在windows程序开发时,我们常使用的IDE(Visual studio)是否具有功能的扩展性呢?毫无疑问,回答是肯定的.我 ...
- python 之 BeautifulSoup 常用提取
一.bs4信息提取后返回的数据类型 soup.find('tbody') ---> 返回结构是一个bs4.element.Tag soup.find('tbody').children ---& ...
- cms-帖子静态化
实现帖子静态化和实现友情链接静态化一致, 1.首先建立帖子类别的实体类: package com.open1111.entity; /** * 帖子类别实体 * @author user * */pu ...
- ubuntu常见错误
ubuntu常见错误--Could not get lock /var/lib/dpkg/lock解决 ubuntu常见错误--Could not get lock /var/lib/dpkg/loc ...