View Code of Problem 120

#include<iostream>
#include<cmath>
#include <string>
using namespace std;
bool can(int a) {
	int flag = 1;
	for (int i = 2; i < sqrt(a)+1; i++)
	{
		if (a % i == 0) {
			flag = 0;
			break;
		}
	}
	return flag;
}
int main() {
	string a, b;
	while (cin >> a) {
		cin >> b;
		int hour =stoi(b.substr(0, 2)) - stoi(a.substr(0, 2)),
			min = stoi(b.substr(3, 5)) - stoi(a.substr(3, 5)),
			court=0;
		for (int j = min; j >= 0; j--)
		{
			if (can(hour * 2500 + j)) {
				court++;
			}
		}
		hour--;
		for (int i = hour; i >=0; i--)
		{
			for (int j = 60; j >0; j--)
			{
				if (can(i * 2500 + j)) {
					court++;
				}
			}
		}
		cout << court << endl;
	}
}

Double click to view unformatted code.


Back to problem 120