密码工程-小素数

发布时间 2023-05-10 09:08:25作者: 20201208史逸霏
任务详情
0. 在openEuler(推荐)或Ubuntu或Windows(不推荐)中完成下面任务
1. 参考《密码工程》p107伪代码基于Eratosthenes算法实现 int SmallPrimeList(int n, int *plist, int *len), 其中plist返回素数列表,len返回列表长度(5
’)
2 写出测试代码,至少包括 n=2, n=你的四位学号,n>2^20次方的测试代码,提交代码和运行结果截图(10)
 

代码实现

#include <string.h>
#include <stdio.h> 
#include <stdlib.h>
#include <math.h>
//#define SIZE  //该方法能够求出 2*SIZE 之内的质数
#define TRUE 1
#define FALSE 0
int main()
{ 
  int n,SIZE;
  printf("请输入一个数:");
  scanf("%d",&n);
  SIZE = n/2;
  char sieve[ SIZE ]; /* the sieve */ 
  char *sp; /* p to access the sieve */ 
  int number; 
  for( sp = sieve; sp = &sieve[ SIZE ] ; ) 
  break; 
  while( sp += number, sp < &sieve[ SIZE ] ) *sp = FALSE; 

  printf( "2\t" ); 

for( number = 3, sp = &sieve[ 0 ]; sp < &sieve[ SIZE ]; number += 2, sp++ )
{ 
  if( *sp ) 
  printf( "%d\t", number ); 
} 

  } 

 

 

运行截图