Algorithm
- ์๊ทธ๋ง -
๋ฌธ์
๋ ์ ์ A์ B๊ฐ ์ฃผ์ด์ก์ ๋, ๋ ์ ์ ์ฌ์ด์ ์๋ ์์ ํฉ์ ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค.
์ฌ์ด์ ์๋ ์๋ค์ A์ B๋ ํฌํจํ๋ค.
์ ์ถ๋ ฅ ์์
๋ฌธ์ ํ๊ธฐ
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let input = [];
let sum = 0;
rl.on("line", function (line) {
input = line
.toString()
.split(" ")
.map((el) => Number(el));
}).on("close", function () {
if (input[0] > input[1]) {
sum = ((input[0] - input[1] + 1) * (input[0] + input[1])) / 2;
} else {
sum = ((input[1] - input[0] + 1) * (input[0] + input[1])) / 2;
}
console.log(sum);
process.exit();
});
๋ฐ์ํ
'๊ฐ์ธ๊ณต๋ถ > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค][Node.js] 2438๋ฒ : ๋ณ์ฐ๊ธฐ - 1 (0) | 2021.08.03 |
---|---|
[๋ฐฑ์ค][Node.js] 2420๋ฒ : ์ฌํ๋ฆฌ์๋ (0) | 2021.08.02 |
[๋ฐฑ์ค][Node.js] 2338๋ฒ : ๊ธด์๋ฆฌ ๊ณ์ฐ (0) | 2021.08.01 |
[๋ฐฑ์ค][Node.js] 2292๋ฒ : ๋ฒ์ง (0) | 2021.07.30 |
[๋ฐฑ์ค][Node.js] 2178๋ฒ : ๋ฏธ๋ก ํ์ (0) | 2021.07.29 |
๋๊ธ