密码工程-小素数
代码:
#include <stdio.h> int main() { int i,n,x,j,k,q; scanf("%d",&n); n=n+1; while(n>=1048576){ printf("%s","n is too large\n"); scanf("%d",&n); } int b[n]; int P[n]; for(x=0;x<n;x++) { b[x]=1; } i=2; while(i*i<=n){ for(x=2;x<=(n/i);x++) { b[x*i]=0; } i=i+1; } q=0; printf("%s","the list:"); for(k=2;k<=n;k++){ if(b[k]==1){ printf("%d ",k); q=q+1; } } printf("%s","\n the lenth of list:"); printf("%d",q); return 0; }
测试截图: