CodeForces - 678B B. The Same Calendar

B. The Same Calendar
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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
题意:找出下一个年份跟今年相同的
平年(365 % 7 == 1)闰年(366 % 7 == 2),所以满足条件的下个年份就是能被7整除且跟今年是相同的闰年或平年。

AC代码:

#include<cstdio>

int is_ren(int n){
	if(n%400 == 0 || (n%100 != 0 && n%4 == 0)) return 1;
	return 0;
}
int main(){
	int n, sum = 0, flag = 1;
	scanf("%d", &n);
	if(is_ren(n)){
		flag = 0;
	}
	for(int i = n + 1; i < n + 50; i++){
		if(is_ren(i)){
			sum = (sum + 366) % 7;
		}
		else{
			sum = (sum + 365) % 7;
		}
		if(sum == 0 && is_ren(i) == is_ren(n)){
			printf("%d", i);
			break;
		}
	}
	return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kunsir_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值