View Code of Problem 120

#include <iostream>
#include <math.h>
using namespace std;

bool isprime(int n){
  if(n==1)
    return true;
  int bound = (int)sqrt(n)+1;
  for(int j=2;j<bound;j++){
    if(n%j==0)
      return false;
  }
  return true;
}

int main(){
  int h1,m1,h2,m2,sum,count;
  while(scanf("%2d:%2d",&h1,&m1)!=EOF){
    scanf("%2d:%2d",&h2,&m2);
    count = 0;
    for(int j=h1;j<=h2;j++){
      for(int k=m1;k<=m2;k++){
        sum = j*2500+k;
        if(isprime(sum))
          count++;
      }
    }
    printf("%d\n",count);
  }
  return 0;
}

Double click to view unformatted code.


Back to problem 120