fork download
  1. <?php
  2. // Read input values
  3. list($N, $A, $B) = explode(" ", trim(fgets(STDIN)));
  4.  
  5. // Iterate through numbers and calculate the sum
  6. $totalSum = 0;
  7. for ($i = 1; $i <= $N; $i++) {
  8. $num = $i;
  9. $sumOfDigits = 0;
  10.  
  11. // Calculate sum of digits without using a separate function
  12. while ($num > 0) {
  13. $sumOfDigits += $num % 10;
  14. $num = (int)($num / 10);
  15. }
  16.  
  17. if ($sumOfDigits >= $A && $sumOfDigits <= $B) {
  18. $totalSum += $i;
  19. }
  20. }
  21.  
  22. // Output the result
  23. echo $totalSum;
  24. ?>
  25.  
Success #stdin #stdout 0.03s 25604KB
stdin
20 2 5
stdout
84