【链接】 我是链接,点我呀:)

【题意】

f[i]表示在x[]中有多少个数字是i的倍数
让你求出sum(f[i]) li

【题解】

做筛法求素数的时候顺便把素数i在x[]中的倍数的个数求出来就好
前缀和 输出即可

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = (int)1e7;
static class Task{
public void solve(InputReader in,PrintWriter out) {
int n;
int []cnt = new int [N+10];
int []shai = new int [N+10];
long []f = new long [N+10];
n = in.nextInt();
for (int i = 1;i <= n;i++) {
int x;
x = in.nextInt();
cnt[x]++;
} for (int i = 2;i <= N;i++)
if (shai[i]==0) {
f[i] = cnt[i];
for (int j = 2*i;j <= N;j+=i) {
f[i] = f[i] + cnt[j];
shai[j] = 1;
}
}
for (int i = 1;i <= N;i++)
f[i]=f[i-1]+f[i];
n = in.nextInt();
for (int i = 1;i <= n;i++) {
int l,r;
l = in.nextInt();r = in.nextInt();
l = Math.min(l, N);r = Math.min(r,N);
out.println(f[r]-f[l-1]);
}
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
}
}
}

【Codeforces 385C】Bear and Prime Numbers的更多相关文章

  1. 【66.47%】【codeforces 556B】Case of Fake Numbers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 【32.89%】【codeforces 574D】Bear and Blocks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【codeforces 791D】 Bear and Tree Jumps

    [题目链接]:http://codeforces.com/contest/791/problem/D [题意] 你可以从树上的节点一次最多走k条边. (称为跳一次); 树为无权树; 然后问你任意两点之 ...

  4. 【codeforces 791C】Bear and Different Names

    [题目链接]:http://codeforces.com/contest/791/problem/C [题意] 给你n-k+1个限制 要求 a[i]..a[i]+k-1里面有相同的元素,或全都不同; ...

  5. 【codeforces 791B】Bear and Friendship Condition

    [题目链接]:http://codeforces.com/contest/791/problem/B [题意] 给你m对朋友关系; 如果x-y是朋友,y-z是朋友 要求x-z也是朋友. 问你所给的图是 ...

  6. 【codeforces 791A】Bear and Big Brother

    [题目链接]:http://codeforces.com/contest/791/problem/A [题意] 给你两个数字a和b; a每次乘3,b每次乘2 问你什么时候a第一次大于b [题解] 傻逼 ...

  7. 【19.05%】【codeforces 680D】Bear and Tower of Cubes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【Codeforces 639B】Bear and Forgotten Tree 3

    [链接] 我是链接,点我呀:) [题意] [题解] 首先,因为高度是h 所以肯定1下面有连续的h个点依次连成一条链.->用了h+1个点了 然后,考虑d这个约束. 会发现,形成d的这个路径,它一定 ...

  9. 【Codeforces 639A】Bear and Displayed Friends

    [链接] 我是链接,点我呀:) [题意] [题解] 时刻维护一下前K大的数字就好. 因为k<=6 然后数字不会减少只会增加. 因此只要维护一个大小为k的数组就ok. 保证这个数组是有序的. 写个 ...

随机推荐

  1. iOS界面之间的跳转方式

    iOS界面之间的跳转方式基本有3种. .改变window的根视图 [self.window setRootViewController:VC]; .模态弹出 [self presentViewCont ...

  2. 最直观的poi的使用帮助(告诉你怎么使用poi的官网),操作word,excel,ppt

    最直观的poi的使用帮助(告诉你怎么使用poi的官网),poi操作word,excel,ppt 写在最前面 其实poi的官网上面有poi的各种类和接口的使用说明,还有非常详细的样例,所以照着这些样例来 ...

  3. seq2seq里的数学

    seq2seq模型详解 原创 2017年12月25日 09:41:04 标签: seq2seq / 自然语言 / 机器人   在李纪为博士的毕业论文中提到,基于生成的闲聊机器人中,seq2seq是一种 ...

  4. Codeforces--622A--Infinite Sequence(数学)

     Infinite Sequence Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:26214 ...

  5. qtree4

    https://zybuluo.com/ysner/note/1236834 题面 给出一棵边带权的节点数量为\(n\)的树,初始树上所有节点都是白色.有两种操作: 改变节点\(x\)的颜色,即白变黑 ...

  6. PCB genesis连孔加除毛刺孔(圆孔与圆孔)实现方法(一)

    一.为什么 连孔加除毛刺孔 原因是 PCB板材中含有玻璃纤维, 毛刺产生位置在于2个孔相交位置,由于此处钻刀受力不均导致纤维切削不断形成毛刺 ,为了解决这个问题:在钻完2个连孔后,在相交处再钻一个孔, ...

  7. P4166 [SCOI2007]最大土地面积

    传送门 首先,四边形的四个点肯定都在凸包上(别问我为什么我也不知道,感性理解一下好了) 那么我们可以求出凸包之后\(O(n^4)\)暴力枚举,据说在随机数据下凸包上的点只有\(O(logn)\)个可过 ...

  8. CSS样式适配杂记

    1.问:input框的对齐,制作类似百度搜索框的时候,发现IE下前面输入框和后面按钮总是不能对齐. 解答:给input框增加vertical-align:bottom; 2.问:IE下display: ...

  9. Spring思维课程导图——bean得实例化和bean的管理

  10. 元组Tuple、数组Array、映射Map

    一.元组Tuple 元组Tuple是不同类型的值的聚集,元组的值将单个的值包含在圆括号中来构成,元组可以包含一个不同类型的元素 如 val riple = (100, "Scala" ...