fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int sumOfDigits(int a){
  5. int sum = 0;
  6. while (a > 0){
  7. sum += a%10;
  8. a /= 10;
  9. }
  10. return sum;
  11. }
  12.  
  13. int main() {
  14. int m, n, sumMin, counter = 1;
  15. cin >> m >> n;
  16. sumMin = sumOfDigits(m);
  17. for(int i = m + 1; i <= n; i++){
  18. if (sumOfDigits(i) < sumMin){
  19. sumMin = sumOfDigits(i);
  20. counter = 1;
  21. }
  22. else if (sumOfDigits(i) == sumMin)
  23. counter++;
  24. }
  25. cout << counter;
  26. return 0;
  27. }
Success #stdin #stdout 0s 3416KB
stdin
2 2 
stdout
1