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 <= 10^{6}

Source: geeksforgeeks | Difficulty: EASY
Tags: Number theory

Starter code: #User function Template for python3

class Solution:
    def getLargest(self, n):
        # code here 

Solutions:
from math import sqrt

class Solution:

	def getLargest(self, n):

		def getsum(n):
			s = 0
			while n != 0:
				s += n % 10
				n = n // 10
			return s
		c = 0
		x = int(sqrt(n))
		maxsum = 0
		for i in range(1, x + 1):
			if n % i == 0:
				aux1 = getsum(i)
				aux2 = getsum(n / i)
				maxsum = max(maxsum, aux1, aux2)
		return int(maxsum)


class Solution:

	def getLargest(self, n):
		k = 0
		if n == 1:
			return 1
		for i in range(1, int(n ** 0.5)):
			m = 0
			p = 0
			if n % i == 0:
				a = str(i)
				b = str(n // i)
				for j in range(len(a)):
					m += int(a[j])
				for t in range(len(b)):
					p += int(b[t])
				m = max(m, p)
				k = max(k, m)
		return k