We call the complexity of an integer n as the least number of 1s required to build the integer n using only additions, multiplications and parentheses.
Let C ( n ) denote the complexity of the integer n . Find the value of C ( 2 0 1 6 ) .
Details and Assumptions
As an explicit example, the least number of 1s required to build the integer 6 is 5 because 6 = ( 1 + 1 ) × ( 1 + 1 + 1 ) and we cannot build the integer 6 with four 1's or less.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
My solution in python 3:
1 2 3 4 5 6 7 8 9 10 |
|
Output:
1 |
|
Nice solution.(+1)
But by pen and paper 2 0 1 6 = 2 5 . 3 2 . 7 = 2 5 . 3 2 . ( 2 × 3 + 1 ) . Hence C ( 2 0 1 6 ) = 2 2 .
EDIT: that was by luck.. here is why.
Log in to reply
Exactly what I did! +1
We actually need to prove the following claim to justify the method in your comment :
Claim: If, for positive integer a , a = i ∏ p i q i is the unique prime representation of a , then C ( a ) = i ∑ q i C ( p i ) and for any prime p , we have C ( p ) = 1 + C ( p − 1 ) with the obvious initial value C ( 1 ) = 1 .
Intuitively, this seems to be true and I also verified the above claim to be true for numerous values of a by checking the result given by it with the one given by the posted code, but I can't think of a proper formal proof to the above claim.
Log in to reply
"Guy asks if a(p) = a(p-1) + 1 for prime p. Martin Fuller found the least counterexample p = 353942783 in 2008"
This is actually a very complex problem (no pun intended).
For eg, why not C ( p ) = ( 1 + 1 ) + C ( p − 2 ) .
Or by considering your approach, C ( p ) = 1 + C ( p − 1 ) ,
what if p − 1 = x ⋅ q where q is a large prime again? It can be solved easily with computers but it's a hard job manually.
Log in to reply
@Arulx Z – Because....... this will explain better.
It's funny that you tried that approach, because I started that way too. Then I realized that the complexity of a slightly smaller number (e.g. 2015) might well be significantly less... So that's where I started coding.
You need to prove that 22 is the minimum.
Problem Loading...
Note Loading...
Set Loading...
Output: