View Code of Problem 3493

import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in =new Scanner(System.in);
		while(in.hasNext()) {
			int a =in.nextInt();
			int b =in.nextInt();
			if(a==-1 && b==-1) {
				break;
			}
			int count=0;
			for(int i =a;i<=b;i++) {
				if(ifss(i)) {
					count++;
				}
			}
			System.out.println(count);
		}
	}
	public static boolean ifss(int n ) {
		if(n==1 || n==0) {
			return false;
		}
		for(int i =2;i<=Math.sqrt(n);i++) {
			if(n%i==0) {
				return false;
			}
		}
		return true;
	}
}

Double click to view unformatted code.


Back to problem 3493