Shubhamizm

PRIME1

Oct 7th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import java.util.*;
  2. class Prime
  3. {
  4. public static void main(String[] args)
  5. {
  6. int n,i,j,m;
  7. Scanner sc = new Scanner(System.in);
  8. n = sc.nextInt();
  9. if(n<10)
  10. {
  11. int a[][] = new int[n][2];
  12. for(i=0;i<n;i++)
  13. {
  14. for(j=0;j<2;j++)
  15. {
  16. a[i][j]=sc.nextInt();
  17. }
  18. }
  19. for(i=0;i<n;i++)
  20. {
  21. j=0;
  22. n=a[i][j];
  23. m=a[i][j+1];
  24. if(m<=1000000000 && m>=n && m-n<=100000)
  25. check(n,m);
  26. }
  27. }}
  28.  
  29. static void check(int n, int m)
  30. {
  31. int flag=1;
  32. for(int i=n; i<=m; i++)
  33. {
  34. if(i==1)
  35. {
  36. flag=0;
  37. break;
  38. }
  39. for(int j=2; j<=(int)Math.sqrt(i); j++)
  40. {
  41. if(i%j==0)
  42. {
  43. flag=0;
  44. break;
  45. }
  46. else
  47. {
  48. System.out.println(i+"\n");
  49. }
  50. }
  51. System.out.println("\n");
  52. }
  53. }
  54. }
Add Comment
Please, Sign In to add comment