View Code of Problem 120

#include<stdio.h>
#include<math.h>

int main()
{
	int h1, m1, h2, m2;
	int t1, t2, t;
	int flag, count;
	while(scanf("%d:%d", &h1, &m1) != EOF)
	{
		count = 0;
		scanf("%d:%d", &h2, &m2);
		t1 = h1*60 + m1;
		t2 = h2*60 + m2;
		if(t2 < t1)
		{
			int tmp = t1;
			t1 = t2;
			t2 = tmp;
		}
		for(int i = t1; i <= t2; i++)
		{
			flag = 1;
			t = i/60*2500 + i%60;
			for(int j = 2; j <= sqrt(t); j++)
				if(t%j == 0)
				{
					flag = 0;
					break;
				}
			if(flag)
				count++;
		}
		printf("%d\n", count);
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 120