# Find the number of ways to divide number into four parts such that a = c and b = d

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:

- Count number of ways to divide a number in 4 parts
- Divide a number into two parts
- Divide a big number into two parts that differ by k
- Divide a number into two parts such that sum of digits is maximum
- Divide number into two parts divisible by given numbers
- Number of ways N can be divided into four parts to construct a rectangle
- Count number of ways to divide an array into two halves with same sum
- Number of ways to divide string in sub-strings such to make them in lexicographically increasing sequence
- Find count of digits in a number that divide the number
- Divide N into K unique parts such that gcd of those parts is maximum
- Split a number into 3 parts such that none of the parts is divisible by 3
- Find the number of ways to reach Kth step in stair case
- Sum and Product of digits in a number that divide the number
- Number of ways to split a binary number such that every part is divisible by 2
- Divide an isosceles triangle in two parts with ratio of areas as n:m

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.