密码工程-小素数

任务详情

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

代码实现

#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 ); 
} 

  } 

运行截图

posted @   20191308_chuuuuer  阅读(43)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示