fork download
  1. #include<stdio.h>
  2. #include<math.h>
  3. #include<stdlib.h>
  4.  
  5. long prime(long num)
  6. {
  7. long i,sqr;
  8. if(num ==1)
  9. return 0;
  10. else if(num == 2)
  11. return 1;
  12. else if(num %2 ==0 )
  13. return 0;
  14. else if(num ==3)
  15. return 1;
  16. else if(num % 3 == 0)
  17. return 0;
  18. else
  19. { sqr=sqrt(num);
  20. for(i=2;i<=sqr;i+=3)
  21. {
  22. if(num % i == 0)
  23. {
  24. return 0;
  25. break;
  26. }
  27. }
  28. }
  29. return 1;
  30. }
  31. int main()
  32. {
  33. int tst,res;
  34. long int *ptr1,*ptr2,i,k;
  35. scanf("%d",&tst);
  36. ptr1=(long int*)malloc(tst*sizeof(long int));
  37. ptr2=(long int*)malloc(tst*sizeof(long int));
  38. for(i=0;i<tst;i++)
  39. {
  40. scanf("%ld%ld",ptr1+i,ptr2+i);
  41. for(k=*(ptr1+i);k<=*(ptr2+i);k++)
  42. {
  43. res=prime(k);
  44. if(res != 0)
  45. printf("%ld\n",k);
  46. }
  47. printf("\n");
  48.  
  49. }
  50.  
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0s 2428KB
stdin
2
2 10
3 5
stdout
2
3
5
7

3
5