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.
- Count non decreasing subarrays of size N from N Natural numbers
- Check the divisibility of Hexadecimal numbers
- Largest Even and Odd N-digit numbers in Hexadecimal Number System
- Largest and Smallest N-digit Hexadecimal Numbers
- How to add two Hexadecimal numbers
- Convert a binary number to hexadecimal number
- Program for decimal to hexadecimal conversion
- Program to Convert Hexadecimal Number to Binary
- Reverse bytes of a Hexadecimal Number
- Check if a HexaDecimal number is Even or Odd
- Check if a string represents a hexadecimal number or not
- Program to Convert Octal to Hexadecimal
- Fill the missing numbers in the array of N natural numbers such that arr[i] not equal to i
- 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
- Count set bits in the Kth number after segregating even and odd from N natural numbers
- Count of natural numbers in range [L, R] which are relatively prime with N
- Count of pairs with sum N from first N natural numbers
- Count array elements that can be maximized by adding any permutation of first N natural 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 firstname.lastname@example.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.