fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdint>
  4. #include <algorithm>
  5.  
  6. typedef std::vector<std::uintmax_t> DType;
  7.  
  8. DType SepDigit(std::uintmax_t N, std::uintmax_t R) {
  9. DType D;
  10.  
  11. while (N) {
  12. D.push_back(N % R);
  13. N /= R;
  14. }
  15.  
  16. return D;
  17. }
  18.  
  19. DType MakeHoge(std::uintmax_t F, std::uintmax_t E, std::uintmax_t N,std::uintmax_t R=10) {
  20. if (F > E) { std::swap(F, E); }
  21.  
  22. DType Re;
  23.  
  24. for (std::uintmax_t i=F;i < E; i++) {
  25. DType D = SepDigit(i,R);
  26. std::uintmax_t X = 0;
  27. for (auto& o : D) {
  28. X += o;
  29. }
  30. if (N == X) {
  31. Re.push_back(i);
  32. }
  33. }
  34. return Re;
  35. }
  36.  
  37. int main() {
  38. DType R;
  39.  
  40. R = MakeHoge(1, 100, 12);
  41.  
  42. for (auto& o : R) {
  43. std::cout << o << ',';
  44. }
  45. std::cout << std::endl;
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0s 4400KB
stdin
Standard input is empty
stdout
39,48,57,66,75,84,93,