Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Solution {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int a = sc.nextInt(),b=sc.nextInt();
- for(int i = a;i<=b;i++){
- if(isPrime(i)){
- System.out.print(i+" ");
- }
- }
- }
- static boolean isPrime(int n) {
- if (n == 2 || n == 3)
- return true;
- if (n % 2 == 0)
- return false;
- for (long i = 3; i * i <= n; i += 2) {
- if (n % i == 0)
- return false;
- }
- return n != 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement