View Code of Problem 120

#include<iostream>
#include<cmath>
#include <string>
using namespace std;
struct zyh
{
	int hour;
	int min;
};
bool can(int a) {
	int flag = 1;
	if (a == 0||a==1)return 0;
	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 court = 0;
		zyh bg, end;
		bg.hour = stoi(a.substr(0, 2));
		bg.min = stoi(a.substr(3, 5));
		end.hour = stoi(b.substr(0, 2));
		end.min = stoi(b.substr(3, 5));
		int j = bg.min;
		for (int i = bg.hour; i <= end.hour; i++)
		{
			for (; j < 60; j++)
			{
				if (i == end.hour && j > end.min) {
					break;
				}
				if (can(i * 2500 + j)) {
					court++;
				}
			}
			j = 0;
		}
		cout << court << endl;
	}
}

Double click to view unformatted code.


Back to problem 120