const FS = require('fs');
const PATH = process.platform === 'linux' ? '/dev/stdin' : './data.txt';
let input = FS.readFileSync(PATH).toString().trim();
function solve(input) {
let number = Number(input);
let acc = 1;
let line = 1;
let temp = 0;
while (acc < number) {
line++;
temp = acc;
acc += line;
}
if (line % 2 === 1) {
return `${acc - (number - 1)}/${number - temp}`;
} else {
return `${number - temp}/${acc - (number - 1)}`;
}
}
console.log(solve(input));
๋ณ ๊ฑฐ ์๋์ง๋ง, const๋ก ๋ณํ์ง ์๋ ์์๊ฐ์ ์ ์ธํ ๋๋ ๋๋ฌธ์(์ค๋ค์ดํฌ๊ธฐ๋ฒ)์ ์ฐ์.
์กฐ๊ธ ํท๊ฐ๋ฆฌ๊ธด ํ์ง๋ง, ์์ ํ์๋ ๋ฒ์ง ๋ฌธ์ ์ฒ๋ผ ํน์ ๊ตฌ๊ฐ์ ๋๋๊ณ ๊ฐ ๊ตฌ๊ฐ์ ๋๋ ์ ์๊ฐํด๋ณด๋ฉด ์ค๋ง๋ฆฌ๊ฐ ๋ณด์ด๋ ๊ฒ ๊ฐ๋ค.
'๐ JavaScript > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JS] 10250 (0) | 2022.05.19 |
---|---|
[JS] 2869 (0) | 2022.05.19 |
[JS] 2292 (0) | 2022.05.18 |
[JS] 1712 (0) | 2022.05.18 |
[JS] 1316 (0) | 2022.05.18 |