View Code of Problem 120

#include<iostream>
#include<string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <cmath>
#include<cstring>
using namespace std;
int sh(int n)
{
	if (n == 0 || n == 1)
		return 0;
	if (n == 2 || n == 3)
		return 1;
	for (int i = 2;i < (int)sqrt(n) + 1;i++)
	{
		if (n%i == 0)
			return 0;
	}
	return 1;
}
int main()
{
	int h1, t1, h2, t2;
	char z;
	while (cin >> h1 >> z >> t1 >> h2 >> z >> t2)
	{
		int cnt = 0;
		int num1 = h1 * 60 + t1;
		int num2 = h2 * 60 + t2;
		for (int i = num1;i <= num2;i++)
		{
			int h = i / 60;
			int t = i % 60;
			long long num = h * 2500 + t;
			if (sh(num) == 1)
				cnt++;
		}
		cout << cnt << endl;
	}
	
	
}

Double click to view unformatted code.


Back to problem 120