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 }
复制代码

 

 

posted @   樱花落舞  阅读(261)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示