题目描述
An Easy Task
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 28473 Accepted Submission(s): 18363
Problem Description
Ignatius was born in a leap year, so he want to know when he could hold his birthday party. Can you tell him?
Given a positive integers Y which indicate the start year, and a positive integer N, your task is to tell the Nth leap year from year Y.
Note: if year Y is a leap year, then the 1st leap year is year Y.
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains two positive integers Y and N(1<=N<=10000).
Output
For each test case, you should output the Nth leap year from year Y.
Sample Input
3
2005 25
1855 12
2004 10000
Sample Output
2108
1904
43236
Hint
We call year Y a leap year only if (Y%4==0 && Y%100!=0) or Y%400==0.
Author
Ignatius.L
原题链接
More info:Question
Accepted代码
直接暴力解,不超时。另外,闰年的计算按照题目要求的做,即认为满足(Y%4==0 && Y%100!=0)那么Y这年就可以被称为闰年。即不考虑大年份闰年的判别情况
但是实际上,闰年分为普通闰年和世纪闰年。
普通闰年:公历年份是4的倍数的,一般是闰年。(如2004年就是闰年);
世纪闰年:公历年份是整百数的,必须是400的倍数才是闰年(如1900年不是世纪闰年,2000年是世纪闰年);
大年份闰年:对于数值很大的年份,这年如果能整除3200,并且能整除172800则是闰年。如172800年是闰年,86400年不是闰年(因为虽然能整除3200,但不能整除172800)
1 | #include<iostream> |
Author: Zoey
Link: https://zoey1038569979.github.io/2019/08/09/hdoj1076/
Copyright: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.
关于HDOJ 1098题(Ignatius's puzzle) 的理解(C/C++)NextPost >
关于HDOJ 1058题(Humble Numbers(有且仅有质因数2,3,5,7组成的数)) 的理解(C/C++)