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

    splay 练手用: 杭电的oj要手动开栈: #include<cstdio> #pragma comment(linker, "/STACK:102400000,1024000 ...

  2. zoj 3716

    题目给我们四个点,要求我们以这四个点为圆心,形成四个相切的圆: 求他们的半径和: 首先我们从他们中间选出三个点,以这三个点为圆心的三个圆最大可以两两互相相切: 证明:假设这三个圆的半径分别为a,b,c ...

  3. ZOJ 3170 Friends

    点我看题目 题意 : 就是有n个人,m对关系,每对关系的两个人是好朋友,这个关系是相互的,如果有两个人的共同好朋友超过k个,那这两个人也会是好朋友的,给你m对关系,给你足够长的时间,问你还能增加几对关 ...

  4. Oracle11g密码区分大小写导致database link无法连接

    http://f.dataguru.cn/thread-128013-1-1.html Oracle11g的密码默认是区分大小写的,该特性通过初始化参数sec_case_sensitive_logon ...

  5. cat命令常用的13个技巧

    在Linux系统中,大多数配置文件.日志文件,甚至shell脚本都使用文本文件格式,因此,Linux系统存在着多种文本编辑器,但当你仅仅想要查看一下这些文件的内容时,可使用一个简单的命令-cat. c ...

  6. [转贴]超级懒汉编写的基于.NET的微信SDK

    一.前言 特别不喜欢麻烦的一个人,最近碰到了微信开发.下载下来了一些其他人写的微信开发“框架”,但是被恶心到了,实现的太臃肿啦. 最不喜欢的就是把微信返回的xml消息在组装成实体类,所以会比较臃肿,现 ...

  7. 9. MonoBehaviour.StartCoroutine 开始协同程序

    function StartCoroutine (routine : IEnumerator) : Coroutine 描述:开始协同程序. 一个协同程序在执行过程中,可以在任意位置使用yield语句 ...

  8. money 和 smallmoney

    代表货币或货币值的数据类型. 数据类型 范围 存储 money -922,337,203,685,477.5808 到 922,337,203,685,477.5807 8 字节 smallmoney ...

  9. Android imageview显示圆形图片

    需要ImageView显示圆形图片做法如下 public static Bitmap toRoundCorner(Bitmap bitmap, float ratio) { System.out.pr ...

  10. make menuconfig出错

    make[1]: *** [scripts/kconfig/mconf] Error 1 make: *** [menuconfig] Error 2 fixed: sudo apt-get inst ...