欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

hdu 1076 An Easy Task

程序员文章站 2022-07-05 23:45:00
time limit: 2000/1000 ms (java/others)memory limit: 65536/32768 k (java/others) total submission(s)...
time limit: 2000/1000 ms (java/others)memory limit: 65536/32768 k (java/others)
total submission(s): 19908accepted submission(s): 12725



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

 

y 开始以后的第n个闰年

闰年为能被4整除不能被100整除 或者被400整除

 

#include 
int main()
{
	int ncase;
	scanf("%d",&ncase);
	while(ncase--)
	{
		int year,n;
		scanf("%d %d",&year,&n);
		for(int i=year;;i++)
		{
			if((i%4==0&&i%100)||i%400==0)
			n--;
			if(n==0)
			{
				printf("%d\n",i);
				break;
			}
		}
	}
	return 0;
}