格式原因,所以先存储,再打印
#include <stdio.h>
#include <math.h>
bool judge(int n)
{
int i,j,k;
int a[10001] = {0};
int num = 0;
for (i = 2;i < n;i++)
{
k = (int)sqrt((double)i);
for (j = 2;j <=k;j++)
{
if (i%j == 0) break;
}
if (j==k+1||j==2)
{
if (i % 10 == 1)
{
a[num++] = i;
}
}
}
if (num == 0) return false;
for (i = 0;i < num;i++)
{
if (i != num - 1) printf("%d ", a[i]);
else printf("%d", a[i]);
}
return true;
}
int main()
{
int n;
while (scanf("%d", &n) != EOF)
{
if (judge(n)==true) printf("\n");
else printf("%d\n", -1);
}
return 0;
}