### Exploring the number of different ways a number can be expressed as a sum of powers of 2题号：169 难度： 50 中英对照

Define f(0)=1 and f(n) to be the number of different ways n can be expressed as a sum of integer powers of 2 using each power no more than twice.

For example, f(10)=5 since there are five different ways to express 10:

1 + 1 + 8
1 + 1 + 4 + 4
1 + 1 + 2 + 2 + 4
2 + 4 + 4
2 + 8

What is f(1025)?

### Code

import java.math.BigInteger;

public final class p169 {
public static void main(String[] args) {
long start=System.nanoTime();
String result = run();
long end=System.nanoTime();
System.out.println(result);
System.out.println( (end-start)/1000000 + "ms" );
}

static public String run() {
BigInteger bi = new BigInteger("10000000000000000000000000");
long a = 1;
long b = 0;
for (int i = bi.bitLength()-1; i >=0; i--) {
if (bi.testBit(i)){
b += a;
}
else{
a += b;
}
}
return a+"";
}
}
178653872807
1ms