Another approach requiring 7 +
:
int M1 = a;
int M2 = M1 + M1;
int M4 = M2 + M2;
int M8 = M4 + M4;
int M16 = M8 + M8;
int res = M16 + M8 + M4 + M1;
The result is built from a binary multiplier pattern, that is, 29 decimal numbers is binary code 0001.1101. Therefore, we need to add M16, M8, M4 and M1 (and exclude M2).
source
share