View Code of Problem 120

#include<stdio.h>
#include<math.h>
int isprime(int a,int b);
int main(){
	
	int h1,m1;
	while(scanf("%d:%d",&h1,&m1)!=EOF){
		int h2,m2;
		scanf("%d:%d",&h2,&m2);
		int count=0;
		for(int i=h1;i<=h2;i++){
			for(int j=m1;j<=m2;j++){	
				if(isprime(i,j)==1){
					count++;
				} 
			}
		}
		
	printf("%d\n",count);	
	}
	
	return 0;
}
int isprime(int a,int b){
	int sum=a*2500+b;
	int flag=1;
	if(a==0&&b==2){
		flag=1;
	}else if(a==0&&b==1){
		flag=0;
	}else {
		for(int i=2;i<=sqrt(sum);i++){
			if(sum%i==0){
				flag=0;
				break;
			}
			
		}
	} 

	return flag;	
} 

Double click to view unformatted code.


Back to problem 120