#include<iostream> #include<math.h> using namespace std; int prime(int n){ if(n==0||n==1)return 0; for(int i=2;i<=sqrt(n);i++){ if(n%i==0)return 0; } return 1; } int main(){ char ch; int hs; int ms; int he; int me; while(~scanf("%d:%d",&hs,&ms)){ scanf("%d:%d",&he,&me); int sum; int c=0; //cout<<hs<<ms<<he<<me; for(int i=hs;i<=he;i++){ if(hs==he){ for(int j=ms;j<=me;j++){ sum=hs*2500+j; if(prime(sum)==1){ c++; } } break; } else if(hs<he){ if(i==hs){ for(int j=ms;j<=59;j++){ sum=hs*2500+j; if(prime(sum)==1){ c++; } } } else if(i>hs&&i<he){ for(int j=0;j<=59;j++){ sum=i*2500+j; if(prime(sum)==1){ c++; } } } else if(i==he){ for(int j=0;j<=me;j++){ sum=i*2500+j; if(prime(sum)==1){ c++; } } } } } cout<<c<<'\n'; } } |
Double click to view unformatted code.