In order to encourage Hiqivenfin to study math, his mother gave him a sweet candy when the day of the month was a prime number. Hiqivenfin was happy with that. But several days later, his mother modified the rule so that he could get a candy only when the day of the month was a prime number and the month was also a prime number. He felt a bit upset because he could get fewer candies. What's worse, his mother changed the rule again and he had to answer a question before he could get a candy in those days. The question was that how many candies he could get in the given time interval. Hiqivenfin wanted to cry and asked you for help. He promised to give you half of a candy if you could help him to solve this problem.

Input

There are multiple test cases. The first line of input is an integer T (0 < T <= 50), indicating the number of test cases. Then T test cases follow. The i-th line of the next T lines contains two dates, the day interval of the question. The format of the date is "yyyy mm dd". You can assume both dates are valid. Hiqivenfin was born at 1000-01-01 and would not die after 2999-12-31, so the queries are all in this interval.

Hiqivenfin didn't seem to be an earthman, but the calendar was the same as that we usually use. That is to say, you need to identify leap years, where February has 29 days. In the Gregorian calendar, leap years occur in years exactly divisible by four. So, 1993, 1994, and 1995 are not leap years, while 1992 and 1996 are leap years. Additionally, the years ending with 00 are leap years only if they are divisible by 400. So, 1700, 1800, 1900, 2100, and 2200 are not leap years, while 1600, 2000, and 2400 are leap years.

Output

Output the number of candies Hiqivenfin could get in the time interval. Both sides of the interval are inclusive.

Sample Input

2
1000 01 01 1000 01 31
2000 02 01 2000 03 01

Sample Output

0
10

这个一开始想复杂了后来想想只要开一个三维数组把到这天的可以拿糖的个数放上去,至于两者之间直接剪一下就可,但是要注意如果起始点是素数月、天要总数++,忘了这个点不小心wa了一发

#include <iostream>

#include <string.h>

#include <cmath>

using namespace std;

struct node

{

    int year;

    int month;

    int day;

}st,ed;

int check(int year)

{

    if((year%==&&year%!=)||year%==)

        return ;

    else

        return ;

}

int isprime(int n)

{

    int flag=;

    for(int i=;i*i<=n;i++)

    {

        if(n%i==)

        {

            flag=;

            break;

        }

    }

    if((flag&&n!=)||n==)return ;

    else

        return ;

}

int month[]={,,,,,,,,,,,,};

int ans[][][];

void solveit()

{

    int sum=;

    for(int y=;y<=;y++)

    {

        if(check(y))

            month[]=;

        else

            month[]=;   

        for(int m=;m<=;m++)

        {

            for(int d=;d<=month[m];d++)

            {

                if(isprime(m)&&isprime(d))

                    sum++;

                ans[y][m][d]=sum;

            }

        }

    }

}

int main()

{

    int t;

    cin>>t;

    memset(ans, , sizeof(ans));

    solveit();

    while (t--) {

        cin>>st.year>>st.month>>st.day;

        cin>>ed.year>>ed.month>>ed.day;

        int days=ans[ed.year][ed.month][ed.day]-ans[st.year][st.month][st.day];

        if(isprime(st.month)&&isprime(st.day))days++;

        cout<<days<<endl;

    }

    return ;

}

