码迷,mamicode.com
首页 > 其他好文 > 详细

闭区间筛素数个数

时间:2018-05-24 18:23:55      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:max   void   oss   name   lse   c++   its   ||   namespace   

//n为询问次数,m为maxx
#include<bits/stdc++.h> using namespace std; int a[1000005]; int cnt[1000005]; void P(int maxx) { for(int i = 2;i <= maxx;i ++) { cnt[i] = cnt[i-1]; if(!a[i]){ for(int k = i;k <= maxx / i;k ++){ a[i * k] = 1; } cnt[i] ++; } } } int main() { int n,m; scanf("%d%d",&n,&m); P(m); for(int i = 1;i <= n;i ++){ int l,r; scanf("%d%d",&l,&r); if(r > m || r < 1 || l < 1 || l > m){ printf("Crossing the line\n"); } else{ printf("%d\n",cnt[r] - cnt[l - 1]); } } }

 

闭区间筛素数个数

标签:max   void   oss   name   lse   c++   its   ||   namespace   

原文地址:https://www.cnblogs.com/love-fromAtoZ/p/9083808.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!