# Find the count of natural Hexadecimal numbers of size N

Given an integer **N**, the task is to find the count of natural Hexadecimal numbers with **N** digits.

**Examples:**

Input:N = 1

Output:15

Input:N = 2

Output:240

**Approach:** It can be observed that for the values of **N = 1, 2, 3, …**, a series will be formed as **15, 240, 3840, 61440, 983040, 15728640, …** which is a GP series whose common ratio is **16** and **a = 15**.

Hence the **n ^{th}** term will be

**15 * pow(16, n – 1)**.

So, the count of **n-digit** natural hexadecimal numbers will be **15 * pow(16, n – 1)**.

Below is the implementation of the above approach:

## C++

`// C++ implementation of the above approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to return the count of n-digit ` `// natural hexadecimal numbers ` `int` `count(` `int` `n) ` `{ ` ` ` `return` `15 * ` `pow` `(16, n - 1); ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 2; ` ` ` `cout << count(n); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `GFG ` `{ ` ` ` `// Function to return the count of n-digit ` `// natural hexadecimal numbers ` `static` `int` `count(` `int` `n) ` `{ ` ` ` `return` `(` `int` `) (` `15` `* Math.pow(` `16` `, n - ` `1` `)); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String args[]) ` `{ ` ` ` `int` `n = ` `2` `; ` ` ` `System.out.println(count(n)); ` `} ` `} ` ` ` `// This code is contributed by 29AjayKumar ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the above approach ` ` ` `# Function to return the count of n-digit ` `# natural hexadecimal numbers ` `def` `count(n) : ` ` ` ` ` `return` `15` `*` `pow` `(` `16` `, n ` `-` `1` `); ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `n ` `=` `2` `; ` ` ` `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 n-digit ` ` ` `// natural hexadecimal numbers ` ` ` `static` `int` `count(` `int` `n) ` ` ` `{ ` ` ` `return` `(` `int` `) (15 * Math.Pow(16, n - 1)); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main(String []args) ` ` ` `{ ` ` ` `int` `n = 2; ` ` ` `Console.WriteLine(count(n)); ` ` ` `} ` `} ` ` ` `// This code is contributed by 29AjayKumar ` |

*chevron_right*

*filter_none*

**Output:**

240

**Time Complexity:** O(1)

## Recommended Posts:

- Count natural numbers whose factorials are divisible by x but not y
- Count natural numbers whose all permutation are greater than that number
- Count pairs of natural numbers with GCD equal to given number
- Find m-th summation of first n natural numbers.
- Program to find sum of first n natural numbers
- Find if given number is sum of first n natural numbers
- Find sum of N-th group of Natural Numbers
- Find the average of first N natural numbers
- Find the good permutation of first N natural numbers
- Find maximum N such that the sum of square of first N natural numbers is not more than X
- Find the permutation of first N natural numbers such that sum of i % P
_{i}is maximum possible - Find permutation of first N natural numbers that satisfies the given condition
- Find the number of sub arrays in the permutation of first N natural numbers such that their median is M
- Find ways an Integer can be expressed as sum of n-th power of unique natural numbers
- Check the divisibility of Hexadecimal numbers

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.