Given an integer **N**, the task is to find the count of coloured **0s** in an **N-level** hexagon when the **0s** are coloured in the following way:

**Examples:**

Input:N = 2

Output:5

Input:N = 3

Output:12

**Approach:** For the values of **N = 1, 2, 3, …** it can be observed that a series will be formed as **1, 5, 12, 22, 35, …**. It’s a difference series where differences are in AP as **4, 7, 10, 13, …**.

Therefore the **N ^{th}** term of will be 1 + {4 + 7 + 10 +13 +…..(n – 1) terms}

= 1 + (n – 1) * (2 * 4 + (n – 1 – 1) * 3) / 2

= 1 + (n – 1) * (8 + (n – 2) * 3) / 2

= 1 + (n – 1) * (8 + 3n – 6) / 2

= 1 + (n – 1) * (3n + 2) / 2

**= n * (3 * n – 1) / 2**

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 count of ` `// coloured 0s in an n-level hexagon ` `int` `count(` `int` `n) ` `{ ` ` ` `return` `n * (3 * n - 1) / 2; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 3; ` ` ` ` ` `cout << count(n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `GFG ` `{ ` ` ` `// Function to return the count of ` `// coloured 0s in an n-level hexagon ` `static` `int` `count(` `int` `n) ` `{ ` ` ` `return` `n * (` `3` `* n - ` `1` `) / ` `2` `; ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `int` `n = ` `3` `; ` ` ` ` ` `System.out.println(count(n)); ` `} ` `} ` ` ` `// This code is contributed by Code_Mech ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function to return the count of ` `# coloured 0s in an n-level hexagon ` `def` `count(n) : ` ` ` ` ` `return` `n ` `*` `(` `3` `*` `n ` `-` `1` `) ` `/` `/` `2` `; ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `n ` `=` `3` `; ` ` ` ` ` `print` `(count(n)); ` ` ` `# This code is contributed by AnkitRai01 ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to return the count of ` `// coloured 0s in an n-level hexagon ` `static` `int` `count(` `int` `n) ` `{ ` ` ` `return` `n * (3 * n - 1) / 2; ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main(String[] args) ` `{ ` ` ` `int` `n = 3; ` ` ` ` ` `Console.WriteLine(count(n)); ` `} ` `} ` ` ` `// This code is contributed by 29AjayKumar ` |

*chevron_right*

*filter_none*

**Output:**

12

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:

- Area of hexagon with given diagonal length
- Area of the Largest Triangle inscribed in a Hexagon
- Area of a circle inscribed in a regular hexagon
- Area of a square inscribed in a circle which is inscribed in a hexagon
- Find length of Diagonal of Hexagon
- Largest Square that can be inscribed within a hexagon
- Diagonal of a Regular Hexagon
- Largest hexagon that can be inscribed within a square
- Largest hexagon that can be inscribed within an equilateral triangle
- Largest square that can be inscribed within a hexagon which is inscribed within an equilateral triangle
- Biggest Reuleaux Triangle inscribed within a square which is inscribed within a hexagon
- Count of 0s in an N-level hexagon
- Count of Equilateral Triangles of unit length possible from a given Hexagon
- Number of factors of very large number N modulo M where M is any prime number
- Find minimum number to be divided to make a number a perfect square
- How to check if a given number is Fibonacci number?
- Find the smallest number whose digits multiply to a given number n
- Find n'th number in a number system with only 3 and 4
- Build Lowest Number by Removing n digits from a given number
- Count number of ways to divide a number in 4 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.