|
常用鏈接
留言簿(4)
隨筆分類
隨筆檔案
搜索
最新評論

閱讀排行榜
評論排行榜
Powered by: 博客園
模板提供:滬江博客
|
|
|
|
|
發新文章 |
|
|
媽的,沒見過那么惡心的題目。。。 首先題目就錯了,1不是質數啊!!! 輸出之間居然還有一空行。。。 檢查了半天都沒查出來,殺人了!!! 懶得改了,用了同學的
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
using namespace std;

#include"stdio.h"
#include"math.h"
int p[2001];

int main()
  {
int n,c,n1;
int i,j;
int tol;
int flag;
while(scanf("%d%d",&n,&c)!=-1)
 {


p[1]=1;
tol=1;
for(i=2;i<=3000;i++)
 {
flag=1;
for(j=2;j<=(int)sqrt((double)i);j++)
 {
 if(i%j==0) {flag=0;break;}
}
if(flag==0)continue;
else if(i>n)break;
else
 {
tol++;
p[tol]=i;

}

}


//此時質數的個數是tol,第一個質數是1
printf("%d %d:",n,c);
if(tol%2==0&&tol>=c*2)
 {
for(i=1;i<=c*2;i++)
 {
j=(tol-c*2)/2;
printf(" %d",p[j+i]);

}
printf("\n\n");
}

if(tol%2==0&&tol<c*2)
 {
for(j=1;j<=tol;j++)
printf(" %d",p[j]);
printf("\n\n");
}

if(tol%2==1&&tol>=c*2-1)
 {
for(i=1;i<=c*2-1;i++)
 {
j=(tol-c*2+1)/2;
printf(" %d",p[i+j]);
}
printf("\n\n");
}

if(tol%2==1&&tol<c*2-1)
 {
for(j=1;j<=tol;j++)
 {
printf(" %d",p[j]);
}
printf("\n\n");
}



}
}
|
|