HDU 1076 An Easy Task

An Easy Task

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 17145    Accepted Submission(s): 10946


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
 

 

Recommend
We have carefully selected several similar problems for you:  1021 1097 1040 1013 1004
 
 
 1 #include<math.h>
 2 #include<stdio.h>
 3 #include<string.h>
 4 #include<iostream>
 5 #include<algorithm>
 6 using namespace std;
 7 
 8 bool judge(int Y)
 9 {
10     if( (Y%4==0 && Y%100!=0) || Y%400==0 )return 1;
11     else return 0;
12 }
13 
14 int n,y;
15 
16 int main()
17 {
18     int t;cin>>t;
19     while(t--)
20     {
21         scanf("%d%d",&y,&n);
22         int i=0;
23         while(1)
24         {
25 
26             if(judge(y))i++;
27             if(i==n){printf("%d\n",y);break;}
28             y++;
29         }
30     }
31     return 0;
32 }
33 
34 //freopen("1.txt", "r", stdin);
35     //freopen("2.txt", "w", stdout);
36 //**************************************

 

posted @ 2015-07-20 22:02  wmxl  阅读(189)  评论(0编辑  收藏  举报