poj 1595 Prime Cuts

5598 ワード

大学1年生の時にたたいた
 1 #include "stdio.h"

 2 #include "stdlib.h"

 3 #include "math.h"

 4 int main()

 5 {

 6     int i, j, c, prime[1000], b[1000], m, n, t, min, max;

 7     prime[0] = 1;

 8     memset(b, 0, sizeof(b));

 9     while (scanf("%d%d", &m, &n) != EOF)

10     {

11         c = 1;

12         for (i = 2; i <= m; i++)

13             if (!b[i])

14             {

15                 prime[c++] = i;

16                 for (j = i*i; j <= m; j += i)

17                     b[j] = 1;

18             }

19         t = (c) / 2;

20         printf("%d %d:", m, n);

21         if (t - n<0)

22             min = 0;

23         else

24         {

25             min = t - n;

26             if (c % 2)

27                 min++;

28         }

29         if (t + n >= c)

30             max = c;

31         else

32 

33             max = t + n;

34 

35 

36         for (j = min; j<max; j++)

37             printf(" %d", prime[j]);

38         printf("

"); 39 } 40 return 0; 41 }