With Greater Powers

4 , 2 + 2 , 2 + 1 + 1 , 1 + 2 + 1 , 1 + 1 + 2 , 1 + 1 + 1 + 1 4, 2+2, 2+1+1, 1+2+1, 1+1+2, 1+1+1+1

Let f ( n ) f(n) be the number of ways in which one can express n n as the sum of powers of 2 2 , where each permutation is distinct . For example, f ( 4 ) = 6 f(4) = 6 because 4 4 can be written in the 6 ways listed above.

Find the smallest n n greater than 2013 2013 for which f ( n ) f(n) is odd.


The answer is 2047.

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.

2 solutions

Patrick Corn
Jun 23, 2015

As in Agnishom's solution, we have the recurrence f ( n ) = k = 0 f ( n 2 k ) f(n) = \sum_{k=0}^{\infty} f(n-2^k) , where f ( 0 ) = 1 f(0) = 1 and f ( m ) = 0 f(m) = 0 for m < 0 m < 0 .

(To see this, we classify the partitions of n n into powers of 2 2 by the first term; there are f ( n 1 ) f(n-1) partitions starting with a 1 1 , f ( n 2 ) f(n-2) starting with a 2 2 , and so on.)

We'd like to show that f ( n ) f(n) is odd if and only if n n is one less than a power of 2 2 . We proceed by induction.

Clearly the statement is true for n = 0 , 1 n = 0,1 . Now suppose n 1 n \ge 1 and use the recurrence to see that the parity of f ( n ) f(n) is determined by the number of k k such that f ( n 2 k ) f(n-2^k) is odd. By the inductive hypothesis, this is the number of k k such that n 2 k = 2 j 1 n- 2^k = 2^j-1 for some j j , i.e. the number of ways to write n = 2 k + 2 j 1 n = 2^k + 2^j -1 . Since we can interchange k k and j j , this number is even unless there is a representation with j = k j= k , in which case it is odd.

So f ( n ) f(n) is odd if and only if n = 2 k + 2 k 1 n = 2^k + 2^k - 1 for some k k , i.e. if and only if n n is one less than a power of 2 2 . Hence we are done by induction.

The answer to the problem is 2 11 1 = 2047 2^{11} - 1 = \fbox{2047} .

Great solution. Could you add a line to explain how the recurrence relation is obtained (so that your solution is self-contained)? Thanks!

Calvin Lin Staff - 5 years, 11 months ago

Log in to reply

????????? Any simpler method Relevant and easy with regards to jee

Gauri shankar Mishra - 5 years, 4 months ago

That is an excellent solution. Thank you!

Agnishom Chattopadhyay - 5 years, 11 months ago

This is a beautiful solution.

Igmut Schnoll - 5 years, 11 months ago

First, notice that for every n n , the first summand could be either 1 1 or, 2 2 , or 4 4 ... or 2 j 2^j .

So, this gives us the recurrence relation:

f ( n ) = f ( n 1 ) + f ( n 2 ) + f ( n 4 ) + f(n) = f(n-1) + f(n-2) + f(n-4) + \cdots

Using this recurrence, we can build up the following table containing the values of n n modulo 2 2 .

1
2
3
4
5
6
7
8
f = [1] #because f(0) = 1
for i in xrange(1,10001):
     j = 0
     s = 0
     while 2**j <= i:
             s += f[i-2**j]
             j += 1
     f.append(s%2)

Now, we just look for the numbers above 2013 for which f ( n ) f(n) is odd:

1
2
>>> filter (lambda n: t[n],range(2013,3000))
[2047]


f(n) is odd if and only if n = 2^k - 1 for some nonnegative integer k

To prove this, assume that this is true for all values up to n 1 n-1 .

Now,

f ( 2 k 1 ) = f ( 2 k 2 ) + f ( 2 k 3 ) + f ( 2 k 2 k 1 1 ) f(2^k - 1) = f(2^k - 2) + f(2^k - 3) + \cdots f(2^k - 2^{k-1} - 1)

It is not to hard to see that none of the arguments above except the last one is of the form 2 k 1 2^k - 1 . Hence, they are all even by assumption.

The last term, however, simplifies to 2 k 2 k 1 1 = 2 k 1 1 2^k - 2^{k-1} - 1 = 2^{k-1} - 1 the f f of which is odd, by the induction hypotheses.

Hence, in such a case, f ( 2 k 1 ) f(2^k - 1) is always odd.

For the next part of the proof, we need to show that all the odds pair up whenever n 2 k 1 n \neq 2^k - 1 , yielding an even number.

[The rest of the proof is too big for this margin to contain]

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...