fork download
  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. int countNum(const std::string& s, int i)
  5. {
  6. int j = i;
  7. int count = 0;
  8. while (s[j++] == s[i]) ++count;
  9. return count;
  10. }
  11.  
  12. std::string nextTerm(const std::string& s)
  13. {
  14. std::ostringstream oss;
  15. for (int i = 0; i < s.size(); )
  16. {
  17. int n = countNum(s, i);
  18. oss << n << s[i];
  19. i += n;
  20. }
  21. return oss.str();
  22. }
  23.  
  24. int digitSum(const std::string& s)
  25. {
  26. int sum = 0;
  27. for (char c : s) sum += c - '0';
  28. return sum;
  29. }
  30.  
  31. int main()
  32. {
  33. std::string s = "1";
  34. for (int i = 0; i < 63; ++i)
  35. {
  36. std::cout << i+1 << "\t" << digitSum(s) << "\t" << s.size() << "\n";
  37. s = nextTerm(s);
  38. }
  39. }
Success #stdin #stdout 14.9s 3416KB
stdin
Standard input is empty
stdout
1	1	1
2	2	2
3	3	2
4	5	4
5	8	6
6	10	6
7	13	8
8	16	10
9	23	14
10	32	20
11	44	26
12	56	34
13	76	46
14	102	62
15	132	78
16	174	102
17	227	134
18	296	176
19	383	226
20	505	302
21	679	408
22	892	528
23	1151	678
24	1516	904
25	1988	1182
26	2602	1540
27	3400	2012
28	4410	2606
29	5759	3410
30	7519	4462
31	9809	5808
32	12810	7586
33	16710	9898
34	21758	12884
35	28356	16774
36	36955	21890
37	48189	28528
38	62805	37158
39	81803	48410
40	106647	63138
41	139088	82350
42	181301	107312
43	236453	139984
44	308150	182376
45	401689	237746
46	523719	310036
47	682571	403966
48	889807	526646
49	1159977	686646
50	1511915	894810
51	1970964	1166642
52	2569494	1520986
53	3349648	1982710
54	4366359	2584304
55	5691884	3369156
56	7419702	4391702
57	9671795	5724486
58	12608013	7462860
59	16435261	9727930
60	21424450	12680852
61	27928126	16530884
62	36407156	21549544
63	47459488	28091184