题解 | #水仙花数#
水仙花数
https://www.nowcoder.com/practice/11c9f023a9f84418a15b48792a5f7c70
代码
let line ; while(line = readline()){ let arr = line.split(" ") let n = parseInt(arr[0]) let m = parseInt(arr[1]) let res = []; for(let i = n; i <= m; i++) { let hurdred = parseInt((i / 100)); let ten = parseInt((i % 100 / 10)) let unit = parseInt((i % 100 % 10)) if(unit**3 + ten**3 + hurdred**3 == i) res.push(i) // console.log(unit,ten,hurdred) } if(res.length) { let s = res.reduce((p,c) => { return p + " " + c }) console.log(s) } else { console.log("no") } }#算法学习#