View Code of Problem 120

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while(scanner.hasNext()) {
			String[] s1 = scanner.nextLine().split(":");
			String[] s2 = scanner.nextLine().split(":");
			int t1 = Integer.valueOf(s1[0] )* 60 + Integer.valueOf(s1[1]);
			int t2 = Integer.valueOf(s2[0] )* 60 + Integer.valueOf(s2[1]);
			int num = 0;
			for(int i=t1; i<=t2; i++) {
				int h = i/60;
				int m = i-(h*60);
				int temp =2500*h+m;
				if(isSu(temp)) {
					num++;
				}
			}
			System.out.println(num);
		}
		
	}

	public static boolean isSu(int x) {
		// TODO Auto-generated method stub
		for(int i=2; i<=Math.sqrt(x); i++) {
			if(x % i ==0) {
				return false;
			}
		}
		return true;
	}
}

Double click to view unformatted code.


Back to problem 120