/*
可以在筛选质数的同时,算出每组数据中能被各个质数整除的个数,
然后算出[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的更多相关文章

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

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

  3. Codeforces Round #226 (Div. 2)B. Bear and Strings

    /* 题意就是要找到包含“bear”的子串,计算出个数,需要注意的地方就是不要计算重复. */ 1 #include <stdio.h> #include <string.h> ...

  4. Codeforces Round #226 (Div. 2)A. Bear and Raspberry

    /* 贪心的找到相邻两项差的最大值,再减去c,结果若是负数答案为0. */ 1 #include <stdio.h> #define maxn 105 int num[maxn]; int ...

  5. 【计算几何】【状压dp】Codeforces Round #226 (Div. 2) D. Bear and Floodlight

    读懂题意发现是傻逼状压. 只要会向量旋转,以及直线求交点坐标就行了.(验证了我这俩板子都没毛病) 细节蛮多. #include<cstdio> #include<algorithm& ...

  6. 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers

    题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...

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

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

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

随机推荐

  1. 基于C#的SolidWorks插件开发(1)--SolidWorks API接口介绍

    这是两年前毕业时写的一篇关于SolidWorks插件开发与公司PDM集成的毕业设计,最近闲来无事拿出来整理一下,大神们可以略过. 1.1   SolidWorks API接口 正确调用SolidWor ...

  2. 【springmvc Request】 springmvc请求接收参数的几种方法

    通过@PathVariabl注解获取路径中传递参数 转载请注明出处:springmvc请求接收参数的几种方法 代码下载地址:http://www.zuida@ima@com/share/1751862 ...

  3. Class.forName()的作用与使用总结(转载)

    转载自:Class.forName()的作用与使用总结 1.Class类简介: Java程序在运行时,Java运行时系统一直对所有的对象进行所谓的运行时类型标识.这项信息纪录了每个对象所属的类.虚拟机 ...

  4. 如何获得iphone设备的剩余空间

    在手机终端开发的时候,我们需要关注手机剩余空间,因为手机不像电脑一样空间宽裕,当设备空间比较少得时候需要释放空间. 用法:先引入头文件 #include <sys/param.h> #in ...

  5. Asynchronous socket communication

    来源:http://www.codeproject.com/Articles/1608/Asynchronous-socket-communication 本地下载 Download source f ...

  6. shell学习总结之自定义函数

    shell学习总结之自定义函数 Myfun (){ echo -n "now i is $i " ! [ "$i" ] && exit ; ec ...

  7. bzoj 1133: [POI2009]Kon dp

    1133: [POI2009]Kon Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 242  Solved: 81[Submit][Status][D ...

  8. BZOJ 3993 [SDOI 2015] 星际战争 解题报告

    首先我们可以二分答案. 假设当前二分出来的答案是 $Ans$ ,那么我们考虑用网络流检验: 设武器为 $X$,第 $i$ 个武器的攻击力为 $B_i$: 设机器人为 $Y$,第 $i$ 个机器人的装甲 ...

  9. PHP 系统常量及自定义常量

    __FILE__ 这个默认常量是 PHP 程序文件名.若引用文件 (include 或 require)则在引用文件内的该常量为引用文件名,而不是引用它的文件名. __LINE__ 这个默认常量是 P ...

  10. apache的 .htaccess文件的常用配置

    使用.htaccess文件需要注意的地方: 1.找到配置文件httpd.conf,将override的值改成all.如下图:(如果不设置成all,apache将忽略.htaccess文件)