Description
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
这个题目其实还是浙江省赛中除了那三道水题之外,我唯一能做出来的题目,惭愧,
自己实在是太水了,!!!!
这题目的意思是说这个两个日期之间包括符合月也是素数,同时日也是素数
的日子到底有多少,把所有的情况列举
一下,一个年份从这个月到那个月的,然后再减去这个月之前那些天的,
举个例子,我再算时如果是5月17日,那么
就把5月2日到5月17日的日子减去就是了,不包含5月17,然后再开始算那
些是不是一年的,把年份也算上,瑞年的
是53,平年就是52,然后算算就是了!!!!!!
#include<iostream> #include<cstdio> using namespace std; int month(int m) { if(m==2||m==3||m==5||m==7||m==11) return 1; return 0; } int day(int t) { if(t==2||t==3||t==5||t==7||t==11||t==13||t==17 ||t==19||t==23||t==29||t==31)//11个 return 1; return 0; } int year(int x) { if(x%400==0||(x%100!=0&&x%4==0)) return 1; return 0; } int main() { int i,j,k; int a,b,c,a1,b1,c1; int t; scanf("%d",&t); int sum=0; while(t--) { sum=0; scanf("%d%d%d%d%d%d",&a,&b,&c,&a1,&b1,&c1); if(a==a1) { if(b==b1) { if(month(b)) { for(i=c; i<=c1; i++) { if(day(i)) sum++; } } } if(b<b1) { for(i=b; i<b1; i++) { if(month(i)) { if((year(a))&&(i==2)) sum=sum+10; else if((!year(a))&&(i==2)) sum=sum+9; else if(i==11) sum=sum+10; else sum=sum+11; } } if(month(b)) { for(i=2; i<c; i++) { if(day(i)) sum--; } } if(month(b1)) { for(i=2; i<=c1; i++) if(day(i)) sum++; } } } if(a<a1) { for(i=a+1; i<a1; i++) if(year(i)) sum=sum+53; else sum=sum+52; for(i=b; i<12; i++) { if(month(i)) { if((year(a))&&(i==2)) sum=sum+10; else if((!year(a))&&(i==2)) sum=sum+9; else if(i==11) sum=sum+10; else sum=sum+11; } } if(month(b)) for(i=2; i<c; i++) { if(day(i)) sum--; } for(i=2; i<b1; i++) { if(month(i)) { if((year(a1))&&(i==2)) sum=sum+10; else if((!year(a1))&&(i==2)) sum=sum+9; else if(i==11) sum=sum+10; else sum=sum+11; } } if(month(b1)) { for(i=2; i<=c1; i++) { if(day(i)) sum++; } } } printf("%d\n",sum); } return 0; }