View Code of Problem 120

#include <iostream>
#include <valarray>

using namespace std;

/**
 * kkmd66
 * @return 
 */

int main() {

    int begin_h, begin_m;
    while (scanf("%d:%d", &begin_h, &begin_m) != EOF) {

        int end_h, end_m, count = 0;
        scanf("%d:%d", &end_h, &end_m);

        long long begin = begin_h * 60 + begin_m;
        long long end = end_h * 60 + end_m;

        for (int i = begin; i <= end; ++i) {
            bool flag = true;

            int minute = i % 60, hour = i / 60;
            long long result = hour * 2500 + minute;
            for (int j = 2; j <= sqrt(result); ++j) {
                if (result % j == 0) {
                    flag = false;
                    break;
                }
            }

            if (flag)
                count++;
        }

        cout << count << endl;

    }


    return 0;
}

Double click to view unformatted code.


Back to problem 120