-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path11005.js
More file actions
34 lines (26 loc) · 723 Bytes
/
11005.js
File metadata and controls
34 lines (26 loc) · 723 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
B진법으로 몇 자리 숫자인지를 찾는다
그다음에 나눗셈
*/
const INPUT_FILE = process.platform === 'linux' ? '/dev/stdin' : './input';
const [value, base] = require('fs').readFileSync(INPUT_FILE).toString().trim()
.split(' ')
.map(Number);
const digits = [];
for (let digit = 1; digit <= value; digit *= base) {
digits.push(digit);
}
const change = [];
let remainder = value;
while (digits.length) {
const dividend = digits.pop();
const quotient = Math.floor(remainder / dividend);
remainder %= dividend;
change.push(quotient);
}
const sol = change.map((value) => (
value < 10
? value
: String.fromCharCode(value - 10 + 'A'.charCodeAt(0))
));
console.log(sol.join(''));