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. intent的startActivityForResult()方法

      /******************************************************************************************** * au ...

  2. HDU1247 Hat’s Words 【trie树】

    Hat's Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  3. apache 配置https(转)

    主要讲述在windows下apache配置SSL以实现http转换为https SSL: SSl是为Http传输提供安全的协议,通过证书认证来确保客户端和网站服务器之间的数据是安全.也就是说在SSL下 ...

  4. Javascript 第一阶段 学习使用总结

    JavaScript 是一种轻量级的编程语言.JavaScript 是可插入 HTML 页面的编程代码.脚本可被放置在 HTML 页面的 <body> 和 <head> 部分中 ...

  5. Linux shell入门基础(三)

    三.输入输出重定向及管道 01.过滤器   Linux过滤器分三种:     1.过滤器(重定向只对过滤器有作用) #gzip a(将a作为输入源,涉及到输入输出)     2.编辑器     3.交 ...

  6. nginx 1.安装

    nginx 1.安装 nginx的众多优点这里就不多说了,直接开始吧. 基本依赖 yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel ...

  7. PHP编写的SVN类

    <?php /** * SVN 外部命令 类 * * @author rubekid * * @todo comment need addslashes for svn commit * */ ...

  8. WebStorm修改默认快捷键

    打开 "File" -> "Setting" -> "keymap",即可修改.

  9. 在浏览器中打不开Oracle 11gR2的企业管理器页面

    最简单的办法,重建EM 四个步骤: emca -repos drop emca -repos create emca -config dbcontrol db emctl start dbconsol ...

  10. Swift中的延迟加载(懒加载)

    Swift方式的延迟加载 而在Swift中,你只需一行代码即可实现此机制: lazy var players = String[]() 简单.简洁,直入主题. 但你得记住,你必须使用var关键字来定义 ...