#include <iostream> #include <math.h> using namespace std; bool isprime(int n){ if(n<=1) return false; 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,h,m,time1,time2; while(scanf("%2d:%2d",&h1,&m1)!=EOF){ scanf("%2d:%2d",&h2,&m2); count = 0; time1 = h1*60+m1; time2 = h2*60+m2; for(int j=time1;j<=time2;j++){ m = j%60; h = j/60; if(isprime(h*2500+m)) count++; } printf("%d\n",count); } return 0; } |
Double click to view unformatted code.