CYER- Editorial

PROBLEM LINKS:

Practice

Contest

Author:

bigo_admin

Tester and Editorialist:

subhasis10

DIFFICULTY:

EASY

PREREQUISITES:

Knowledge on Leap Years

PROBLEM:

For a given year we have to find the next nearest year which has the exactly same calendar.

EXPLANATION:

We take the year X as input and check if it is leap year or not. Every non-leap year has 365 days and 365%7=1 so that is 52 weeks and 1 day extra. Every leap year has 366 days and 366%7=2 so that is 2 days extra.

So to find the next congruent year, we need to traverse all the years i coming after X and add the number of extra days they have. We will stop when the sum%7==0 that is the extra days form a week, so that it becomes same as X.

And if X is a leap year, we need to check if i is a leap year, if not then continue traversing.

TESTER’S SOLUTION:

Can be found here

//