View Code of Problem 120

#include<bits/stdc++.h>
using namespace std;
#define max 60000	
bool pri[max] = {0};
void find();
int main(){     
	find();
	pri[0] = true; 
	pri[1] = true;
	int hour1,min1,hour2,min2,start,stop,H,M;
	while(scanf("%d:%d %d:%d",&hour1,&min1,&hour2,&min2)!=EOF){
		int num = 0;
//		stop = hour2 * 2500 + min2;
//		start = hour1 * 2500 + min1;
		H = hour1 * 60 + min1;
		M = hour2 * 60+ min2;
		for(int i = H ;i<=M ;i++){
			start = i/60;
			stop = i%60;
			if(pri[start*2500+stop]==false)num++;
		}
		cout<<num<<endl;
	}		
	return 0;
}  


void find(){
	for(int i = 2;i<max;i++){
		if(pri[i]==false){
			for(int j = i*2;j<max;j+=i) pri[j] = true;
		}
	}
}

Double click to view unformatted code.


Back to problem 120