Codeforces 678 B. The Same Calendar

#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

bool isLeap(LL n)
{
    return (n % 400==0 or (n%4==0 and n%100!=0));
}

int main()
{
    ios_base::sync_with_stdio(false);

    LL n;
    while(cin >> n)
    {
        LL day=0;

        for(LL i=n; ; i++)
        {
            if(isLeap(i)) day+=366;
            else day+=365;

            if(day%7==0 and isLeap(n) == isLeap(i+1) and n!=i+1)
            {
                cout << i+1 << "\n";
                break;
            }
        }
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number