Given a number **N**. Find the number of ways to divide a number into four parts(a, b, c, d) such that a = c and b = d and a not equal to b.

**Examples:**

Input :N = 6

Output :1

Expalantion :four parts are {1, 2, 1, 2}

Input :N = 20

Output :4

Expalantion :possible ways are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}.

**Approach :**

If the given **N** is odd the answer is 0, because the sum of four parts will not be even number.

If n is divisible by 4 then answer will be n/4 -1(here a equals to b can be possible so subtract that possibility) otherwise n/4.

Below is the implementation of the above approach :

## C++

`// C++ implementation for above approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find the number of ways to divide ` `// N into four parts such that a = c and b = d ` `int` `possibleways(` `int` `n) ` `{ ` ` ` `if` `(n % 2 == 1) ` ` ` `return` `0; ` ` ` `else` `if` `(n % 4 == 0) ` ` ` `return` `n / 4 - 1; ` ` ` `else` ` ` `return` `n / 4; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 20; ` ` ` `cout << possibleways(n); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation for above approach ` `class` `GFG ` `{ ` ` ` `// Function to find the number of ways to divide ` `// N into four parts such that a = c and b = d ` `static` `int` `possibleways(` `int` `n) ` `{ ` ` ` `if` `(n % ` `2` `== ` `1` `) ` ` ` `return` `0` `; ` ` ` `else` `if` `(n % ` `4` `== ` `0` `) ` ` ` `return` `n / ` `4` `- ` `1` `; ` ` ` `else` ` ` `return` `n / ` `4` `; ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `int` `n = ` `20` `; ` ` ` `System.out.println(possibleways(n)); ` `} ` `} ` ` ` `// This code contributed by Rajput-Ji ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation for above approach ` ` ` `# Function to find the number of ways ` `# to divide N into four parts ` `# such that a = c and b = d ` `def` `possibleways(n): ` ` ` ` ` `if` `(n ` `%` `2` `=` `=` `1` `): ` ` ` `return` `0` `; ` ` ` `elif` `(n ` `%` `4` `=` `=` `0` `): ` ` ` `return` `n ` `/` `/` `4` `-` `1` `; ` ` ` `else` `: ` ` ` `return` `n ` `/` `/` `4` `; ` ` ` `# Driver code ` `n ` `=` `20` `; ` `print` `(possibleways(n)); ` ` ` `# This code is contributed by mits ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation for above approach ` `class` `GFG ` `{ ` ` ` `// Function to find the number of ways to divide ` `// N into four parts such that a = c and b = d ` `static` `int` `possibleways(` `int` `n) ` `{ ` ` ` `if` `(n % 2 == 1) ` ` ` `return` `0; ` ` ` `else` `if` `(n % 4 == 0) ` ` ` `return` `n / 4 - 1; ` ` ` `else` ` ` `return` `n / 4; ` `} ` ` ` `// Driver code ` `static` `void` `Main() ` `{ ` ` ` `int` `n = 20; ` ` ` `System.Console.WriteLine(possibleways(n)); ` `} ` `} ` ` ` `// This code is contributed by mits ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation for above approach ` ` ` `// Function to find the number of ways to divide ` `// N into four parts such that a = c and b = d ` `function` `possibleways(` `$n` `) ` `{ ` ` ` `if` `(` `$n` `% 2 == 1) ` ` ` `return` `0; ` ` ` `else` `if` `(` `$n` `% 4 == 0) ` ` ` `return` `$n` `/ 4 - 1; ` ` ` `else` ` ` `return` `$n` `/ 4; ` `} ` ` ` `// Driver code ` `$n` `= 20; ` `echo` `possibleways(` `$n` `); ` ` ` `// This code is contributed by ajit ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

4

## Recommended Posts:

- Divide N into K unique parts such that gcd of those parts is maximum
- Number of ways N can be divided into four parts to construct a rectangle
- Split a number into 3 parts such that none of the parts is divisible by 3
- Divide a number into two parts such that sum of digits is maximum
- Count ways to divide C in two parts and add to A and B to make A strictly greater than B
- Count number of ways to divide a number in 4 parts
- Split a string in equal parts such that all parts are palindromes
- Divide number into two parts divisible by given numbers
- Divide a big number into two parts that differ by k
- Divide a number into two parts
- Minimum cuts required to divide the Circle into equal parts
- Divide N into K parts in the form (X, 2X, ... , KX) for some value of X
- Split the number into N parts such that difference between the smallest and the largest part is minimum
- Partition N into M parts such that difference between Max and Min part is smallest
- Divide a sorted array in K parts with sum of difference of max and min minimized in each part
- Count number of ways to divide an array into two halves with same sum
- Minimum Cuts can be made in the Chessboard such that it is not divided into 2 parts
- Split the string into minimum parts such that each part is in the another string
- Divide an isosceles triangle in two parts with ratio of areas as n:m
- Number of ways to divide string in sub-strings such to make them in lexicographically increasing sequence

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.