题解 | #自守数#

自守数

https://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
    // Write your code here
    while ((line = await readline())) {
        let res = 0;
        for (let i = 0; i <= line; i++) {
            if (isZishoushu(i)) {
                res++;
            }
        }
        console.log(res);
    }
})();

function isZishoushu(n) {
    let pow = Math.pow(n, 2);
    // console.log(pow);
    let s = String(n);
    // console.log(s);
    if (pow % Math.pow(10, s.length) == n) return true;
    return false;
}

全部评论

相关推荐

天门一键开:她的意思是问你有没有论文吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务