Given an integer **N**, the task is to find the number of odd days in the years from **1** to **N**.

**Odd Days:** Number of odd days refer to those days that are left in a certain year(s) when it’s days gets converted into weeks. Say, an ordinary year has 365 days, that is 52 weeks and one odd day. This means, out of the 365 days in an ordinary year, 364 days will get converted into 52 weeks and one day will remain. This one day is referred to as 1 odd day.

- Simply the modulus total number of days by 7(days in a week) gives us the number of odd days.
- It’s value lies between 0 to 6 only. [0, 6]
- Leap Year: Every year divisible either by 400 or by 4 but not 100
- Ordinary Year: Years Except Leap Years
- Every Ordinary Year has 1 odd day.
- Every Leap Year has 2 odd days.

**Examples:**

Input:N = 8

Output:3

Out of the 8 years, 4 and 8 are the only leap years.

(6 x 1) + (2 x 2) = 10 i.e. 1 week and 3 days

Input:N = 400

Output:0

**Approach:**

- Count number of ordinary years and number of leap years out of given N years.
- Calculate the overall number of days.
- Print the modulo(7) of the total number of days.

Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `// Function to return the count of odd days ` `int` `oddDays(` `int` `N) ` `{ ` ` ` ` ` `// Count of years divisible ` ` ` `// by 100 and 400 ` ` ` `int` `hund1 = N / 100; ` ` ` `int` `hund4 = N / 400; ` ` ` ` ` `// Every 4th year is a leap year ` ` ` `int` `leap = N >> 2; ` ` ` `int` `ord = N - leap; ` ` ` ` ` `// Every 100th year is divisible by 4 ` ` ` `// but is not a leap year ` ` ` `if` `(hund1) { ` ` ` `ord += hund1; ` ` ` `leap -= hund1; ` ` ` `} ` ` ` ` ` `// Every 400th year is divisible by 100 ` ` ` `// but is a leap year ` ` ` `if` `(hund4) { ` ` ` `ord -= hund4; ` ` ` `leap += hund4; ` ` ` `} ` ` ` ` ` `// Total number of extra days ` ` ` `int` `days = ord + leap * 2; ` ` ` ` ` `// modulo(7) for final answer ` ` ` `int` `odd = days % 7; ` ` ` ` ` `return` `odd; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` ` ` `// Number of days ` ` ` `int` `N = 100; ` ` ` `cout << oddDays(N); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `GFG { ` ` ` ` ` `// Function to return the count of odd days ` ` ` `static` `int` `oddDays(` `int` `N) ` ` ` `{ ` ` ` `// Count of years divisible ` ` ` `// by 100 and 400 ` ` ` `int` `hund1 = N / ` `100` `; ` ` ` `int` `hund4 = N / ` `400` `; ` ` ` ` ` `// Every 4th year is a leap year ` ` ` `int` `leap = N >> ` `2` `; ` ` ` `int` `ord = N - leap; ` ` ` ` ` `// Every 100th year is divisible by 4 ` ` ` `// but is not a leap year ` ` ` `if` `(hund1 > ` `0` `) { ` ` ` `ord += hund1; ` ` ` `leap -= hund1; ` ` ` `} ` ` ` ` ` `// Every 400th year is divisible by 100 ` ` ` `// but is a leap year ` ` ` `if` `(hund4 > ` `0` `) { ` ` ` `ord -= hund4; ` ` ` `leap += hund4; ` ` ` `} ` ` ` ` ` `// Total number of extra days ` ` ` `int` `days = ord + leap * ` `2` `; ` ` ` ` ` `// modulo(7) for final answer ` ` ` `int` `odd = days % ` `7` `; ` ` ` ` ` `return` `odd; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String args[]) ` ` ` `{ ` ` ` ` ` `// Number of days ` ` ` `int` `N = ` `100` `; ` ` ` `System.out.print(oddDays(N)); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function to return the count of odd days ` `def` `oddDays(N): ` ` ` ` ` `# Count of years divisible ` ` ` `# by 100 and 400 ` ` ` `hund1 ` `=` `N ` `/` `/` `100` ` ` `hund4 ` `=` `N ` `/` `/` `400` ` ` ` ` `# Every 4th year is a leap year ` ` ` `leap ` `=` `N >> ` `2` ` ` `ordd ` `=` `N ` `-` `leap ` ` ` ` ` `# Every 100th year is divisible by 4 ` ` ` `# but is not a leap year ` ` ` `if` `(hund1): ` ` ` `ordd ` `+` `=` `hund1 ` ` ` `leap ` `-` `=` `hund1 ` ` ` ` ` `# Every 400th year is divisible by 100 ` ` ` `# but is a leap year ` ` ` `if` `(hund4): ` ` ` `ordd ` `-` `=` `hund4 ` ` ` `leap ` `+` `=` `hund4 ` ` ` ` ` `# Total number of extra days ` ` ` `days ` `=` `ordd ` `+` `leap ` `*` `2` ` ` ` ` `# modulo(7) for final answer ` ` ` `odd ` `=` `days ` `%` `7` ` ` ` ` `return` `odd ` ` ` `# Driver code ` ` ` `# Number of days ` `N ` `=` `100` `print` `(oddDays(N)) ` ` ` `# This code is contributed ` `# by mohit kumar ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` ` ` `// Function to return the count of odd days ` ` ` `static` `int` `oddDays(` `int` `N) ` ` ` `{ ` ` ` `// Count of years divisible ` ` ` `// by 100 and 400 ` ` ` `int` `hund1 = N / 100; ` ` ` `int` `hund4 = N / 400; ` ` ` ` ` `// Every 4th year is a leap year ` ` ` `int` `leap = N >> 2; ` ` ` `int` `ord = N - leap; ` ` ` ` ` `// Every 100th year is divisible by 4 ` ` ` `// but is not a leap year ` ` ` `if` `(hund1 > 0) ` ` ` `{ ` ` ` `ord += hund1; ` ` ` `leap -= hund1; ` ` ` `} ` ` ` ` ` `// Every 400th year is divisible by 100 ` ` ` `// but is a leap year ` ` ` `if` `(hund4 > 0) ` ` ` `{ ` ` ` `ord -= hund4; ` ` ` `leap += hund4; ` ` ` `} ` ` ` ` ` `// Total number of extra days ` ` ` `int` `days = ord + leap * 2; ` ` ` ` ` `// modulo(7) for final answer ` ` ` `int` `odd = days % 7; ` ` ` ` ` `return` `odd; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `static` `void` `Main() ` ` ` `{ ` ` ` ` ` `// Number of days ` ` ` `int` `N = 100; ` ` ` `Console.WriteLine(oddDays(N)); ` ` ` `} ` `} ` ` ` `// This code is contributed by mits ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of the approach ` ` ` `// Function to return the count of odd days ` `function` `oddDays(` `$N` `) ` `{ ` ` ` ` ` `// Count of years divisible ` ` ` `// by 100 and 400 ` ` ` `$hund1` `= ` `floor` `(` `$N` `/ 100); ` ` ` `$hund4` `= ` `floor` `(` `$N` `/ 400); ` ` ` ` ` `// Every 4th year is a leap year ` ` ` `$leap` `= ` `$N` `>> 2; ` ` ` `$ord` `= ` `$N` `- ` `$leap` `; ` ` ` ` ` `// Every 100th year is divisible by 4 ` ` ` `// but is not a leap year ` ` ` `if` `(` `$hund1` `) ` ` ` `{ ` ` ` `$ord` `+= ` `$hund1` `; ` ` ` `$leap` `-= ` `$hund1` `; ` ` ` `} ` ` ` ` ` `// Every 400th year is divisible by 100 ` ` ` `// but is a leap year ` ` ` `if` `(` `$hund4` `) ` ` ` `{ ` ` ` `$ord` `-= ` `$hund4` `; ` ` ` `$leap` `+= ` `$hund4` `; ` ` ` `} ` ` ` ` ` `// Total number of extra days ` ` ` `$days` `= ` `$ord` `+ ` `$leap` `* 2; ` ` ` ` ` `// modulo(7) for final answer ` ` ` `$odd` `= ` `$days` `% 7; ` ` ` ` ` `return` `$odd` `; ` `} ` ` ` `// Driver code ` ` ` `// Number of days ` `$N` `= 100; ` ` ` `echo` `oddDays(` `$N` `); ` ` ` `// This code is contributed by Ryuga ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

5

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Total number of days taken to complete the task if after certain days one person leaves
- Date after adding given number of days to the given date
- C program to print number of days in a month
- Find number of days between two given dates
- Find the day of the week after K days from the given day
- Find temperature of missing days using given sum and average
- Finding number of days between two dates using StringStream
- Maximize number of days for which P chocolates can be distributed consecutively to N people
- Average of odd numbers till a given odd number
- Count of days remaining for the next day with higher temperature
- Print odd positioned nodes of odd levels in level order of the given binary tree
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Program to calculate area and perimeter of a rhombus whose diagonals are given
- Program to calculate angle on circumference subtended by the chord when the central angle subtended by the chord is given
- Program to calculate area of a rhombus whose one side and diagonal are given
- Program to calculate Resistance using given color code in circuits
- Split the array into odd number of segments of odd lengths
- Check if a number has an odd count of odd divisors and even count of even divisors
- Java Program to Calculate Power of a Number
- Write a program to calculate pow(x,n)

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.