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.

题意就是:输入一个年份year和一个n,求这个year之后的第n个闰年,

如果year是闰年,则算第一个闰年。

直接暴力做,并没有超时。

import java.util.Scanner;

public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int year = sc.nextInt();
int n = sc.nextInt();
int nyear = 0;
if((year%4==0&&year%100!=0)|(year%400==0)){
nyear=1;
}//如果year是闰年,nyear就加一
while(nyear<n){//当nyear小于n时,就循环
year++;
if((year%4==0&&year%100!=0)|(year%400==0)){
nyear++;
}//year是闰年,nyear就加加
}
System.out.println(year);
}
} }

HDOJ 1076 An Easy Task(闰年计算)的更多相关文章

  1. 【HDOJ】1076 An Easy Task

    水题,如题. #include <stdio.h> #define chk(Y) (Y%4==0 && Y%100!=0) || Y%400==0 int main() { ...

  2. HDU 1076 An Easy Task

    题解:枚举即可…… #include <cstdio> int main(){ int now,y,n,T,count; scanf("%d",&T); whi ...

  3. An Easy Task

    An Easy Task Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  4. HDU-------An Easy Task

    An Easy Task Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

  5. HDU-1076-An Easy Task(Debian下水题測试.....)

    An Easy Task Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot ...

  6. CodeForces462 A. Appleman and Easy Task

    A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input sta ...

  7. ZOJ 2969 Easy Task

    E - Easy Task Description Calculating the derivation of a polynomial is an easy task. Given a functi ...

  8. An Easy Task(简箪题)

    B. An Easy Task Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO f ...

  9. Codeforces 263A. Appleman and Easy Task

    A. Appleman and Easy Task time limit per test  1 second memory limit per test  256 megabytes input  ...

随机推荐

  1. C++读写文件并排序

    比如一条记录是 1987 9 2 1988 8 26 代表公司员工生日 然后需要读入到系统 现在需要放入容器,并且排序 最后输出到新的文件中,按照年龄由大到小. #include "stda ...

  2. unity3d 版本问题

    version: 4.2.1f4 1. 安装以后,不要启动,把exe拷贝覆盖. 2. 断网(重点,不断的话你试试就知道了) 3. 打开unity3d, 点击load License 4. 把ulf导入 ...

  3. Qt Sqlite封装类SqliteUtil

    在网上找了很久关于Qt访问Sqlite数据库的封装类,但是没能找到一个很好的访问调用类,自己写了一个出来,在这里分享一下,希望能对大家有所帮助,小弟不才,写代码没多少经验,如果有什么不恰当之处,请批评 ...

  4. 关于DOS下启动MySQL时提示服务名无效

    主要原因:启动时:net start mysql 而打开服务后发现,本地服务中mysql这个服务实际名字为mysql55,故启动语句应为:net  start mysql55: 以下摘自课程提问: 你 ...

  5. NYOJ 284 坦克大战 bfs + 优先队列

    这类带权的边的图,直接广搜不行,要加上优先队列,这样得到的结果才是最优的,这样每次先找权值最小的,代码如下 #include <stdio.h> #include <iostream ...

  6. OD: File Vulnerabilities & Protocols & Fuzz

    IE.Office 等软件有个共同点,即用文件作为程序的主要输入,但攻击者往往会挑战程序员的假定和假设. 文件格式 Fuzz 就是利用畸形文件测试软件的稳健性,其流程一般包括: * 以一个正常文件作为 ...

  7. MySQL性能调优与架构设计读书笔记

    可扩展性设计之数据切分 14.2 数据的垂直切分 如何切分,切分到什么样的程度,是一个比较考验人的难题.只能在实际的应用场景中通过平衡各方面的成本和利益,才能分析出一个真正适合自己的拆分方案. 14. ...

  8. java反射机制(工厂模式)

    http://www.phpddt.com/dhtml/338.html java里面没有typeof,js有. 我终于实现了用反射机制编写的工厂模式.java反射在工厂模式可以体现. 包含产品接口类 ...

  9. Android开发中在一个Activity中关闭另一个Activity

    比如有ActivityA, ActivityB,在ActivityB中关闭ActivityA 解决方案: 1. 在 ActivityA 里面设置一个静态的变量instance,初始化为this在 Ac ...

  10. 网页上facebook分享功能的具体实现

    1,一个链接: 参数是要分享的页面的链接 代码如下: <a style="width:35px; height:40px; position:relative; top:10px; l ...