언젠가는 펼쳐 볼 아카이브

[BOJ] 2231번 - 분해합 본문

IT/Baekjoon Oline Judge

[BOJ] 2231번 - 분해합

개발자희망생고롸파덕 2024. 1. 9. 17:17

사용언어 : javascript - node.js

 

# 문제

출처 : 백준 온라인

 

 

#제출코드

const fs = require('fs');
const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
const input = fs.readFileSync(filePath).toString().trim();

console.log(solution(+input));

function solution(input) {
  for (let i = 1; i < input; i++) {
    let num = i;
    let temp = i;

    while (temp > 0) {
      num += temp % 10;
      temp = Math.floor(temp / 10);
    }

    if (num === input) {
      return i;
    }
  }

  return 0;
}