& nbsp; Harry & nbsp; ngày 26 tháng 8 năm 2022Harry August 26, 2022
Tác giả: HarryHarry
Xin chào các bạn, cảm ơn vì đã ghé thăm trang web của tôi. Tôi là một lập trình viên Python. Tôi, với một số thành viên khác, viết blog trên trang web này dựa trên Python và lập trình. Chúng tôi vẫn đang trong giai đoạn phát triển đó là lý do tại sao thiết kế trang web không tốt và có nhiều thứ khác cần được sửa chữa trong trang web này nhưng tôi hy vọng tất cả những điều này sẽ xảy ra vào một ngày nào đó. Nhưng, cho đến lúc đó chúng ta sẽ không ngăn mình tải lên các bài viết tuyệt vời hơn. Nếu bạn muốn tham gia với chúng tôi hoặc có bất kỳ câu hỏi nào, bạn có thể gửi thư cho tôi cảm ơn bạn
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 448
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 440
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 459
str_years = [x for x in range[24]]
#[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
#Or, if you're starting with ints:
int_years = [int[x] for x in str_years]
#Formatted here
form_years = ["%02d" % x for x in int_years]
print[form_years]
#['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23']
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
using
2n, we need to find the sum of its digits such that: If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]
If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
5Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum[x] == 10
Hence ans will be 1+0 = 1
Input : 5674
Output : 4
4 If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
47If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
65 using
9 If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
34__
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
using
9brute force approach is to sum all the digits until the sum < 10. Flowchart:
192
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]47
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]65
using
9namespace
0C++
#include
using
namespace
std;
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]1
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]3
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 45
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]9
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 40
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 45
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 49
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]7
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
13
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
15
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
17
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
13
192
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
94
13
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 95
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 904
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
94
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
94
13
Java
96
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 912
99
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]83
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
#include
2 If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]1
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]3
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
namespace
5using
2namespace
0Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]9
using
6using
2 using
8using
9namespace
0Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
namespace
5using
2namespace
7namespace
8
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 49
namespace
8using
1using
2using
3
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
13
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
std;
7std;
8using
3Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]01
std;
8using
3Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
13
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 92
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
13
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
98
#include
2 If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]14
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]15
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]20
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]21
using
3Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]24
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
13
13
Python
96
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]29
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]30
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]31
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]33
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
using
2If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]9
using
6____72 If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]40
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]33
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]47
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
using
2If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]44
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]53
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]33
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]33
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
using
2Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]33
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]62
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]53
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]65
std;
8Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]53
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]69
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
std;
8If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]33
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]53
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]21
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]78
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]79
C#
using
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]81
99
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]83
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
#include
2 If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]1
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]3
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]7
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]9
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 40
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 45
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
namespace
8
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 49
namespace
8
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]7
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
13
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
15
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
17
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
13
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 92
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
13
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
98
#include
2 If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]14
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]15
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]20
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]21
using
3Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 433
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
13
13
Python
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 437
96
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]29
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]30
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]31
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]33
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
using
2If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]9
using
6____72 If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]40
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]33
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]47
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
using
2If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]44
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]53
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]33
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
13
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]33
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
using
2Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]33
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]62
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]53
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]65
std;
8If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
13
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]53
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]69
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
std;
813
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]33
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]53
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]21
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 495
If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
78 If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
79
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 496
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 498
using
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]81
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
103
99
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]83
107
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
109
namespace
8
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 49
namespace
8
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]7
107
13
107
117
107
119
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
13
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 92
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
13
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
128
129
If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
5#include
2 If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
0 If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
1If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
0 If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
3
130
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]7
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]9
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 40
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]9
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 40
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 45
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 49
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]7
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 45
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
15
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
17
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
13
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
98
#include
2 If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]14
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 426
13
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 99
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
PHP
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
172
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 448
174
175
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 438
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 439
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 440
namespace
013
If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
5Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum[x] == 10
Hence ans will be 1+0 = 1
Input : 5674
Output : 4
44 Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum[x] == 10
Hence ans will be 1+0 = 1
Input : 5674
Output : 4
45
1
If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
5If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
9Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum[x] == 10
Hence ans will be 1+0 = 1
Input : 5674
Output : 4
48Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum[x] == 10
Hence ans will be 1+0 = 1
Input : 5674
Output : 4
40 Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum[x] == 10
Hence ans will be 1+0 = 1
Input : 5674
Output : 4
50Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum[x] == 10
Hence ans will be 1+0 = 1
Input : 5674
Output : 4
44 Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum[x] == 10
Hence ans will be 1+0 = 1
Input : 5674
Output : 4
52 O[log[n]].
Auxiliary Space: O[1]
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 448
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 440
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 459
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 48
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 440
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 464
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44444
There exists a simple and elegant O[1] solution for this too. The answer is given simply:-
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 9
Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum[x] == 10
Hence ans will be 1+0 = 1
Input : 5674
Output : 4
8Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum[x] == 10
Hence ans will be 1+0 = 1
Input : 5674
Output : 4
44 Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum[x] == 10
Hence ans will be 1+0 = 1
Input : 5674
Output : 4
45
Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum[x] == 10
Hence ans will be 1+0 = 1
Input : 5674
Output : 4
3Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum[x] == 10
Hence ans will be 1+0 = 1
Input : 5674
Output : 4
44 Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum[x] == 10
Hence ans will be 1+0 = 1
Input : 5674
Output : 4
74Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum[x] == 10
Hence ans will be 1+0 = 1
Input : 5674
Output : 4
40 Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum[x] == 10
Hence ans will be 1+0 = 1
Input : 5674
Output : 4
76
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 440
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 479
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 440
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 481
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 444
using
3If a number n is divisible by 9, then the sum of its digit until the sum becomes a single digit is always 9. For example,
Let, n = 2880
Sum of digits = 2 + 8 + 8 = 18: 18 = 1 + 8 = 9
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 440
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 490
A number can be of the form 9x or 9x + k. For the first case, the answer is always 9. For the second case, and is always k which is the remainder left.
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 491
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]1
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 440
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 494
JavaScript
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 438
101
C++
#include
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]9
106
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]7
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]9
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 40
192
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
94
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
197
13
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 95
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 904
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 906
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
94
13
Java
96
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 912
99
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]83
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
#include
2 If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]1
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]3
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
namespace
5using
2namespace
0Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
using
2using
3Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 934
using
9 If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 936__72
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
13
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
98
#include
2 If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]14
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 949
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]20
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 9555____73
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]24
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
13
13
Python3
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]30
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 963
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]47
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
using
2If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]44
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
using
2If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]47
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]65
using
9 If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34__
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
using
9If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 987
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 988
192
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]47
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]65
using
9namespace
0If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]53
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 955
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]78
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]79
C#
using
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]81
99
903
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
#include
2 If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]1
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]3
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
namespace
5using
2namespace
0Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
using
2using
3Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 934
using
9 If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 936__72
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
13
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
98
#include
2 If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]14
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 949
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]20
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 9555____73
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 433
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
13
13
If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
30 If n == 0
return 0;
If n % 9 == 0
digSum[n] = 9
Else
digSum[n] = n % 9
63
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 437
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]47
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
using
2If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]44
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
using
2Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
using
2using
3Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 934
using
9 If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 936__72
13
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
98
#include
2 If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]14
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 949
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]0
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]20
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 9555____73
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]30
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 963
If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
5Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum[x] == 10
Hence ans will be 1+0 = 1
Input : 5674
Output : 4
4 If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
47If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
34If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
34 using
2If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
44
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 496
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
using
2If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]4
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]47
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]65
using
9 If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34__
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
using
2using
3Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 43
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 91
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 934
using
9 If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 936__72
13
If n == 0 return 0; If n % 9 == 0 digSum[n] = 9 Else digSum[n] = n % 904
983
129
Output:
9
If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
59
8 #include
2 If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
14 If n == 0
return 0;
If n % 9 == 0
digSum[n] = 9
Else
digSum[n] = n % 9
49 O[1]
Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum[x] == 10
Hence ans will be 1+0 = 1
Input : 5674
Output : 4
3If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
0 If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
20If n == 0
return 0;
If n % 9 == 0
digSum[n] = 9
Else
digSum[n] = n % 9
555____73 O[1]
If n < 10
digSum[n] = n
Else
digSum[n] = Sum[digSum[n]]
30 If n == 0
return 0;
If n % 9 == 0
digSum[n] = 9
Else
digSum[n] = n % 9
63
//www.geeksforgeeks.org/digital-rootrepeated-digital-sum-given-integer/
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]5
Input : 1234 Output : 1 Explanation : The sum of 1+2+3+4 = 10, digSum[x] == 10 Hence ans will be 1+0 = 1 Input : 5674 Output : 44
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]47
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]34
using
2If n < 10 digSum[n] = n Else digSum[n] = Sum[digSum[n]]44Ayush Khanduri. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.