Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 479491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:47:52+00:00 2026-05-13T00:47:52+00:00

The problem is to derive a formula for determining number of digits a given

  • 0

The problem is to derive a formula for determining number of digits a given decimal number could have in a given base.

For example: 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.

Well the formula I derived so far is like this : (log10(num) /log10(base)) + 1.

in C/C++ I used this formula to compute the above given results.

long long int size = ((double)log10(num) / (double)log10(base)) + 1.0;

But sadly the formula is not giving correct answer is some cases,like these :

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

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.

Edit : 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:47:52+00:00Added an answer on May 13, 2026 at 12:47 am

    There are fast floating operations in your compiler settings. You need precise floation operations. The thing is that log10(8)/log10(2) is always 3 in math. But may be your result is 2.99999, for expample. It is bad. You must add small additive, but not 0.5. It should be about .00001 or something like that.

    Almost true formula:

    int size = static_cast<int>((log10((double)num) / log10((double)base)) + 1.00000001);
    

    Really true solution

    You should check the result of your formula. Compexity is O(log log n) or O(log result)!

    int fast_power(int base, int s)
    {
        int res = 1;
        while (s) {
            if (s%2) {
                res*=base;
                s--;
            } else {
                s/=2;
                base*=base;
            }
        }
        return res;
    }
    
    int digits_size(int n, int base)
    {
        int s = int(log10(1.0*n)/log10(1.0*base)) + 1;
        return fast_power(base, s) > n ? s : s+1;
    }
    

    This check is better than Brute-force test with base multiplications.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 274k
  • Answers 274k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try the following var newMap = oldMap.ToDictionary(pair => pair.Key, pair=>(object)pair.Value); May 13, 2026 at 2:18 pm
  • Editorial Team
    Editorial Team added an answer You can use Google Earth for that. May 13, 2026 at 2:18 pm
  • Editorial Team
    Editorial Team added an answer Linq to SQL is no longer being actively developed -… May 13, 2026 at 2:18 pm

Related Questions

The following problem has been puzzling me for a couple of days (nb: this
Problem: How many of the first 100,000,000 hexagonal numbers are divisible by all the
I have a PHP web application built with CodeIgniter MVC framework. I wish to
In some C++ code, I use integers to store lots of changing data. To

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.