fork download
  1. process.stdin.resume();
  2. process.stdin.setEncoding('utf8');
  3.  
  4. // your code goes here
  5. function solve() {
  6. const input = require('fs').readFileSync('/dev/stdin', 'utf8').trim();
  7. const [a, b] = input.split(' ').map(Number);
  8.  
  9. function countClaps(N) {
  10. if (N <= 0) return 0;
  11.  
  12. let total = 0;
  13. let power = 1;
  14.  
  15. while (power <= N) {
  16. const higher = Math.floor(N / (power * 10));
  17. const current = Math.floor(N / power) % 10;
  18. const lower = N % power;
  19.  
  20. for (const target of [3, 6, 9]) {
  21. if (current > target) {
  22. total += (higher + 1) * power;
  23. } else if (current === target) {
  24. total += higher * power + (lower + 1);
  25. } else {
  26. total += higher * power;
  27. }
  28. }
  29.  
  30. power *= 10;
  31. }
  32.  
  33. return total;
  34. }
  35.  
  36. console.log(countClaps(b) - countClaps(a - 1));
  37. }
  38.  
  39. solve();
Success #stdin #stdout 0.08s 43368KB
stdin
999999 10000000
stdout
19200006