View Code of Problem 120

#include "stdlib.h"
#include "algorithm"
#include "iostream"
#include <cstdio>
#include "string"
#include <iomanip>
#include <map>
#include <set>
#include "math.h"
using namespace std;
map<int, bool> mp;
set<string> st;

int judge(int n)
{
	int i;
	for (int i = 2; i <= sqrt(n); i++)
	{
		if (n%i == 0)
		{
			return 0;
			break;
		}
	}
	return 1;
}
int main() 
{
	int h1,h2,m1,m2;
	while (scanf("%d:%d", &h1, &m1) != EOF) 
	{
		scanf("%d:%d", &h2, &m2);
		int sum = 0;
		for (int i = h1; i <= h2; i++) 
		{
			if (h1 == h2) 
			{
				for (int j = m1; j <= m2; j++) 
				{
					int s = j + i * 2500;
					if (judge(s))sum++;
				}
			}
			else if (h1<h2) 
			{
				if (i == h1) 
				{
					for (int j = m1; j<60; j++) 
					{
						int s = j + i * 2500;
						if (judge(s))sum++;
					}
				}
				if (i != h1 && i != h2) 
				{
					for (int j = 0; j<60; j++) 
					{
						int s = j + i * 2500;
						if (judge(s))sum++;
					}
				}
				if (i == h2) 
				{
					for (int j = 0; j <= m2; j++) 
					{
						int s = j + i * 2500;
						if (judge(s))sum++;
					}
				}
			}
		}
		cout << sum << endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 120