View Code of Problem 120

#include <stdio.h>

typedef struct node{
    int hour,munite;
}tm;

int Issu(int n)
{
    int i;
    if(n == 1 || n == 0)
        return 0;
    else
    {
        for(i = 2;i <= n / 2;i++)
        {
            if(n % i == 0)
                return 0;
        }
        return 1;
    }
}

int main(void)
{
    int a,b,h,i,j;
    while(scanf("%2d:%2d",&a,&b) != EOF)
    {
        tm t[2];
        int index = 0;
        t[0].hour = a,t[0].munite = b;
        scanf("%2d:%2d",&t[1].hour,&t[1].munite);
        h = t[1].hour - t[0].hour;
        if(!h)
        {
            for(i = t[0].munite;i <= t[1].munite;i++)
            {
                if(Issu(2500 * h + i))
                   index++;
            }
        }
        else
        {
            for(i = t[0].munite;i <= 59;i++)
            {
                if(Issu(2500 * t[0].hour + i))
                    index++;
            }
            for(i = 0;i <= t[1].munite;i++)
            {
                if(Issu(2500 * t[1].hour + i))
                    index++;
            }
            if(h >= 2)
            {
                for(j = t[0].hour + 1;j < t[1].hour;j++)
                {
                    for(i = 0;i < 60;i++)
                    {
                        if(Issu(2500 * j + i))
                            index++;
                    }
                }
            }
        }
        printf("%d\n",index);
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 120