题解 | #挑7#
挑7
https://www.nowcoder.com/practice/ba241b85371c409ea01ac0aa1a8d957b
两者取其一:要么被7整除,要么含7。注意只能选其中一个,如果同时满足,比如77,也只算一次。
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 num = parseInt(line); let count = 0; for(let i=1;i<=num;i++){ if(i%7 == 0){ count++; }else if(i.toString().indexOf('7')!=-1){ count++; } } console.log(count); } }()