E - An Awful Problem 求两段时间内满足条件的天数//lxm
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的更多相关文章
- PHP 求两个日期之间相差的天数、月数
<?php /** * 求两个日期之间相差的天数 * (针对1970年1月1日之后,求之前可以采用泰勒公式) * @param string $day1 * @param string $day ...
- MySql 求一段时间范围内的每一天,每一小时,每一分钟
平常经常会求一段时间内的每一天统计数据,或者每一时点的统计数据.但是mysql本身是没有直接获取时点列表的函数或表.下面是自己用到的一些方法,利用临时变量和一个已存在的比较多数据(这个需要根据实际情况 ...
- 【u124】环状最大两段子段和
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 给出一段环状序列,即认为A[1]和A[N]是相邻的,选出其中连续不重叠且非空的两段使得这两段和最大. ...
- js 求两个日期之间相差天数
//求两个日期之间的相差天数 function daysBetween(DateOne, DateTwo) { var OneMonth = DateOne.substring(5, DateOne. ...
- java 求取某一段时间内的每一天、每一月、每一年
1.求取某一段时间内的每一天 Date date0 = new SimpleDateFormat("yyyy-MM-dd").parse("2014-01-01" ...
- POJ 2479 两段连续最大和
题目大意: 在一组数中,找到连续的两段 , 是这两段相加和达到最大 这里利用dp[2][N]的数组保存所有的状态 dp[0][i]表示取到第i个数时只取了一段的最大和,第i个数是一定要被取到的 dp[ ...
- [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 ...
- 求两条线段交点zz
"求线段交点"是一种非常基础的几何计算, 在很多游戏中都会被使用到. 下面我就现学现卖的把最近才学会的一些"求线段交点"的算法说一说, 希望对大家有所帮助. 本 ...
- storm入门(二):关于storm中某一段时间内topN的计算入门
刚刚接触storm 对于滑动窗口的topN复杂模型有一些不理解,通过阅读其他的博客发现有两篇关于topN的非滑动窗口的介绍.然后转载过来. 下面是第一种: Storm的另一种常见模式是对流式数据进行所 ...
随机推荐
- bzoj 4403 序列统计 卢卡斯定理
4403:序列统计 Time Limit: 3 Sec Memory Limit: 128 MB Description 给定三个正整数N.L和R,统计长度在1到N之间,元素大小都在L到R之间的单调 ...
- Jmeter 中多线程并发和循环控制器
今天遇到一个场景, 给一个手机号发送短信验证码,通过正确输入短信验证码即登录并获得token,进行其他操作. 短信验证码是4位,即9999个组合, 接口没有对验证次数做校验,所以可以一直一直尝试通过验 ...
- PROC怎么遇到错误全局rollback---SQLServer 异常的处理
ALTER PROCEDURE [dbo].[PROC_SMSACTIVE_UPDATE] AS BEGIN SET XACT_ABORT ON
- 【Jmeter】Linux(Mac)上使用最新版本Jmeter(5.0)做性能测试
本文我们一起来学习在Linux(Mac)上利用Jmeter进行性能测试并生成测试报告的方法. 环境准备 JDK 访问这个地址 [JDK11.01],根据实际环境下载一个JDK. Jmeter Jmet ...
- Java JDK5新特性-静态导入
2017-10-31 00:10:50 静态导入格式:import static 包名 ...类名.方法名: 也就说可以直接导入到方法名. 注意: 方法必须是静态的 如果有多个同名的静态方法,容易不知 ...
- secureCRT启动xmanager图形化工具
secureCRT启动xmanager图形化工具 2014年9月17日 11:42 secureCRT是我们在维护UNIX或者linux的重要工具.xmanager 工具是连接UNIX或者linux的 ...
- gvim配置文件
vimrc配置 source $VIMRUNTIME/vimrc_example.vim source $VIMRUNTIME/mswin.vim behave mswin "设置文件的 ...
- JavaScript学习总结(十)——this关键字
1 <script type="text/javascript"> 2 function Person(){ 3 /*使用var 属性名定义的属性是类的私有属性,外界无 ...
- Spring Boot 学习(一) 快速搭建SpringBoot 项目
快速搭建一个 Spring Boot 项目 部分参考于<深入实践Spring Boot>.<Spring实战 第四版>与程序猿DD的有关博客. 参考(嘟嘟独立博客):http: ...
- stimulsoft report工具—— 简单的多表连接打印报表例子
一.用报表工具打印多个表格信息(包括学生表.教师表.班级表) 1.准备打印的数据(用sqlserver) 1)班级表