E - An Awful Problem 求两段时间内满足条件的天数//lxm的更多相关文章

  1. PHP 求两个日期之间相差的天数、月数

    <?php /** * 求两个日期之间相差的天数 * (针对1970年1月1日之后,求之前可以采用泰勒公式) * @param string $day1 * @param string $day ...

  2. MySql 求一段时间范围内的每一天,每一小时,每一分钟

    平常经常会求一段时间内的每一天统计数据,或者每一时点的统计数据.但是mysql本身是没有直接获取时点列表的函数或表.下面是自己用到的一些方法,利用临时变量和一个已存在的比较多数据(这个需要根据实际情况 ...

  3. 【u124】环状最大两段子段和

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 给出一段环状序列,即认为A[1]和A[N]是相邻的,选出其中连续不重叠且非空的两段使得这两段和最大. ...

  4. js 求两个日期之间相差天数

    //求两个日期之间的相差天数 function daysBetween(DateOne, DateTwo) { var OneMonth = DateOne.substring(5, DateOne. ...

  5. java 求取某一段时间内的每一天、每一月、每一年

    1.求取某一段时间内的每一天 Date date0 = new SimpleDateFormat("yyyy-MM-dd").parse("2014-01-01" ...

  6. POJ 2479 两段连续最大和

    题目大意: 在一组数中,找到连续的两段 , 是这两段相加和达到最大 这里利用dp[2][N]的数组保存所有的状态 dp[0][i]表示取到第i个数时只取了一段的最大和,第i个数是一定要被取到的 dp[ ...

  7. [LeetCode] Intersection of Two Linked Lists 求两个链表的交点

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  8. 求两条线段交点zz

    "求线段交点"是一种非常基础的几何计算, 在很多游戏中都会被使用到. 下面我就现学现卖的把最近才学会的一些"求线段交点"的算法说一说, 希望对大家有所帮助. 本 ...

  9. storm入门(二):关于storm中某一段时间内topN的计算入门

    刚刚接触storm 对于滑动窗口的topN复杂模型有一些不理解,通过阅读其他的博客发现有两篇关于topN的非滑动窗口的介绍.然后转载过来. 下面是第一种: Storm的另一种常见模式是对流式数据进行所 ...

随机推荐

  1. android开发:Android 中自定义属性(attr.xml,TypedArray)的使用

    今天我们的教程是根据前面一节扩展进行的,如果你没有看,请点击 Android高手进阶教程(三)查看第三课,这样跟容易方便你的理解! 在xml 文件里定义控件的属性,我们已经习惯了android:att ...

  2. Codeforces 496D - Tennis Game

    496D - Tennis Game 思路:枚举每个t,求出对应的满足条件的s. 代码: #include<bits/stdc++.h> using namespace std; #def ...

  3. WPF中的Style(风格,样式)

    作者: 周银辉  来源: 博客园  发布时间: 2009-02-27 15:04  阅读: 6698 次  推荐: 0   原文链接   [收藏]   在WPF中我们可以使用Style来设置控件的某些 ...

  4. 3-23Agile Web Development,3-24(chapter: 6)

    第2章 Instant Gratification 复习 和 练习第一章,新建rails web页面. 重点: 知道了类,方法,实例变量 在rails是怎么用的. rails generate con ...

  5. Python基础--Python简介和入门

    ☞写在前面 在说Python之前,我想先说一下自己为什么要学Python,我本人之前也了解过Python,但没有深入学习.之前接触的语言都是Java,也写过一些Java自动化用例,对Java语言只能说 ...

  6. 二分求LIS并打印结果

    1275: God's ladder [DP] 时间限制: 1 Sec 内存限制: 128 MB  Special Judge 题目描述 天明来到神之宫殿,在他眼前出现了若干个石柱,每个石柱上有1枚金 ...

  7. 在菜鸟教程学 HTML(一)

    注意:对于中文网页需要使用 <meta charset="utf-8"> 声明编码,否则会出现乱码.有些浏览器会设置 GBK 为默认编码,则你需要设置为 <met ...

  8. 多态性&& 虚函数 && 抽象类

    http://www.cnblogs.com/CaiNiaoZJ/archive/2011/08/11/2134673.html 多态性 指相同对象收到不同消息或不同对象收到相同消息时产生不同的实现动 ...

  9. OC 设计模式

    设计模式 一种或几种被所有程序员广泛认同的,有某些特定功能,或者实现某些特殊作用的编码格式 单例模式 键值编码(KVC) 键值观察(KVO) 观察者模式() 工厂模式(工厂方法) ps:MVC &am ...

  10. python3 scrapy 爬取腾讯招聘

    安装scrapy不再赘述, 在控制台中输入scrapy startproject tencent 创建爬虫项目名字为 tencent 接着cd tencent 用pycharm打开tencent项目 ...