View Code of Problem 120

#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
bool isPrime(int n) {
	for (int i = 2; i <= sqrt(n); i++)
		if (n%i == 0)
			return 0;
	return 1;
}
int cnt(int h1, int m1, int h2, int m2) {
	int sum = 0;
	int t1 = h1 * 60 + m1;
	int t2 = h2 * 60 + m2;
	for (int i = t1; i <= t2; i++) {
		int t = i / 60 * 2500 + i % 60;
		if (isPrime(t))
			sum++;
	}
	return sum;
}
int main() {
	int h1, m1,h2,m2;
	char c;
	while (cin >>h1>>c>> m1>>h2>>c>>m2) {
		if (h1 < h2 || h1 == h2 && m1 < m2) {
			cout << cnt(h1, m1, h2, m2) << endl;
		}
		else
			cout << cnt(h1, m1, 23, 59) + cnt(0, 0, h2, m2) << endl;
	}
}

Double click to view unformatted code.


Back to problem 120