View Code of Problem 120

import  java.util.*;
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 start = Integer.valueOf(s1[0] ) * 60 + Integer.valueOf(s1[1]);
			int end = Integer.valueOf(s2[0] ) * 60 + Integer.valueOf(s2[1]);
			int count = 0;
			for(int i=start; i<=end; i++) {
				int h = i / 60;
				int m = i-h*60;
				int temp = h*2500+m;
				if(isSu(temp)) {
					count++;
				}
			}
			System.out.println(count);
		}
	}
 
	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