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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:48:50+00:00 2026-06-02T07:48:50+00:00

How can you compute a shortest addition chain (sac) for an arbitrary n <=

  • 0

How can you compute a shortest addition chain (sac) for an arbitrary n <= 600 within one second?

Notes

This is the programming competition on codility for this month.

Addition chains are numerically very important, since they are the most economical way to compute x^n (by consecutive multiplications).

Knuth’s Art of Computer Programming, Volume 2, Seminumerical Algorithms has a nice introduction to addition chains and some interesting properties, but I didn’t find anything that enabled me to fulfill the strict performance requirements.

What I’ve tried (spoiler alert)

Firstly, I constructed a (highly branching) tree (with the start 1-> 2 -> ( 3 -> …, 4 -> …)) such that for each node n, the path from the root to n is a sac for n. But for values >400, the runtime is about the same as for making a coffee.

Then I used that program to find some useful properties for reducing the search space. With that, I’m able to build all solutions up to 600 while making a coffee. But for n, I need to compute all solutions up to n. Unfortunately, codility measures the class initialization’s runtime, too…

Since the problem is probably NP-hard, I ended up hard-coding a lookup table. But since codility asked to construct the sac, I don’t know if they had a lookup table in mind, so I feel dirty and like a cheater. Hence this question.

Update

If you think a hard-coded, full lookup table is the way to go, can you give an argument why you think a full computation/partly computed solutions/heuristics won’t work?

  • 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-02T07:48:51+00:00Added an answer on June 2, 2026 at 7:48 am

    I have just got my Golden Certificate for this problem. I will not provide a full solution because the problem is still available on the site.I will instead give you some hints:

    1. You might consider doing a deep-first search.
    2. There exists a minimal star-chain for each n < 12509
    3. You need to know how prune your search space.
    4. You need a good lower bound for the length of the chain you are looking for.
    5. Remember that you need just one solution, not all.

    Good luck.

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

Sidebar

Related Questions

I can't find any PHP script to compute Krippendorff's Alpha . I need this
I can't seem to find an algorithm to compute the number of arrays within
Let's say I have a function that can compute one output from one input,
I can successfully compute the 200 day moving average for one ticker using a
Is there a build in library in .NET that can compute secure one-way hash
Given any two sequences/vectors of M real numbers, I can easily compute their closeness
What does TEMP0_FILES below compute to? SOURCE_FILES can equal to multiple source files. Please
I am looking for a simple java class that can compute tf-idf calculation. I
Using pandas I can compute simple moving average SMA using pandas.stats.moments.rolling_mean exponential moving average
How can I compute the intersection between two text files in terms of raw

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.