Largest sum of digits in all Divisors
Easy Accuracy: 19.24% Submissions: 26 Points: 2

Given a integer number n, find largest sum of digits in all divisors of n.

 

Example 1:

Input:
n = 12
Output:
6
Explanation:
The divisors of 6 are: 1,2,3,4,6,12.
6 is the maximum digit-sum among all divisors.

Example 2:

Input:
n = 34
Output:
8
Explanation:
The divisors of 34 are: 1,2,17,34.
8 is the maximum digit-sum among all divisors. 

 

Your Task:
You don't need to read input or print anything. Your task is to complete the function getLargest() which takes an Integer n as input and returns the answer.

 

Expected Time Complexity: O(sqrt(n)*log(n))
Expected Auxiliary Space: O(1)

 

Constraints:
1 <= n <= 106

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Output Window