Timer is Running

Three Number Even Sum
Submissions: 8   Accuracy:


  Difficulty: Easy   Marks: 2

Given an integer N, the task is to find the number of ways we can choose 3 numbers from {1, 2, 3, …, N} such that their sum is even.

Note: Answer can be very large, output answer modulo 109+7

Example 1:

Input: N = 3
Output: 1
Explanation: Select {1, 2, 3}

Example 2:

Input: N = 4
Output: 2
Explanation: Either select {1, 2, 3} or 
{1, 3, 4}

Your Task:  
You don't need to read input or print anything. Complete the function countWays() which takes N as input parameter and returns the integer value.

Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

1 ≤ N ≤ 105

** For More Input/Output Examples Use 'Expected Output' option **

Author: ShivamKD

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.