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

素数打表

时间:2019-01-20 20:10:50      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:bool   class   打表   pre   int   prim   amp   style   for   

 1 const int maxn=1e7+5;
 2 bool prime[maxn];
 3 int p[maxn];
 4 int tot;
 5 void findprime()
 6 {
 7     for(int i = 2; i < maxn; i ++)  prime[i] = true;
 8     for(int i = 2; i < maxn; i ++)
 9     {
10         if(prime[i])  p[++tot]=i;
11         for(int j=1;j<=tot && i*p[j]<maxn; j++)
12         {
13             prime[i*p[j]]=false;
14             if(i%p[j]== 0) break;
15         }
16     }
17 }

 

素数打表

标签:bool   class   打表   pre   int   prim   amp   style   for   

原文地址:https://www.cnblogs.com/liuyongliu/p/10295716.html

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