您的位置:首页 > 其它

Educational Codeforces Round 13 B

2016-06-15 12:18 357 查看
[b]Description[/b]

The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.

The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year.

Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100(https://en.wikipedia.org/wiki/Leap_year).

Input
The only line contains integer y (1000 ≤ y < 100'000) — the year of the calendar.

Output
Print the only integer y' — the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar.

Examples

input
2016


output
2044


input
2000


output
2028


input
50501


output
50507


Note
Today is Monday, the 13th of June, 2016.

这个我使用基姆拉尔森计算公式求相同日期如果星期数相同,就看做日历相同。。这里我是拿1月1,3月1,和12月1比较。都相同就是相同的。。

其实正确解法是计算每年相隔天数。。如果是7的倍数而且平闰相同就是结果。

#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
#include<time.h>
#include <stdlib.h>
using namespace std;
int Day_weak(int year,int month,int day)
{
if(month==1||month==2)
{
month +=12;
--year;
}
int week = -1;
week=(day+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7+1;
return week; // 输出-1为错误
}
int main()
{
int a,b,c;
int i;
cin>>a;
for(i=a+1;i<=1000000;i++)
{
if(Day_weak(a,1,1)==Day_weak(i,1,1)&&Day_weak(a,3,1)==Day_weak(i,3,1)&&Day_weak(a,12,1)==Day_weak(i,12,1))
{
break;
}
}
cout<<i<<endl;
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: