View Code of Problem 120

#include<stdio.h>
int isPrime(int k);
int main()

{
    int a,b,c,d,i,j,k,count;
    int m,n;
    while(scanf("%d:%d",&a,&b)!=EOF&&scanf("%d:%d",&c,&d)!=EOF)
    {
        count=0;
        m=a*60+b;
        n=c*60+d;
        for(i=m;i<=n;i++)
        {   j=(i/60)*2500+i%60;
            k=isPrime(j);
            if(k==1) count++;
        }
        printf("%d\n",count);
    }


}

int isPrime(int k)
{
    int j;
    for ( j=2; j<k; j++ )
    {
        if(k%j==0)    // 如果不为素数返回0
        {
             return 0;
        }
        }
    return 1;    // 反之则返回1
}

Double click to view unformatted code.


Back to problem 120