2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: 5900f3a01000cf542c50feb3
|
2020-12-16 00:37:30 -07:00
|
|
|
|
title: 问题52:置换倍数
|
2018-10-10 18:03:03 -04:00
|
|
|
|
challengeType: 5
|
|
|
|
|
videoUrl: ''
|
2021-01-13 03:31:00 +01:00
|
|
|
|
dashedName: problem-52-permuted-multiples
|
2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --description--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
可以看出,数字125874及其双精度数251748包含完全相同的数字,但顺序不同。找到最小的正整数x,使得2x,3x,4x,5x和6x包含相同的数字。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --hints--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
`permutedMultiples()`应该返回142857。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
|
assert.strictEqual(permutedMultiples(), 142857);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```
|
|
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
|
# --seed--
|
|
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
function permutedMultiples() {
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
permutedMultiples();
|
|
|
|
|
```
|
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --solutions--
|
2020-08-13 17:24:35 +02:00
|
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
|
```js
|
|
|
|
|
function permutedMultiples() {
|
|
|
|
|
const isPermutation = (a, b) =>
|
|
|
|
|
a.length !== b.length
|
|
|
|
|
? false
|
|
|
|
|
: a.split('').sort().join() === b.split('').sort().join();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let start = 1;
|
|
|
|
|
let found = false;
|
|
|
|
|
let result = 0;
|
|
|
|
|
|
|
|
|
|
while (!found) {
|
|
|
|
|
start *= 10;
|
|
|
|
|
for (let i = start; i < start * 10 / 6; i++) {
|
|
|
|
|
found = true;
|
|
|
|
|
for (let j = 2; j <= 6; j++) {
|
|
|
|
|
if (!isPermutation(i + '', j * i + '')) {
|
|
|
|
|
found = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (found) {
|
|
|
|
|
result = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
```
|