/*
可以在筛选质数的同时,算出每组数据中能被各个质数整除的个数,
然后算出[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. OpenFileDialog组件打开文件....待续

    1.常用属性 InitialDirectory           对话框的初始目录 this.openFileDialog1.InitialDirectory = "d:\\"; ...

  2. JAVA TCP/IP Socket通信机制以及应用

    关于局域网通信(同一wifi下,自己电脑当服务端,同一网络段) 1.例如192.168.1.x,只有x位不相同视为同一网络段 2.当具备了以上条件,即可编写服务端代码,服务端的机制. 3.Server ...

  3. Python Geospatial Development reading note(1)

    chapter 1, Summary: In this chapter, we briefly introduced the Python programming language and the m ...

  4. display:inline-block元素间空白间隙问题

    display:inline-block元素间有空白间隙,可以在父元素上加font-size:0

  5. Codeforces Round #359 div2

    Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...

  6. oracle学习之-----操作表中的数据

    1. 向表中添加数据(Insert 语句): 添加的语法: INSERT INTO table_name(column1,column2,column3,......) VALUES(value1,v ...

  7. [转载]MongoDB 常用命令

    mongodb由C++编写,其名字来自humongous这个单词的中间部分,从名字可见其野心所在就是海量数据的处理.关于它的一个最简洁描述为:scalable, high-performance, o ...

  8. 关于对js的this的几点理解

    四种不同模式小调用的指向 1.函数调用模式的时候,this指向window 2.方法调用模式的时候,this指向方法所在的对象 3.构造函数模式的时候,this指向新生成的实例 4.apply/cal ...

  9. 常用的python模块

    http://tiankonghaikuo1000.blog.163.com/blog/static/18231597200812424255338/ adodb:我们领导推荐的数据库连接组件bsdd ...

  10. 【HDOJ】1204 糖果大战

    题目本身不难.类似于dp.f(i)表示手中现有i颗糖果赢的概率,则下一局赢的概率是p(1-q),下一局输的概率是q(1-p),下一句平手的概率是1-p(1-q)-q(1-p),平手包括两人均答对或答错 ...