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 7824035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:27:34+00:00 2026-06-02T08:27:34+00:00

I am attempting to write a function which takes a large number as input

  • 0

I am attempting to write a function which takes a large number as input (upwards of 800 digits long) and returns a simple formula of no complex math as a string.

By simple math, I mean just numbers with +,-,*,/,^ and () as needed.

'4^25+2^32' = giveMeMath(1125904201809920); // example

Any language would do. I can refactor it, just looking for some help with the logic.

Bonus. The shorter the output the better. Processing time is important. Also, mathematical accuracy is a must.

Update:
to clarify, all input values will be positive integers (no decimals)

  • 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-06-02T08:27:37+00:00Added an answer on June 2, 2026 at 8:27 am

    Here is my attempt in Python:

    def give_me_math(n): 
    
        if n % 2 == 1:
            n = n - 1  # we need to make every odd number even, and add back one later
            odd = 1
        else:
            odd = 0
        exps = []
    
        while n > 0:
            c = 0
            num = 0
            while num <= n/2:
                c += 1
                num = 2**c
    
            exps.append(c)    
            n = n - num
        return (exps, odd)
    

    Results:

    >>> give_me_math(100)
    ([6, 5, 2], 0)  #2**6 + 2**5 + 2**2 + 0 = 100
    
    >>> give_me_math(99)
    ([6, 5, 1], 1)  #2**6 + 2**5 + 2**1 + 1 = 99
    
    >>> give_me_math(103) 
    ([6, 5, 2, 1], 1) #2**6 + 2**5 + 2**2 + 2**1 + 1 = 103
    

    I believe the results are accurate, but I am not sure about your other criteria.

    Edit:

    Result: Calculates in about a second.

    >>> give_me_math(10**100 + 3435)
    ([332, 329, 326, 323, 320, 319, 317, 315, 314, 312, 309, 306, 304, 303, 300, 298, 295, 294, 289, 288, 286, 285, 284, 283, 282, 279, 278, 277, 275, 273, 272, 267, 265, 264, 261, 258, 257, 256, 255, 250, 247, 246, 242, 239, 238, 235, 234, 233, 227, 225, 224, 223, 222, 221, 220, 217, 216, 215, 211, 209, 207, 206, 203, 202, 201, 198, 191, 187, 186, 185, 181, 176, 172, 171, 169, 166, 165, 164, 163, 162, 159, 157, 155, 153, 151, 149, 148, 145, 142, 137, 136, 131, 127, 125, 123, 117, 115, 114, 113, 111, 107, 106, 105, 104, 100, 11, 10, 8, 6, 5, 3, 1], 1)
    

    800 digit works fast too:

    >>> give_me_math(10**800 + 3452)
    

    But the output is too long to post here, which is OPs concern of course.

    Time complexity here is 0(ln(n)), so it is pretty efficient.

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

Sidebar

Related Questions

I have the code below, I'm attempting to write a generic function which takes
I am attempting to write a function which will operate on a std::map of
I'm attempting to write a function which starts a thread for each contact and
So I am attempting to write a compare function in C which can take
I am attempting to write a function which tries to connect to Redis using
I'm attempting to write a function that recursively computes the resulting fibonacci number from
I am attempting to write a C# component which will expose events. The component
I am attempting to write a VB.net application which will allow users to create
I am attempting to write a LaTeX package which leverages the minted package's \inputminted
I'm attempting to write a Python function to send an email to a list

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.