๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ์ธ๊ณต๋ถ€/Algorithm

[๋ฐฑ์ค€][Node.js] 2355๋ฒˆ : ์‹œ๊ทธ๋งˆ

by ๐Ÿ‡๋ฐ•๋ด‰๋ด‰๐Ÿ‡ 2021. 8. 1.

 

 

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();
});

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€