hdu 1076 An Easy Task

来源:互联网 发布:ad hoc 路由算法 编辑:程序博客网 时间:2024/06/07 20:19

Description

Ignatius was born in a leap year, so hewant to know when he could hold his birthday party. Can you tell him?

 

Given a positive integers Y which indicatethe start year, and a positive integer N, your task is to tell the Nth leapyear from year Y.

 

Note: if year Y is a leap year, then the1st leap year is year Y.

 

Input

The input contains several test cases. Thefirst line of the input is a single integer T which is the number of testcases. T test cases follow.

Each test case contains two positiveintegers Y and N(1<=N<=10000).

 

Output

For each test case, you should output theNth 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.


题意:输入一个年份,计算从输入年份开始的第几个闰年是哪一年,并输出年份。需要考虑到闰年并不是四年一次,也有可能八年一次。闰年的判断的条件:普通年份能整除4,不能整除100,以00结尾的年份能整除400。


#include<stdio.h>int main(){    int t,y,n,count=0,k;    scanf("%d",&t);    while(t--)    {        count=0;        scanf("%d%d",&y,&n);        while(count<n)        {            if((y%4==0&&y%100!=0)||(y%400==0))            {                k=y;                y+=4;                count++;            }            else y++;        }        printf("%d\n",k);    }    return 0;}


0 0
原创粉丝点击