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. JNI- java.lang.UnsatisfiedLinkError: Native method not found

    http://stackoverflow.com/questions/24566127/jni-java-lang-unsatisfiedlinkerror-native-method-not-fou ...

  2. HTML学习笔记之二(回到顶部 与 回究竟部)

    回到顶部 回究竟部 回到顶部的俩种方式 一.使用js $('html, body').animate({ scrollTop: 0 }, 'fast');//带动画 $('html,body').sc ...

  3. win7 无线网络无法启动

    开始菜单-运行输入services.msc然后确定!找到WLAN Autoconfig这一项,启动此项服务,一切就OK了

  4. 如何实现数字lcd显示效果(原创)

    如题,我最先想到的是找一种字体,然后来显示lcd的效果,但是字体又无法满足有空位的时候那个暗灰色的文字的效果,如下所示 就是前三位那些灰色的888,因为你设置数值的时候只能是从0-9的数字,而这灰色的 ...

  5. SpannableString的一个奇怪的问题

    今天使用spannableString遇到一个奇怪的问题,就是在setspan的时候,原本可以写成 spannableString.setSpan(new RelativeSizeSpan(0.5f) ...

  6. yii cgridview 默认的筛选如何做成选择框

    效果图 参照 http://www.yiiframework.com/doc/api/1.1/CGridColumn http://www.yiiframework.com/doc/api/1.1/C ...

  7. LSI SAS 3108 配置操作

    配置LSISAS3108 介绍LSISAS3108的配置操作. 5.1 登录CU界面 介绍登录LSISAS3108的CU配置界面的方法,以及CU界面的主要功能. 5.2 创建RAID 介绍在LSISA ...

  8. Python第一课

    一.模块的常用方法 __name__     #主模块name值main __file__    #文件所在的路径+文件名 __doc__    #文件级别的注释 二.函数 参数 参数默认值 可变参数 ...

  9. 网页JavaScript3

    window.document 1,确认元素, document.getElementById("id");           根据id找元素 doucment.getEleme ...

  10. sql server根据日期或者月份查询聚合数据

    /*****************************根据时间查询每天的数据***************************************/ @tm_start:开始时间 @tm ...