Given an integer **N**, the task is to divide the number into four parts such that the divided parts can be used to construct a rectangle but not a square. Find how many numbers of ways are there so that the number can be divided fulfilling the condition.

**Examples:**

Input:N = 8

Output:1

Input:N = 10

Output:2

**Approach:** As the number has to be divided such that rectangle is formed from the divided four parts, so **if the number is odd**, then the** number of ways will be zero**, as **perimeter of a rectangle is always even**

Now, if **n is even**, then only **(n – 2) / 4** number of ways are there to divide the number, for example,

if 8 has to be divided in four parts then there is only **(8 – 2) / 4 = 1** way, i.e., **[1, 1, 3, 3]**, no other way is there. It’s because you can only take **sides length < = n/2 – 1 ** to form a valid rectangle and from those ** n/2 – 1** rectangles count divide again by 2 to avoid double counting.

Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to return the ` `// required number of ways ` `int` `cntWays(` `int` `n) ` `{ ` ` ` `if` `(n % 2 == 1) { ` ` ` `return` `0; ` ` ` `} ` ` ` `else` `{ ` ` ` `return` `(n - 2) / 4; ` ` ` `} ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 18; ` ` ` ` ` `cout << cntWays(n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `GFG ` `{ ` ` ` ` ` `// Function to return the ` ` ` `// required number of ways ` ` ` `static` `int` `cntWays(` `int` `n) ` ` ` `{ ` ` ` `if` `(n % ` `2` `== ` `1` `) ` ` ` `{ ` ` ` `return` `0` `; ` ` ` `} ` ` ` `else` ` ` `{ ` ` ` `return` `(n - ` `2` `) / ` `4` `; ` ` ` `} ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main (String[] args) ` ` ` `{ ` ` ` `int` `n = ` `18` `; ` ` ` ` ` `System.out.println(cntWays(n)); ` ` ` ` ` `} ` `} ` ` ` `// This code is contributed by AnkitRai01 ` |

*chevron_right*

*filter_none*

## Python3

`# Python 3 implementation of the approach ` ` ` `# Function to return the ` `# required number of ways ` `def` `cntWays(n) : ` ` ` `if` `n ` `%` `2` `=` `=` `1` `: ` ` ` `return` `0` ` ` `else` `: ` ` ` `return` `(n ` `-` `2` `) ` `/` `/` `4` ` ` `# Driver code ` `n ` `=` `18` `print` `(cntWays(n)) ` ` ` `# This code is contributed by ` `# divyamohan123 ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` ` ` `// Function to return the ` ` ` `// required number of ways ` ` ` `static` `int` `cntWays(` `int` `n) ` ` ` `{ ` ` ` `if` `(n % 2 == 1) ` ` ` `{ ` ` ` `return` `0; ` ` ` `} ` ` ` `else` ` ` `{ ` ` ` `return` `(n - 2) / 4; ` ` ` `} ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main (String[] args) ` ` ` `{ ` ` ` `int` `n = 18; ` ` ` ` ` `Console.WriteLine(cntWays(n)); ` ` ` `} ` `} ` ` ` `// This code is contributed by 29AjayKumar ` |

*chevron_right*

*filter_none*

**Output:**

4

**Time Complexity:** O(1)

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:

- Find the number of ways to divide number into four parts such that a = c and b = d
- Check if any square (with one colored cell) can be divided into two equal parts
- Minimum Cuts can be made in the Chessboard such that it is not divided into 2 parts
- Check if an array of 1s and 2s can be divided into 2 parts with equal sum
- Split a number into 3 parts such that none of the parts is divisible by 3
- Divide N into K unique parts such that gcd of those parts is maximum
- Maximum area of a Rectangle that can be circumscribed about a given Rectangle of size LxW
- Number of K's such that the given array can be divided into two sets satisfying the given conditions
- Check if four segments form a rectangle
- Check if given four integers (or sides) make rectangle
- First N natural can be divided into two sets with given difference and co-prime sums
- Check if array can be divided into two sub-arrays such that their absolute difference is K
- Find the sums for which an array can be divided into sub-arrays of equal sum
- Check if N can be divided into K consecutive elements with a sum equal to N
- Check if a given array can be divided into pairs with even sum
- Check if a line at 45 degree can divide the plane into two equal weight parts
- Ratio of area of a rectangle with the rectangle inscribed in it
- Largest subset of rectangles such that no rectangle fit in any other rectangle
- Count number of ways to divide a number in 4 parts
- Partition a number into two divisible parts

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.