Cody

Problem 44337. Sums of Distinct Powers

You will be given three numbers: base, nstart, and nend. Write a MATLAB script that will compute the sum of a sequence of both the distinct powers of base as well as sums of distinct powers of base. Your sequence should start with the 'nstart'th term and end with the 'nend'th term. For example:

  • base=4
  • nstart=2
  • nend=6

The first several sums of the distinct powers of 4 are:

  • 1 (4^0)
  • 4 (4^1)
  • 5 (4^1 + 4^0)
  • 16 (4^2)
  • 17 (4^2 + 4^0)
  • 20 (4^2 + 4^1)
  • 21 (4^2 + 4^1 + 4^0)
  • 64 (4^3)
  • 65 (4^3 + 4^0)

Since nstart=2 and nend=6 in this example, you take the second through the sixth terms of this sequence. The correct output would be 4+5+16+17+20, or 62. Notice that the number 8 does not occur in this pattern. While 8 is a multiple of 4, 8=4^1+4^1. Because there are two 4^1 terms in the sum, 8 does not qualify as a sum of distinct powers of 4. You can assume that all three will be integers, base>1, and that nstart<nend. Good luck!

Solution Stats

45.85% Correct | 54.15% Incorrect
Last Solution submitted on Nov 19, 2019

Problem Comments

Solution Comments

Problem Recent Solvers123

Suggested Problems

More from this Author80