View Code of Problem 120

# include<stdio.h>
# include<math.h>
# include<stdbool.h>
bool isPrime(int n){
	bool flag=true;
	if(n==0||n==1){
		flag=false;
	}
	for(int i=2;i<=sqrt(n);i++){
		if(n%i==0){
			flag=false;
			break;
		}
	}
	return flag;
}
int main(){
	int h1,m1,h2,m2,t1,t2,count;
	int t,h,m;
	while(scanf("%d:%d %d:%d",&h1,&m1,&h2,&m2)!=EOF){
		count=0;
		t1=h1*60+m1;
		t2=h2*60+m2;
		t=t1;
		h=h1;
		m=m1;
		while(t1<=t&&t<=t2){
			if(isPrime(h*2500+m)){
				count++;
			}
			t++;
			h=t/60;
			m=t%60;
		}
		printf("%d",count);
	}
	return 0;
} 

Double click to view unformatted code.


Back to problem 120