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

[๋ฐฑ์ค€][Node.js] 6679๋ฒˆ : ์‹ฑ๊ธฐํ•œ ๋„ค์ž๋ฆฌ ์ˆซ์ž

by ๐Ÿ‡๋ฐ•๋ด‰๋ด‰๐Ÿ‡ 2021. 12. 6.

 

 

Algorithm

-  ์‹ฑ๊ธฐํ•œ ๋„ค์ž๋ฆฌ ์ˆซ์ž -

 


 

๋ฌธ์ œ

์‹ฑ๊ธฐํ•œ ๋„ค์ž๋ฆฌ ์ˆซ์ž๋ž€, [1000,9999]์ธ 10์ง„์ˆ˜ ์ˆซ์ž์ค‘์—์„œ,  ๋‹ค์Œ์˜ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ์ˆซ์ž๋ฅผ ๋งํ•œ๋‹ค.

  • ์ˆซ์ž๋ฅผ 10์ง„์ˆ˜, 12์ง„์ˆ˜, 16์ง„์ˆ˜๋กœ ๋‚˜ํƒ€๋‚ธ ๋‹ค์Œ, ๊ฐ๊ฐ์˜ ์ˆซ์ž์— ๋Œ€ํ•ด, ๊ฐ ์ˆซ์ž์˜ ์ž๋ฆฌ์ˆ˜๋ฅผ ๋”ํ–ˆ์„ ๋•Œ, ์„ธ ๊ฐ’์ด ๋ชจ๋‘ ๊ฐ™์•„์•ผ ํ•œ๋‹ค.

์—ฌ๋Ÿฌ๋ถ„์€ ์‹ฑ๊ธฐํ•œ ๋„ค์ž๋ฆฌ ์ˆซ์ž๋ฅผ ๋ชจ๋‘ ์ถœ๋ ฅํ•ด์•ผ ํ•œ๋‹ค.

 

์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

 

๋ฌธ์ œ ํ’€๊ธฐ

const readline = require("readline");
const rl = readline.createInterface({
	input: process.stdin,
	output: process.stdout,
});
rl.on("line", function () {}).on("close", function () {
	for (let i = 1000; i <= 9999; i++) {
		let ten = 0;
		let twelve = 0;
		let sixteen = 0;
		let number = i;

		while (number !== 0) {
			ten += number % 10;
			number = Math.floor(number / 10);
		}
		number = i;
		while (number !== 0) {
			twelve += number % 12;
			number = Math.floor(number / 12);
		}
		number = i;
		while (number !== 0) {
			sixteen += number % 16;
			number = Math.floor(number / 16);
		}
		if (ten === twelve && twelve === sixteen) console.log(i);
	}
	process.exit();
});

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€