We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

will it be : 15 * 16^(n-4) * (n-1)P3 + 2 *16^(n-3) * (n-1)P2

where (n-1)P3 is like nPr.

first 15: let's say 0, 1 or A is not the most significant digit. so there will be 15 posibilities (except 0) for that digit.

16^(n-4): now within remaining (n-1) digits we will have to fix 0, 1 and A somewhere. which will allow n-4 digits to be selected freely from 16 digits.

(n-1)P3 : we can select any 3 places out of (n-1) digits that can have 0,1 and A. here order of 0,1 and A is important so used permutation.

+ other half of equation:-

first 2: let's say any one of 0,1 and A is first digit (most significant). But first digit can't be 0. So we have two choices for first digit.

16^(n-3) : first digit is fix and other two digits 0 and 1/A need to be fixed. so remaining (n-3) digits can be selected from 16 digits.

(n-1)P2 : first digit (1 or A) is fixed and other 2 digits 0 and (1 or A) need to be placed within (n-1) places. So we can select any 2 places from (n-1) and order is important. so took permutation.

Are my assumptions correct? Am I missing anything?

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website

## Project Euler #162: Hexadecimal numbers

You are viewing a single comment's thread. Return to all comments →

will it be :

15 * 16^(n-4) * (n-1)P3 + 2 *16^(n-3) * (n-1)P2where (n-1)P3 is like nPr.

first

15: let's say 0, 1 or A is not the most significant digit. so there will be 15 posibilities (except 0) for that digit.16^(n-4): now within remaining (n-1) digits we will have to fix 0, 1 and A somewhere. which will allow n-4 digits to be selected freely from 16 digits.(n-1)P3: we can select any 3 places out of (n-1) digits that can have 0,1 and A. here order of 0,1 and A is important so used permutation.+ other half of equation:-first

2: let's say any one of 0,1 and A is first digit (most significant). But first digit can't be 0. So we havetwochoices for first digit.16^(n-3): first digit is fix and other two digits 0 and 1/A need to be fixed. so remaining (n-3) digits can be selected from 16 digits.(n-1)P2: first digit (1 or A) is fixed and other 2 digits 0 and (1 or A) need to be placed within (n-1) places. So we can select any 2 places from (n-1) and order is important. so took permutation.Are my assumptions correct? Am I missing anything?