fork download
  1. process.stdin.resume();
  2. process.stdin.setEncoding('utf8');
  3.  
  4. function countNumber(num) {
  5. let count = 0;
  6. while (num > 0) {
  7. const digit = num % 10;
  8. // if (digit === 6) {
  9. if (digit === 3 || digit === 6|| digit === 9) {
  10. count++;
  11. }
  12. num = Math.floor(num / 10);
  13. }
  14. return count;
  15. }
  16.  
  17.  
  18. function countInRange(first, last){
  19. let count = 0;
  20. for(let i = first; i< last; i++){
  21. count+=countNumber(i)
  22. }
  23. return count
  24. }
  25.  
  26. var remainder = ''
  27. process.stdin.on('data', function (chunk) {
  28. const input = chunk.toString().split(' ')
  29. console.log(input[0], input[1])
  30. const result = countInRange(Number(input[0]), Number(input[1]))
  31. console.log(result)
  32. });
Success #stdin #stdout 0.86s 37728KB
stdin
1 10000000
stdout
1 10000000
21000000