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.
Input: N = 1
Input: N = 2
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 nth 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:
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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.