fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5.  
  6. class Main {
  7.  
  8. public static void main (String[] args) throws java.lang.Exception {
  9.  
  10. int sumMin, counter = 1;
  11.  
  12. Scanner scanner = new Scanner(System.in);
  13. int m = scanner.nextInt();
  14. int n = scanner.nextInt();
  15.  
  16. sumMin = sumOfDigits(m);
  17.  
  18. for(int i = m + 1; i <= n; i++) {
  19. if (sumOfDigits(i) < sumMin) {
  20. sumMin = sumOfDigits(i);
  21. counter = 1;
  22. } else if (sumOfDigits(i) == sumMin)
  23. counter++;
  24. }
  25. System.out.println(counter);
  26. }
  27.  
  28. public static int sumOfDigits(int a){
  29. int sum = 0;
  30. while (a > 0) {
  31. sum += a%10;
  32. a /= 10;
  33. }
  34. return sum;
  35. }
  36. }
Success #stdin #stdout 0.15s 321280KB
stdin
1 100
stdout
3