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

    1.选择路径 this.folderBrowserDialog1.ShowDialog(); if (this.folderBrowserDialog1.ShowDialog() == DialogR ...

  2. MVC5 ModelBinder

    MVC5 ModelBinder 什么是ModelBinding ASP.NET MVC中,所有的请求最终都会到达某个Controller中的某个Action并由该Action负责具体的处理和响应.为 ...

  3. AppExtention - today

    声明: 本文转自王巍 WWDC 2014 Session笔记 - iOS 通知中心扩展制作入门 本文是我的 WWDC 2014 笔记 中的一篇,涉及的 Session 有 Creating Exten ...

  4. hdu 1255 覆盖的面积 (线段树处理面积覆盖问题(模板))

    http://acm.hdu.edu.cn/showproblem.php?pid=1255 覆盖的面积 Time Limit: 10000/5000 MS (Java/Others)    Memo ...

  5. Collection和Collections的区别

    Collection 是集合类的上级接口,继承它的接口主要有set和list.Collections 是针对集合类的一个帮助类,他提供一系列静态方法实现对各种集合的搜索,排序,线程安全化等操作.

  6. pgrep 查询进程的工具

    pgrep 1:简介 pgrep 是通过程序的名字来查询进程的工具,一般是用来判断程序是否正在运行.在服务器的配置和管理中,这个工具常被应用,简单明了: 1:用法 #pgrep 参数选项 程序名 常用 ...

  7. js正则匹配查找

    var pattern1 = /好/g; console.log(pattern1.test("你好")); 字符串查找: var pattern1 = /\w/; console ...

  8. js去除重复数值

    var c=[2,4,3,5,2,2,2], a = {}, i = 0; for(;i<c.length;i++){ a[c[i]] = 1 //利用对象名称不能重复的特性来去重 } c=[] ...

  9. range([start], stop[, step]):产生一个序列,默认从0开始

    range([start], stop[, step]):产生一个序列,默认从0开始 >>> l = range(10) >>> l [0, 1, 2, 3, 4, ...

  10. x86, x86-64, i386, IA32, IA64...

    转自x86, x86-64, i386, IA32, IA64... x86:Intel从16位微处理器8086开始的整个CPU芯片系列,系列中的每种型号都保持与以前的各种型号兼容,主要有8086,8 ...