View Code of Problem 120

#include <stdio.h>
#include <string.h>
#include <math.h>
#define N 10000
int is(int n)
{
	int i,flag=1;
	for(i=2;i<n;i++)
		if(n%i==0)
			return 0;
	return flag;
}

int main()
{
	int i,j;
	int d1,d2,d3,d4;
	while(scanf("%d:%d",&d1,&d2)!=EOF)
	{
		int count=0;
		scanf("%d:%d",&d3,&d4);
		if(d1==d3)
			for(i=d2;i<=d4;i++)
				if(is(d1*2500+i))
					count++;
		if(d1<d3)
		{
			for(i=d2;i<=60;i++)
				if(is(d1*2500+i))
					count++;
			for(i=d1+1;i<d3;i++)
				for(j=0;j<=60;j++)
					if(is(i*2500+j))
						count++;
			for(i=0;i<=d4;i++)
				if(is(d3*2500+i))
					count++;	
		}
		printf("%d\n",count);
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 120