昵称不能为空

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  5 Posts :: 2 Stories :: 0 Comments :: 0 Trackbacks

常用链接

留言簿

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

2009年11月28日 #

#include <stdio.h>
int prime(int);
int prime1(int);
#define z 1000
int x[z],xc =1;
main()
{
 /*
 int i;
 for(i =2; i <= z; i++)
 {
  if( prime(i))
   printf("%6d",i);
 }
*/
 int i;x[0] = 2;
 printf("%6d",2);
 for( i = 3; i <= z; i++)
 {
  if(prime1(i))
   printf("%6d",i);
 }

}

int prime(int n)
{
 int i,bound;
 if( n % 2 == 0 )
  return ( n == 2 );
 if( n % 3 == 0 )
  return ( n == 3 );
 if( n % 5 == 0 )
  return ( n == 5 );
 for(i = 7; i*i < n; i+=2)
  if( n % i == 0)
   return 0;
 return 1;
}

int prime1(int n)
{
 int k;
 for (k = 0; x[k]*x[k] <= n; k++)
  if(n % x[k] == 0)
   return 0;
 x[xc++] = n;
 return 1;
}

//摘自<编程珠玑2>

posted @ 2009-11-28 09:24 HellpCpp 阅读(149) | 评论 (0)编辑 收藏

2009年9月14日 #

     摘要:   阅读全文
posted @ 2009-09-14 00:18 HellpCpp 阅读(580) | 评论 (0)编辑 收藏

2009年8月18日 #

     摘要:   阅读全文
posted @ 2009-08-18 23:46 HellpCpp 阅读(313) | 评论 (0)编辑 收藏

     摘要:   阅读全文
posted @ 2009-08-18 23:36 HellpCpp 阅读(840) | 评论 (0)编辑 收藏

2009年8月17日 #

     摘要:   阅读全文
posted @ 2009-08-17 10:15 HellpCpp 阅读(280) | 评论 (0)编辑 收藏