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. 用Java随机生成四则运算

    代码链接:https://github.com/devilwjy/Code.Demo 需求分析: 1.程序可接收一个输入参数n,然后随机产生n道加减乘除练习题,每个数字在 0 和 100 之间,运算符 ...

  2. TPCx-BB源码分析

    Copy from: 一篇文章看懂TPCx-BB(大数据基准测试工具)源码 TPCx-BB是大数据基准测试工具,它通过模拟零售商的30个应用场景,执行30个查询来衡量基于Hadoop的大数据系统的包括 ...

  3. Linux中CentOS6.5 64位 系统下安装docker步骤

    CentOS6.5 64位    (docker目前仅支持64位)内核必须在3.10及以上 1. uname -r  查看内核版本 2. 升级内核到3.10版本(带aufs模块)    cd /etc ...

  4. Codeforces 260B - Ancient Prophesy

    260B - Ancient Prophesy 思路:字符串处理,把符合条件的答案放进map里,用string类中的substr()函数会简单一些,map中的值可以边加边记录答案,可以省略迭代器访问部 ...

  5. English trip -- VC(情景课)8 C

    MP review: 音标(Phonetic symbol) [ɪ]    lit adj. 照亮的,点着的(light的过去式及过去分词)n. (Lit)人名:(瑞典)利特:(老)李 [ʊ]   g ...

  6. 20170709pptVBA递归删除LOGO图片与文字

    Public Sub StartRecursionFolder() Dim Pre As Presentation Dim FolderPath As String Dim pp As String ...

  7. Python下尝试实现图片的高斯模糊化

    资源下载 #本文PDF版下载Python下尝试实现图片的高斯模糊化#本文代码下载高斯模糊代码下载 高斯模糊是什么? (先来看一下维基百科对它的定义) 高斯模糊是模糊图像的结果.它是一种广泛使用的图形软 ...

  8. python-day16--内置函数

    内置函数操作 #!usr/bin/env python # -*- coding:utf-8 -*- # 1.locals()和globals() # def func(): # x=1 # y=2 ...

  9. python-day12--函数进阶

    1.命名空间: 分三种:全局命名空间,局部命名空间,内置命名空间. 加载顺序:内置命名空间→全局命名空间→局部命名空间 取值顺序:局部命名空间→全局命名空间→内置命名空间 2.作用域: 作用域就是作用 ...

  10. ABAP基础二:ALV基础之ALV的简单编辑

    前两天有个打印需求变更,需要在ALV显示列表中添加两个字段,可编辑,而我自己用的是函数:REUSE_ALV_GRID_DISPLAY_LVC 因为之前做可编辑基本都是固定套路,定义类,画屏幕.... ...