fork download
  1. // Level 1 - Homework 1 - Question U - Solution 1.
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int N = 0;
  10. int A = 0;
  11. int B = 0;
  12. cin >> N >> A >> B;
  13.  
  14. int Answer = 0;
  15. for(int i = 1; i <= N; ++i)
  16. {
  17. int Sum = 0;
  18. string Basel = to_string(i);
  19. for(int j = 0; j < Basel.size(); ++j)
  20. {
  21. Sum += Basel[j] - 48;
  22. }
  23. if(Sum >= A && Sum <= B)
  24. Answer += i;
  25. }
  26.  
  27. cout << Answer << endl;
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0.01s 5304KB
stdin
100 4 16
stdout
4554