Note that there are some explanatory texts on larger screens.

plurals
  1. POHow many digits in this base?
    primarykey
    data
    text
    <p>The problem is to derive a formula for determining number of digits a given decimal number could have in a given base.</p> <p>For example: <strong>The decimal number 100006 can be represented by 17,11,9,8,7,6,8 digits in bases 2,3,4,5,6,7,8 respectively.</strong></p> <p>Well the formula I derived so far is like this : (log10(num) /log10(base)) + 1.</p> <p>in C/C++ I used this formula to compute the above given results.</p> <p><code>long long int size = ((double)log10(num) / (double)log10(base)) + 1.0;</code></p> <p>But sadly the formula is not giving correct answer is some cases,like these :</p> <pre><code>Number 8 in base 2 : 1,0,0,0 Number of digits: 4 Formula returned: 3 Number 64 in base 2 : 1,0,0,0,0,0,0 Number of digits: 7 Formula returned: 6 Number 64 in base 4 : 1,0,0,0 Number of digits: 4 Formula returned: 3 Number 125 in base 5 : 1,0,0,0 Number of digits: 4 Formula returned: 3 Number 128 in base 2 : 1,0,0,0,0,0,0,0 Number of digits: 8 Formula returned: 7 Number 216 in base 6 : 1,0,0,0 Number of digits: 4 Formula returned: 3 Number 243 in base 3 : 1,0,0,0,0,0 Number of digits: 6 Formula returned: 5 Number 343 in base 7 : 1,0,0,0 Number of digits: 4 Formula returned: 3 </code></pre> <p>So the error is by 1 digit.I just want somebody to help me to correct the formula so that it work for every possible cases.</p> <p><strong>Edit :</strong> As per the input specification I have to deal with cases like 10000000000, i.e 10^10,I don't think log10() in either C/C++ can handle such cases ? So any other procedure/formula for this problem will be highly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload