Given a positive number n. You need to write a program to find the maximum sum of distinct numbers such that the LCM of all these numbers is equal to n and those numbers are less than or equal to n.
Example 1:
Input: n = 2
Output: 3 
Explanation: The distinct numbers you can have are 
just 1 and 2 and their sum is equal to 3.
Example 2:
Input: n = 5
Output: 6
Explanation: The distinct numbers you can have 
are just 1 and 5 and their sum is equal to 6.
Your Task:  
You dont need to read input or print anything. Complete the function maxSumLCM() which takes n as input parameter and returns the maximum sum of distinct numbers such that the LCM of all these numbers is equal to n.
Expected Time Complexity: O(sqrt(n))
Expected Auxiliary Space: O(1)
Constraints:
1<= N <=1000000000

Source: geeksforgeeks | Difficulty: EASY

Starter code: #User function Template for python3

class Solution:

    def maxSumLCM (self, n):

        # code here 

Solutions:
import math

class Solution:

	def maxSumLCM(self, n):
		maxsum = 0
		for i in range(1, int(math.sqrt(n)) + 1):
			if n % i == 0:
				if n / i == i:
					maxsum = maxsum + i
				else:
					maxsum = maxsum + i + n / i
		return int(maxsum)


class Solution:

	def maxSumLCM(self, n):
		ls = [n]
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				ls.append(i)
				if i != n // i:
					ls.append(n // i)
		return sum(set(ls))


class Solution:

	def isPrime(self, N):
		if N == 1 or N == 2:
			return True
		for i in range(2, int(N ** 0.5) + 1):
			if N % i == 0:
				return False
		return True

	def maxSumLCM(self, n):
		if self.isPrime(n):
			return 1 + n
		ls = [n]
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				ls.append(i)
				if i != n // i:
					ls.append(n // i)
		return sum(set(ls))


class Solution:

	def maxSumLCM(self, n):
		sum = 0
		i = 1
		while i * i <= n:
			if n % i == 0:
				sum += i
				if i * i != n:
					sum += n // i
			i += 1
		return sum


class Solution:

	def maxSumLCM(self, n):
		s = set()
		x = int(n ** 0.5) + 1
		for i in range(1, x):
			if n % i == 0:
				s.add(i)
				s.add(n // i)
		return sum(s)


import math

class Solution:

	def maxSumLCM(self, n):
		ans = 0
		i = 1
		while i ** 2 <= n:
			if n % i == 0:
				ans += i
				if n // i != i:
					ans += n // i
			i += 1
		return ans


import math

class Solution:

	def maxSumLCM(self, n):
		n1 = int(math.sqrt(n))
		ans = 0
		for i in range(1, n1 + 1):
			if n % i == 0:
				ans += i
				if n // i != i:
					ans += n // i
		return int(ans)


import numpy as np
import math

class Solution:

	def maxSumLCM(self, n):
		s = 0
		l = int(math.sqrt(n)) + 1
		i = 1
		while i * i <= n:
			if n % i == 0:
				s += i
				if i != n / i:
					s += n / i
			i = i + 1
		s = int(s)
		return s


import math

class Solution:

	def maxSumLCM(self, n):
		sum = 0
		a = math.sqrt(n + 1)
		for i in range(1, int(math.sqrt(n)) + 1):
			if n % i == 0:
				sum = sum + i
				if n / i != i:
					sum += n / i
		return int(sum)


t = int(input())
for _ in range(t):
	n = int(input())
	max_sum = 0
	i = 1
	while i ** 2 <= n:
		if n % i == 0:
			max_sum += i
			if n // i != i:
				max_sum += n // i
		i += 1
	print(max_sum)


class Solution:

	def maxSumLCM(self, n):
		mx = 0
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				if n // i == i:
					mx += i
				else:
					mx += i + n // i
		return mx


import math

class Solution:

	def maxSumLCM(self, n):
		num = int(math.sqrt(n))
		s = 0
		for i in range(num, 0, -1):
			if n % i == 0:
				if i == n // i:
					s += i
					continue
				s += i + n // i
		return s


class Solution:

	def maxSumLCM(self, n):
		max_sum = 0
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				max_sum += i
				if i != n // i:
					max_sum += n // i
		return max_sum


class Solution:

	def maxSumLCM(self, n):
		max_sum = 0
		i = 1
		while i ** 2 <= n:
			if n % i == 0:
				max_sum += i
				if n // i != i:
					max_sum += n // i
			i += 1
		return max_sum


from functools import reduce

class Solution:

	def maxSumLCM(self, n):
		return sum(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))


class Solution:

	def maxSumLCM(self, n):
		if n == 1:
			return 1
		else:
			i = 2
			sm = 1 + n
			while i * i < n:
				if n % i == 0:
					sm += i + n // i
				i += 1
			if i * i == n:
				sm += i
			return sm


import math

class Solution:

	def lcm(self, a, b):
		return abs(a * b) // math.gcd(a, b)

	def maxSumLCM(self, n):
		ans = 0
		i = 1
		while i * i <= n:
			if n % i == 0:
				if n / i == i:
					ans += i
				else:
					ans += i + n // i
			i += 1
		return ans


from math import floor, sqrt

class Solution:

	def maxSumLCM(self, n):
		count = 0
		for i in range(1, int(sqrt(n)) + 1):
			if n % i == 0:
				if n // i != i:
					count += i
					count += n // i
				else:
					count += i
		return count


class Solution:

	def maxSumLCM(self, n):
		l = 1
		d = set()
		while l * l <= n:
			if n % l == 0:
				d.add(l)
				d.add(n // l)
			l += 1
		return sum(d)


import math

class Solution:

	def maxSumLCM(self, n):
		maxsum = 0
		i = 1
		while i * i <= n:
			if n % i == 0:
				maxsum += i
				if n // i != i:
					maxsum += n // i
			i += 1
		return maxsum


def factors(n):
	l = [1, n]
	import math
	for _ in range(2, int(math.sqrt(n)) + 1):
		if n % _ == 0:
			l.append(_)
			l.append(n / _)
	return list(set(l))

class Solution:

	def maxSumLCM(self, n):
		factor_list = factors(n)
		return int(sum(factor_list))


class Solution:

	def maxSumLCM(self, n):
		a = 1
		b = 0
		while a * a <= n:
			if n % a == 0:
				b = b + a
				if n // a != a:
					b = b + n // a
			a = a + 1
		return b


from math import sqrt

class Solution:

	def factors(self, n):
		x = int(sqrt(n)) + 1
		s = 0
		for i in range(1, x):
			if n % i == 0:
				s += i
			if i != n // i:
				if n % (n // i) == 0:
					s += n // i
		return s

	def maxSumLCM(self, n):
		if n == 1:
			return 1
		return self.factors(n)


import math

class Solution:

	def lcm(self, a, b):
		return abs(a * b) // math.gcd(a, b)

	def maxSumLCM(self, n):
		maxsum = 0
		for i in range(1, int(math.sqrt(n)) + 1):
			if n % i == 0:
				if n / i == i:
					maxsum = maxsum + i
				else:
					maxsum = maxsum + i + n / i
		return int(maxsum)


class Solution:

	def maxSumLCM(self, n):
		i = 1
		l = []
		while i * i <= n:
			if n % i == 0:
				z = n // i
				l.extend([i, z])
			i += 1
		s = sum(set(l))
		return s


import math

class Solution:

	def maxSumLCM(self, N):
		sum = 0
		LIM = int(math.sqrt(N))
		for i in range(1, LIM + 1):
			if N % i == 0:
				if i == N // i:
					sum = sum + i
				else:
					sum = sum + (i + N // i)
		return sum


import math

class Solution:

	def maxSumLCM(self, n):
		factors = []
		for i in range(1, int(math.sqrt(n)) + 1):
			if n % i == 0:
				if i not in factors:
					factors.append(i)
				if int(n / i) not in factors:
					factors.append(int(n / i))
		return sum(factors)


class Solution:

	def maxSumLCM(self, n):
		l = []
		m = []
		i = 1
		while i * i <= n:
			if n % i == 0:
				l.append(i)
				if n // i != i:
					l.append(n // i)
			i += 1
		return sum(l)


import math

class Solution:

	def maxSumLCM(self, n):
		h = 1
		a = set()
		while h * h <= n:
			if n % h == 0:
				a.add(h)
				a.add(n // h)
			h += 1
		return sum(a)


import math

class Solution:

	def maxSumLCM(self, n):
		ans = 0
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0 and n // i != i:
				ans += i + n // i
			elif n % i == 0 and n // i == i:
				ans += i
		return ans


class Solution:

	def maxSumLCM(self, n):
		ma = 0
		N = 1
		while N ** 2 <= n:
			if n % N == 0:
				ma += N
				if n != N ** 2:
					ma += n // N
			N += 1
		return ma


import math

class Solution:

	def maxSumLCM(self, n):
		i = 1
		s = set()
		ans = 0
		while i * i <= n:
			if n % i == 0:
				s.add(i)
				temp = n / i
				s.add(temp)
			i += 1
		for i in s:
			ans += i
		return int(ans)


class Solution:

	def maxSumLCM(self, n):
		j = 1
		a = set()
		while j * j <= n:
			if n % j == 0:
				a.add(j)
				a.add(n // j)
			j += 1
		return sum(a)


class Solution:

	def maxSumLCM(self, n):
		number_set = set()
		for i in range(1, int(n ** 0.5) + 1, 1):
			if n % i == 0:
				quot = n // i
				number_set.add(quot)
				number_set.add(i)
		return sum(number_set)


import math

class Solution:

	def maxSumLCM(self, n):
		a = int(int(int(n ** 0.5) ** 2 == n) * n ** 0.5)
		for i in range(1, math.ceil(n ** 0.5)):
			if not n % i:
				a += i + n // i
		return a