Codeforces Round #226 (Div. 2)C. Bear and Prime Numbers
/*
可以在筛选质数的同时,算出每组数据中能被各个质数整除的个数,
然后算出[0,s]的个数 [l,r] 的个数即为[0,r]的个数减去[0,l]个数。
*/
#include <stdio.h>
#include <iostream>
#include <string.h>
#define maxn 10000010
using namespace std; int prime[maxn];
int isprime[maxn];
int x[maxn]; void make_prime(){
memset(isprime, , sizeof(isprime));
for(int i = ;i < maxn;i++){
if(!isprime[i]){
//prime[i] += x[i];
for(int j = i;j < maxn;j += i){
isprime[j] = ;
prime[i] += x[j];
}
}
}
// for(int i = 0;i < 100;i++)
// printf("%d ",prime[i]);
for(int i = ;i < maxn;i++)
prime[i] += prime[i-]; } int main(){
int n,m;
while(~scanf("%d",&n)){
int temp = ;
memset(x, , sizeof(x));
memset(prime, , sizeof(prime));
for(int i = ;i < n;i++){
scanf("%d",&temp);
x[temp]++;
}
// for(int i = 0;i < 25;i++)
// printf("%d ",x[i]);
// printf("\n");
make_prime();
int l,r;
scanf("%d",&m);
while(m--){
scanf("%d%d",&l,&r);//由于x1, x2, ..., xn (2 ≤ xi ≤ 10^7)
if(l > maxn)
l = maxn-;//这里的边界一定要注意,WA了好几次才发现
if(r > maxn)
r = maxn-;
printf("%d\n",prime[r]-prime[l-]);
}
}
return ;
}
Codeforces Round #226 (Div. 2)C. Bear and Prime Numbers的更多相关文章
- Codeforces Round #356 (Div. 2) C. Bear and Prime 100(转)
C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #356 (Div. 2) C. Bear and Prime 100 水题
C. Bear and Prime 100 题目连接: http://www.codeforces.com/contest/680/problem/C Description This is an i ...
- Codeforces Round #226 (Div. 2)B. Bear and Strings
/* 题意就是要找到包含“bear”的子串,计算出个数,需要注意的地方就是不要计算重复. */ 1 #include <stdio.h> #include <string.h> ...
- Codeforces Round #226 (Div. 2)A. Bear and Raspberry
/* 贪心的找到相邻两项差的最大值,再减去c,结果若是负数答案为0. */ 1 #include <stdio.h> #define maxn 105 int num[maxn]; int ...
- 【计算几何】【状压dp】Codeforces Round #226 (Div. 2) D. Bear and Floodlight
读懂题意发现是傻逼状压. 只要会向量旋转,以及直线求交点坐标就行了.(验证了我这俩板子都没毛病) 细节蛮多. #include<cstdio> #include<algorithm& ...
- 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers
题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...
- Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)
B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Codeforces Round #356 (Div. 2)A. Bear and Five Cards(简单模拟)
A. Bear and Five Cards time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #356 (Div. 1) D. Bear and Chase 暴力
D. Bear and Chase 题目连接: http://codeforces.com/contest/679/problem/D Description Bearland has n citie ...
随机推荐
- easy-ui datagrid
Easy-ui引用 <link href="css/EasyUI/themes/icon.css" rel="stylesheet" type=&q ...
- MVC-EditorFor与TextBoxFor的区别
EditorFor会根据后面提供的数据类型自动判断生成的控件类型(比如TextBox,CheckBox等): TextBoxFor生成的只是一个TextBox.
- 一步步学习ASP.NET MVC3 (6)——@helper,@functions
请注明转载地址:http://www.cnblogs.com/arhat 在前一章中,我们讲述了View如何从Action中获得数据,并显示出来,但随着需求的变化,我们可能要对View中显示的数据作出 ...
- Spring3事务管理——使用@Transactional 注解(转)
文章地址:http://my.oschina.net/guanzhenxing/blog/214228
- [JavaScript] 用html5 js实现浏览器全屏
项目中需要将后台浏览器的窗口全屏,也就是我们点击一个按钮要实现按F11全屏的 效果. 在HTML5中,W3C制定了关于全屏的API,就可以实现全屏幕的效果,也可以 让页面中的图片,视频等全屏目前只有g ...
- jQuery弹出层---artDialog 文档
artDialog是一个基于javascript编写的对话框组件,它拥有精致的界面与友好的接口 自适应内容 artDialog的特殊UI框架能够适应内容变化,甚至连外部程序动态插入的内容它仍然能自适应 ...
- 几个不常见但非常出色的 .NET 开源库
NLog NLog 目前最为出色的 .NET 日志库,非常容易配置,且极具灵活性.最重要的是与 log4net 相比,NLog 的开发很活跃.顺带提一句,NLog 完全兼容 Mono. Mono.Ce ...
- 判断数据库表字段是否为null值,采用is null
use UserCentergo select * from AccountDetails1.判断一个字段是否为null值,进行查询:update AccountDetails set Project ...
- Java程序发展之路
- android usb Host模式下与usb Hid 设备的通信
做android 与USB HID设备的通信有段时间了,总结一下遇到的问题和解决方法: 1,第一次遇到的问题:android 版本低不支持usb hid, 被要求做相关项目的时候,就从mUsbMana ...