2021-06-15 00:49:18 -07:00
|
|
|
|
---
|
|
|
|
|
id: 5900f3941000cf542c50fea7
|
2021-08-20 00:00:51 -07:00
|
|
|
|
title: 'Problema 40: Constante de Champernowne'
|
2021-06-15 00:49:18 -07:00
|
|
|
|
challengeType: 5
|
|
|
|
|
forumTopicId: 302066
|
|
|
|
|
dashedName: problem-40-champernownes-constant
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# --description--
|
|
|
|
|
|
2021-08-20 00:00:51 -07:00
|
|
|
|
Uma fração decimal irracional é criada concatenando os números inteiros positivos:
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
|
|
0.12345678910**1**112131415161718192021...
|
|
|
|
|
|
2021-08-20 00:00:51 -07:00
|
|
|
|
Podemos notar que o 12º algarismo da parte fracionária é 1.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
2021-11-29 08:32:04 -08:00
|
|
|
|
Se *d<sub>n</sub>* representa o *n*-ésimo algarismo da parte fracionária, encontre o valor da expressão a seguir:
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
|
|
d<sub>1</sub> × d<sub>10</sub> × d<sub>100</sub> × d<sub>1000</sub> × d<sub>10000</sub> × d<sub>100000</sub> × d<sub>1000000</sub>
|
|
|
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
|
2021-08-20 00:00:51 -07:00
|
|
|
|
`champernownesConstant(100)` deve retornar um número.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
assert(typeof champernownesConstant(100) === 'number');
|
|
|
|
|
```
|
|
|
|
|
|
2021-08-20 00:00:51 -07:00
|
|
|
|
`champernownesConstant(100)` deve retornar 5.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
assert.strictEqual(champernownesConstant(100), 5);
|
|
|
|
|
```
|
|
|
|
|
|
2021-08-20 00:00:51 -07:00
|
|
|
|
`champernownesConstant(1000)` deve retornar 15.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
assert.strictEqual(champernownesConstant(1000), 15);
|
|
|
|
|
```
|
|
|
|
|
|
2021-08-20 00:00:51 -07:00
|
|
|
|
`champernownesConstant(1000000)` deve retornar 210.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
assert.strictEqual(champernownesConstant(1000000), 210);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# --seed--
|
|
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
function champernownesConstant(n) {
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
champernownesConstant(100);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# --solutions--
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
function champernownesConstant(n) {
|
|
|
|
|
let fractionalPart = '';
|
|
|
|
|
for (let i = 0; fractionalPart.length <= n; i++) {
|
|
|
|
|
fractionalPart += i.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let product = 1;
|
|
|
|
|
for (let i = 0; i < n.toString().length; i++) {
|
|
|
|
|
const index = 10 ** i;
|
|
|
|
|
product *= parseInt(fractionalPart[index], 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return product;
|
|
|
|
|
}
|
|
|
|
|
```
|