Cody

# Problem 44337. Sums of Distinct Powers

Solution 1351138

Submitted on 20 Nov 2017 by David Hill
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
base=4;nstart=2;nend=6;y_correct=62; assert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))

Exp = 1 Exp = 1 4 Exp = 1 4 16

2   Pass
base=5;nstart=1;nend=1000;y_correct=1193853250; assert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))

Exp = 1 Exp = 1 5 Exp = 1 5 25 Exp = 1 5 25 125 Exp = 1 5 25 125 625 Exp = 1 5 25 125 625 3125 Exp = 1 5 25 125 625 3125 15625 Exp = 1 5 25 125 625 3125 15625 78125 Exp = 1 5 25 125 625 3125 15625 78125 390625 Exp = 1 5 25 125 625 3125 15625 78125 390625 1953125

3   Pass
base=3;nstart=1;nend=1000;y_correct=14438162; assert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))

Exp = 1 Exp = 1 3 Exp = 1 3 9 Exp = 1 3 9 27 Exp = 1 3 9 27 81 Exp = 1 3 9 27 81 243 Exp = 1 3 9 27 81 243 729 Exp = 1 3 9 27 81 243 729 2187 Exp = 1 3 9 27 81 243 729 2187 6561 Exp = 1 3 9 27 81 243 729 2187 6561 19683

4   Pass
base=3;nstart=100;nend=1000;y_correct=14397354; assert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))

Exp = 1 Exp = 1 3 Exp = 1 3 9 Exp = 1 3 9 27 Exp = 1 3 9 27 81 Exp = 1 3 9 27 81 243 Exp = 1 3 9 27 81 243 729 Exp = 1 3 9 27 81 243 729 2187 Exp = 1 3 9 27 81 243 729 2187 6561 Exp = 1 3 9 27 81 243 729 2187 6561 19683

5   Pass
base=2;nstart=1;nend=2017;y_correct=2035153; assert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))

Exp = 1 Exp = 1 2 Exp = 1 2 4 Exp = 1 2 4 8 Exp = 1 2 4 8 16 Exp = 1 2 4 8 16 32 Exp = 1 2 4 8 16 32 64 Exp = 1 2 4 8 16 32 64 128 Exp = 1 2 4 8 16 32 64 128 256 Exp = 1 2 4 8 16 32 64 128 256 512 Exp = 1 2 4 8 16 32 64 128 256 512 1024

6   Pass
base=7;nstart=1234;nend=2345;y_correct=843569026324; assert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))

Exp = 1 Exp = 1 7 Exp = 1 7 49 Exp = 1 7 49 343 Exp = 1 7 49 343 2401 Exp = 1 7 49 343 2401 16807 Exp = 1 7 49 343 2401 16807 117649 Exp = 1 7 49 343 2401 16807 117649 823543 Exp = 1 7 49 343 2401 16807 117649 823543 5764801 Exp = 1 7 49 343 2401 16807 117649 823543 5764801 40353607 Exp = 1 7 49 343 2401 16807 117649 823543 5764801 40353607 282475249 Exp = 1.0e+09 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0008 0.0058 0.0404 0.2825 1.9773

7   Pass
base=7;nstart=1;nend=10;y_correct=1265; assert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))

Exp = 1 Exp = 1 7 Exp = 1 7 49 Exp = 1 7 49 343

8   Pass
nstart=1;nend=50; junk=arrayfun(@(base) sum_distinct_powers(base,nstart,nend),2:10); y_correct=[1275 7120 26365 75000 178591 374560 714465 1266280 2116675]; assert(isequal(junk,y_correct))

Exp = 1 Exp = 1 2 Exp = 1 2 4 Exp = 1 2 4 8 Exp = 1 2 4 8 16 Exp = 1 2 4 8 16 32 Exp = 1 Exp = 1 3 Exp = 1 3 9 Exp = 1 3 9 27 Exp = 1 3 9 27 81 Exp = 1 3 9 27 81 243 Exp = 1 Exp = 1 4 Exp = 1 4 16 Exp = 1 4 16 64 Exp = 1 4 16 64 256 Exp = 1 4 16 64 256 1024 Exp = 1 Exp = 1 5 Exp = 1 5 25 Exp = 1 5 25 125 Exp = 1 5 25 125 625 Exp = 1 5 25 125 625 3125 Exp = 1 Exp = 1 6 Exp = 1 6 36 Exp = 1 6 36 216 Exp = 1 6 36 216 1296 Exp = 1 6 36 216 1296 7776 Exp = 1 Exp = 1 7 Exp = 1 7 49 Exp = 1 7 49 343 Exp = 1 7 49 343 2401 Exp = 1 7 49 343 2401 16807 Exp = 1 Exp = 1 8 Exp = 1 8 64 Exp = 1 8 64 512 Exp = 1 8 64 512 4096 Exp = 1 8 64 512 4096 32768 Exp = 1 Exp = 1 9 Exp = 1 9 81 Exp = 1 9 81 729 Exp = 1 9 81 729 6561 Exp = 1 9 81 729 6561 59049 Exp = 1 Exp = 1 10 Exp = 1 10 100 Exp = 1 10 100 1000 Exp = 1 10 100 1000 10000 Exp = 1 10 100 1000 10000 100000