Geeky Year Last Updated : 17 Jan, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Try it on GfG Practice It is given to you that on 1st January 2001 it was Monday. Let's call a year as Geeky if the 1st January of that year happens to be on Sunday. There will be given two years 'a' and 'b'. The task is to find the no. of Geeky years between those two years (including 'a' and 'b' as well) Examples: Input: a = 2001, b = 2013Output: 2 Input: a = 2020, b = 2024Output: 1 Approach: The idea is to store the days shift for each month and then calculate the answer. Follow the steps below to solve the problem: Initialize the variable count as 0.Iterate over the range [a, b] using the variable i and perform the following tasks:Initialize the variable y as i-1.Initialize the variable ans as (y + y / 4 - y / 100 + y / 400) % 7.If ans equals 6 then increase the value of count by 1.After performing the above steps, print the value of count as the answer. Below is the implementation of the above approach. C++ // C++ program for the above approach #include <bits/stdc++.h> using namespace std; // Function to count the total number // of years int Count(int a, int b) { // Days shifts for each month int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 }; // Store the answer int count = 0; // Traverse over the years for (int i = a; i <= b; i++) { int y = i - 1; int ans = (y + y / 4 - y / 100 + y / 400) % 7; if (ans == 6) { count++; } } return count; } // Driver Code int main() { int a = 2001; int b = 2013; int ans = Count(a, b); cout << ans; } // This code is contributed by Samim Hossain Mondal. Java // Java program for the above approach import java.io.*; import java.lang.*; import java.util.*; class GFG { // Function to count the total number // of years public static int Count(int a, int b) { // Days shifts for each month int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 }; // Store the answer int count = 0; // Traverse over the years for (int i = a; i <= b; i++) { int y = i - 1; int ans = (y + y / 4 - y / 100 + y / 400) % 7; if (ans == 6) { count++; } } return count; } // Driver Code public static void main(String[] args) { int a = 2001; int b = 2013; int ans = Count(a, b); System.out.println(ans); } } Python3 # Python 3 program for the above approach # Function to count the total number # of years def Count(a, b): # Days shifts for each month t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4] # Store the answer count = 0 # Traverse over the years for i in range(a, b + 1): y = i - 1 ans = (y + y // 4 - y // 100 + y // 400) % 7 if (ans == 6): count += 1 return count # Driver Code if __name__ == "__main__": a = 2001 b = 2013 ans = Count(a, b) print(ans) # This code is contributed by ukasp. C# // C# program for the above approach using System; class GFG { // Function to count the total number // of years public static int Count(int a, int b) { // Days shifts for each month int []t = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 }; // Store the answer int count = 0; // Traverse over the years for (int i = a; i <= b; i++) { int y = i - 1; int ans = (y + y / 4 - y / 100 + y / 400) % 7; if (ans == 6) { count++; } } return count; } // Driver Code public static void Main() { int a = 2001; int b = 2013; int ans = Count(a, b); Console.WriteLine(ans); } } // This code is contributed by Samim Hossain Mondal. JavaScript <script> // JavaScript code for the above approach // Function to count the total number // of years function Count(a, b) { // Days shifts for each month let t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]; // Store the answer let count = 0; // Traverse over the years for (let i = a; i <= b; i++) { let y = i - 1; let ans = (y + Math.floor(y / 4) - Math.floor(y / 100) + Math.floor(y / 400)) % 7; if (ans == 6) { count++; } } return count; } // Driver Code let a = 2001; let b = 2013; let ans = Count(a, b); document.write(ans); // This code is contributed by Potta Lokesh </script> Output2 Time Complexity: O(N)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Geeky Year V varunsharma024 Follow Improve Article Tags : Java Mathematical Competitive Programming Java Programs DSA +1 More Practice Tags : JavaMathematical Similar Reads Java Program to Get Year From Date Java is the most powerful programming language, by which we can perform many tasks and Java is an industry preferable language. So it is filled with a huge amount of features. Here we are going to discuss one of the best features of Java, which is how to get a year from date using Java. Methods: The 4 min read Java Program to Find if a Given Year is a Leap Year Leap Year contains 366 days, which comes once every four years. In this article, we will learn how to write the leap year program in Java. Facts about Leap YearEvery leap year corresponds to these facts : A century year is a year ending with 00. A century year is a leap year only if it is divisible 5 min read Check if a given Year is Leap Year You are given an Integer n. Return true if It is a Leap Year otherwise return false. A leap year is a year that contains an additional day, February 29th, making it 366 days long instead of the usual 365 days. Leap years are necessary to keep our calendar in alignment with the Earth's revolutions ar 4 min read YearMonth getYear() method in Java The getYear() method of YearMonth class in Java is used to get the value of the Year field from this YearMonth instance with which it is used. It returns the value of the year field as an integer from MIN_YEAR to MAX_YEAR. Syntax: public int getYear() Parameter: This method does not accepts any para 1 min read Find whether a day fall under the GEEK year The geeks living in the Geekland follow a particular type of calendar. The calendar is such that on a normal year it contains N days. Every Mth year on Geekland is known as the "GEEK" year. For example, if M = 5, then years 5, 10, 15, ... are "GEEK" years. A "GEEK" year contains K additional days th 12 min read Like