2018-09-30 22:01:58 +00:00
---
id: 5900f41c1000cf542c50ff2e
2020-11-27 18:02:05 +00:00
title: >-
Problem 175: Fractions involving the number of different ways a number can be
expressed as a sum of powers of 2
2018-09-30 22:01:58 +00:00
challengeType: 5
2019-08-05 16:17:33 +00:00
forumTopicId: 301810
2021-01-13 02:31:00 +00:00
dashedName: >-
problem-175-fractions-involving-the-number-of-different-ways-a-number-can-be-expressed-as-a-sum-of-powers-of-2
2018-09-30 22:01:58 +00:00
---
2020-11-27 18:02:05 +00:00
# --description--
2021-07-12 14:19:03 +00:00
Define $f(0) = 1$ and $f(n)$ to be the number of ways to write $n$ as a sum of powers of 2 where no power occurs more than twice.
2018-09-30 22:01:58 +00:00
2021-07-12 14:19:03 +00:00
For example, $f(10) = 5$ since there are five different ways to express 10:
2018-09-30 22:01:58 +00:00
2021-07-12 14:19:03 +00:00
$$10 = 8 + 2 = 8 + 1 + 1 = 4 + 4 + 2 = 4 + 2 + 2 + 1 + 1 = 4 + 4 + 1 + 1$$
It can be shown that for every fraction $\frac{p}{q}\\; (p>0, q>0)$ there exists at least one integer $n$ such that $\frac{f(n)}{f(n - 1)} = \frac{p}{q}$.
For instance, the smallest $n$ for which $\frac{f(n)}{f(n - 1)} = \frac{13}{17}$ is 241. The binary expansion of 241 is 11110001.
Reading this binary number from the most significant bit to the least significant bit there are 4 one's, 3 zeroes and 1 one. We shall call the string 4,3,1 the Shortened Binary Expansion of 241.
Find the Shortened Binary Expansion of the smallest $n$ for which
$$\frac{f(n)}{f(n - 1)} = \frac{123456789}{987654321}$$
Give your answer as a string with comma separated integers, without any whitespaces.
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
# --hints--
2018-09-30 22:01:58 +00:00
2021-07-12 14:19:03 +00:00
`shortenedBinaryExpansionOfNumber()` should return a string.
```js
assert(typeof shortenedBinaryExpansionOfNumber() === 'string');
```
`shortenedBinaryExpansionOfNumber()` should return the string `1,13717420,8` .
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
2021-07-12 14:19:03 +00:00
assert.strictEqual(shortenedBinaryExpansionOfNumber(), '1,13717420,8');
2018-09-30 22:01:58 +00:00
```
2020-11-27 18:02:05 +00:00
# --seed--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
## --seed-contents--
2018-09-30 22:01:58 +00:00
```js
2021-07-12 14:19:03 +00:00
function shortenedBinaryExpansionOfNumber() {
2020-09-15 16:57:40 +00:00
2018-09-30 22:01:58 +00:00
return true;
}
2021-07-12 14:19:03 +00:00
shortenedBinaryExpansionOfNumber();
2018-09-30 22:01:58 +00:00
```
2020-11-27 18:02:05 +00:00
# --solutions--
2018-09-30 22:01:58 +00:00
```js
// solution required
```