# ZOJ 3326 An Awful Problem(模拟)

An Awful Problem

Time Limit: 1 Second      Memory Limit: 32768 KB

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
#include <iostream>
#include <string.h>

#include <math.h>
#include <stdio.h>

using namespace std;
int tag[50];
int tag2[50];
int res[50];
int t;
int year1,month1,day1,year2,month2,day2;
int judge(int year)
{
if(year%4==0&&year%100!=0||year%400==0)
return 1;
else
return 0;
}
int ans;
int main()
{
memset(tag,0,sizeof(tag));
tag[2]=1;tag[3]=1;tag[5]=1;tag[7]=1;tag[11]=1;
tag[13]=1;tag[17]=1;tag[19]=1;tag[23]=1;tag[29]=1;tag[31]=1;
tag2[1]=31;tag2[3]=31;tag2[5]=31;tag2[7]=31;tag2[8]=31;
tag2[10]=31;tag2[12]=31;
tag2[2]=28;tag2[4]=30;tag2[6]=30;tag2[9]=30;tag2[11]=30;
memset(res,0,sizeof(res));
res[2]=9;
res[3]=11;
res[5]=11;
res[7]=11;
res[11]=10;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d%d%d%d",&year1,&month1,&day1,&year2,&month2,&day2);
ans=0;
int flag=0;
if(year1==year2&&month1==month2)
flag=-2;
while((year1<year2)||(year1==year2&&month1<=month2))
{
if(year1==year2&&month1==month2&&flag!=-2)
flag=-1;
if(tag[month1])
{
if(flag<=0)
{
int sum,num;
if(flag==0)
{
sum=day1;
num=tag2[month1];
if(judge(year1)&&month1==2)
num=29;
}
else if(flag==-1)
{

sum=1;
num=day2;
}
else if(flag==-2)
{
sum=day1;
num=day2;
}
for(int i=sum;i<=num;i++)
{
if(tag[i])
ans++;
}

}

else
{
if(judge(year1))
res[2]=10;
else
res[2]=9;
ans+=res[month1];

}

}
month1++;
flag=1;
if(month1>12)
{
month1=1;
year1++;
}

}
printf("%d\n",ans);
}
return 0;
}```

0 条评论

• ### 工作六年后，我对软件开发的认知转变

最近我司已经放假过年了，在家里就不免会多逛一些“稀奇古怪”的网站，通过阮一峰的每周新闻，发现了一篇比较不错的英文文章。

• ### 异构负载平衡系统中的随机协调

当今的数据中心和大批量的云服务采用了大量的异构服务器。在这样的环境中，客户的请求通常到达多个入口，将它们分配到服务器上是一个紧迫的分布式系统问题。本文为这类系统...

• ### HDUOJ-------（1022）Train Problem I

Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32...

• ### HDOJ/HDU 1022 Train Problem I(模拟栈)

Problem Description As the new term comes, the Ignatius Train Station is very ...

• ### ZOJ 3705 Applications

Recently, the ACM/ICPC team of Marjar University decided to choose some new memb...

• ### 【 CodeForces 604A】B - 特别水的题2-Uncowed Forces

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102271#problem/B

• ### 通过半确定编程实现多任务闭环逆运动学稳定性（CS RO)

当今复杂的机器人设计在某些情况下包含大量自由度，可实现多目标任务解析（例如，类人机器人或空中机械手）。本文针对这种高度冗余的机器人，解决了分层丢失环逆运动学算法...

• ### 使用强化学习自动合成稳态连续过程

自动流程图合成是计算机辅助过程工程中的重要领域。目前的工作演示了如何将强化学习（RL）用于自动化流程图合成，而无需对概念设计的先验知识进行任何启发。该环境由包含...

• ### 一种不确定性量化的糖尿病视网膜病变分类的主动学习方法（CS LG）

近年来，深度学习（DL）技术已在不同的医学成像任务上提供了最先进的性能。然而，由于所涉及的时间限制以及专家注释（例如放射线医生）的可用性，高质量注释医学数据的可...