CodeForces
来源:互联网 发布:女包包网淘宝网 编辑:程序博客网 时间:2024/05/20 07:36
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).
The only line contains integer y (1000 ≤ y < 100'000) — the year of the calendar.
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.
2016
2044
2000
2028
50501
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;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- 图片加载错位
- c++ 笔记
- 快速排序
- 设计模式番外篇
- C++学习笔记十二之函数重载
- CodeForces
- (sqlalchemy.exc.InvalidRequestError) Can't reconnect until invalid transaction is rolled back
- 荷兰国旗
- Volatile和Synchronized对可见性和原子性的支持
- linux学习总结 unit06进程管理
- 原型模式
- java自定义Exception
- Android零基础入门第14节:使用高速Genymotion,跨入火箭时代
- How Many Tables