Educational Codeforces Round 13 B

Description

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的倍数而且平闰相同就是结果。

 1 #include<stdio.h>
 2 #include<string>
 3 #include<iostream>
 4 #include<math.h>
 5 #include<time.h>
 6 #include <stdlib.h>
 7 using namespace std;
 8 int Day_weak(int year,int month,int day)
 9 {
10     if(month==1||month==2)
11     {
12         month +=12;
13         --year;
14     }
15     int week = -1;
16     week=(day+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7+1;
17     return week; // 输出-1为错误
18 }
19 int main()
20 {
21     int a,b,c;
22     int i;
23     cin>>a;
24     for(i=a+1;i<=1000000;i++)
25     {
26        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))
27        {
28            break;
29        }
30     }
31     cout<<i<<endl;
32     return 0;
33 }

 

原文地址:https://www.cnblogs.com/yinghualuowu/p/5587027.html