fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdint>
  4. #include <map>
  5.  
  6. typedef std::vector<std::uintmax_t> DType;
  7. typedef std::map<std::uintmax_t, std::uintmax_t> MType;
  8. DType SepDigit(std::uintmax_t N, std::uintmax_t R) {
  9. DType D;
  10.  
  11. while (N != 0) {
  12. D.push_back(N % R);
  13. N /= R;
  14. }
  15.  
  16. return D;
  17. }
  18. MType MakeHoge(const std::uintmax_t& L,std::uintmax_t R) {
  19. MType M;
  20. for (std::uintmax_t i = 0; i <= L; i++) {
  21. auto S = SepDigit(i, R);
  22. std::uintmax_t X = 0;
  23. for (auto o : S) { X += o; }
  24. M[X]++;
  25. }
  26. return M;
  27. }
  28.  
  29. int main() {
  30.  
  31. MType R;
  32. std::uintmax_t L = 9999;
  33. std::uintmax_t Radix = 10;
  34.  
  35. R = MakeHoge(L,Radix);
  36.  
  37. for (auto& o : R) {
  38. std::cout << o.first << ':' << o.second << std::endl;
  39. }
  40.  
  41. return 0;
  42.  
  43.  
  44. }
Success #stdin #stdout 0s 4396KB
stdin
Standard input is empty
stdout
0:1
1:4
2:10
3:20
4:35
5:56
6:84
7:120
8:165
9:220
10:282
11:348
12:415
13:480
14:540
15:592
16:633
17:660
18:670
19:660
20:633
21:592
22:540
23:480
24:415
25:348
26:282
27:220
28:165
29:120
30:84
31:56
32:35
33:20
34:10
35:4
36:1