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.
Input: N = 8
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
- 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:
- Total number of days taken to complete the task if after certain days one person leaves
- Java Program to Calculate Power of a Number
- Find number of days between two given dates
- Calculate the number of set bits for every number from 0 to N
- Calculate MDAS Factorial of given number
- Date after adding given number of days to the given date
- Find minimum number of Log value needed to calculate Log upto N
- Program to Convert Octal Number to Binary Number
- Calculate Stirling numbers which represents the number of ways to arrange r objects around n different circles
- Program to check whether a number is Proth number or not
- Fast method to calculate inverse square root of a floating point number in IEEE 754 format
- C program to calculate the value of nPr
- Program to calculate value of nCr
- Write a program to calculate pow(x,n)
- Efficient program to calculate e^x
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.