fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define reach 46341
  4.  
  5. unsigned short t, len, vec[5000];
  6. unsigned long a, b;
  7.  
  8. inline char* itoa(int val, int base)
  9. {
  10. static char buf[32] = {0};
  11. int i = 30;
  12. for(; val && i ; --i, val /= base)
  13. buf[i] = "0123456789abcdef"[val % base];
  14. return &buf[i+1];
  15. }
  16.  
  17. inline unsigned short prime(unsigned long nr)
  18. {
  19. unsigned short i, sq;
  20. for (i = 0, sq = sqrt(nr); i < len && vec[i] <= sq; ++i) {
  21. if (!(nr % vec[i])) {
  22. return 0;
  23. }
  24. }
  25. return 1;
  26. }
  27.  
  28. inline void preprocess()
  29. {
  30. unsigned short i;
  31. i = vec[len++] = 2;
  32. ++i;
  33. while (i < reach) {
  34. if (prime(i)) {
  35. vec[len++] = i;
  36. }
  37. i += 2;
  38. }
  39. }
  40.  
  41. inline void process()
  42. {
  43. char* nr;
  44. unsigned long i;
  45. if (!(a % 2)) {
  46. if (a == 2) {
  47. puts("2");
  48. }
  49. ++a;
  50. }
  51. for (i = a; i <= b; i += 2) {
  52. if (prime(i)) {
  53. nr = itoa(i, 10);
  54. puts(nr);
  55. }
  56. }
  57. }
  58.  
  59. int main()
  60. {
  61. //freopen("print.in", "rt", stdin);
  62. preprocess();
  63. for (scanf("%hu", &t); t > 0; --t) {
  64. scanf("%lu %lu", &a, &b);
  65. process();
  66. }
  67. return 0;
  68. }
  69.  
stdin
1
1500124366 1500124966
compilation info
prog.c: In function ‘main’:
prog.c:63: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
prog.c:64: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
stdout
1500124397
1500124453
1500124471
1500124477
1500124513
1500124517
1500124519
1500124529
1500124567
1500124583
1500124597
1500124643
1500124649
1500124657
1500124679
1500124711
1500124721
1500124723
1500124729
1500124739
1500124757
1500124763
1500124777
1500124783
1500124807
1500124811
1500124823
1500124861
1500124867
1500124877
1500124907