Given a natural number N, the task is to find the sum of the divisors of all the divisors of N.
Example 1:
Input:
N = 54
Output:
232
Explanation:
Divisors of 54 = 1, 2, 3, 6, 9, 18, 27, 54.
Sum of divisors of 1, 2, 3, 6, 9, 18, 27, 54 
are 1, 3, 4, 12, 13, 39, 40, 120 respectively.
Sum of divisors of all the divisors of 54
 = 1 + 3 + 4 + 12 + 13 + 39 + 40 + 120 = 232.
Example 2:
Input:
N = 10
Output:
28
Explanation:
Divisors of 10 are 1, 2, 5, 10
Sums of divisors of all the divisors are 
1, 3, 6, 18.
Overall sum = 1 + 3 + 6 + 18 = 28
Your Task:  
You don't need to read input or print anything. Your task is to complete the function sumOfDivisors() which takes an integer N as an input parameter and return the sum of the divisors of all the divisors of N.
Expected Time Complexity: O(NloglogN)
Expected Auxiliary Space: O(N)
Constraints:
1 <= N <= 10^{4}

Difficulty: EASY
Tags: Number theory

Mathematics
Expected Time Complexity: O(NloglogN)
Expected Auxiliary Space: O(N)

Starter code:
#User function Template for python3



class Solution:

    def sumOfDivisors(self, N):

    	#code here 

Solutions:
class Solution:

	def sumOfDivisors(self, N):
		c = 0
		for i in range(1, N + 1, 1):
			if N % i == 0:
				for j in range(1, i + 1, 1):
					if i % j == 0:
						c += j
		return c


class Solution:

	def sumOfDivisors(self, N):

		def d(x):
			c = 0
			for i in range(1, x + 1):
				if x % i == 0:
					c += i
			return c
		s = 0
		for i in range(1, N + 1):
			if N % i == 0:
				s += d(i)
		return s


class Solution:

	def divisor(self, n):
		t = n
		for i in range(1, n // 2 + 1):
			if n % i == 0:
				t += i
		return t

	def sumOfDivisors(self, N):
		k = N
		t = []
		for i in range(1, N // 2 + 1):
			if N % i == 0:
				t.append(i)
				k += i
		for i in t:
			k += self.divisor(i)
		return k


class Solution:

	def sumOfDivisors(self, N):
		sum = 0
		for i in range(1, N + 1):
			div_sum = 0
			if N % i == 0:
				for j in range(1, i + 1):
					if i % j == 0:
						div_sum += j
				sum = div_sum + sum
		return sum


class Solution:

	def sumOfDivisors(self, N):
		su_m = []
		for i in range(1, N + 1):
			if N % i == 0:
				for j in range(1, i + 1):
					if i % j == 0:
						su_m.append(j)
		return sum(su_m)


def sum1(n):
	sum1 = 0
	for i in range(1, n + 1):
		if n % i == 0:
			sum1 += i
	return sum1

class Solution:

	def sumOfDivisors(self, N):
		sum = 0
		for j in range(1, N + 1):
			if N % j == 0:
				sum += sum1(j)
		return sum


class Solution:

	def sumOfDivisors(self, N):
		if N == 1:
			return 1
		c = 0

		def sumdiv(n):
			c = 0
			for i in range(1, int(n ** 0.5) + 1):
				if n % i == 0:
					if n // i == i:
						c += i
					else:
						c += i
						c += n // i
			return c
		for i in range(1, int(N ** 0.5) + 1):
			if N % i == 0:
				if N // i == i:
					c += sumdiv(i)
				else:
					c += sumdiv(i)
					c += sumdiv(N // i)
		return c


def div(n):
	c = 0
	for i in range(1, n + 1):
		if n % i == 0:
			c = c + i
	return c

class Solution:

	def sumOfDivisors(self, N):
		l = []
		c = 0
		for i in range(1, N + 1):
			if N % i == 0:
				l.append(i)
		for i in l:
			c = c + div(i)
		return c


class Solution:

	def sumOfDivisors(self, N):

		def divisor(n):
			sum = 0
			for i in range(1, n + 1):
				if n % i == 0:
					sum += i
			return sum
		r = N
		a = []
		for i in range(1, N // 2 + 1):
			if N % i == 0:
				a.append(i)
				r += i
		for i in a:
			r += divisor(i)
		return r


class Solution:

	def sumOfDivisors(self, N):

		def sod(n):
			s = 1
			for i in range(2, n // 2 + 1):
				if not n % i:
					s += i
			s += n
			return s
		S = 1
		for i in range(2, N // 2 + 1):
			if not N % i:
				S += sod(i)
		S += sod(N)
		return S


def div(n):
	s = 0
	for i in range(1, n + 1):
		if n % i == 0:
			s += i
	return s

class Solution:

	def sumOfDivisors(self, n):
		s = 0
		for i in range(1, n + 1):
			if n % i == 0:
				s += div(i)
		return s


class Solution:

	def sumOfDivisors(self, N):
		k = int(N ** 0.5)
		m = {}
		for i in range(1, k + 1):
			if N % i == 0:
				m[i] = 1
				m[N // i] = 1
		su = 0
		for i in m:
			k = int(i ** 0.5)
			s = {}
			for j in range(1, k + 1):
				if i % j == 0:
					s[j] = 1
					s[i // j] = 1
			su += sum(s)
		return su


class Solution:

	def sumOfDivisors(self, N):

		def sure(n):
			s = 1 + n
			for i in range(2, n // 2 + 1):
				if n % i == 0:
					s += i
			return s
		l = []
		res = 2
		for i in range(2, N + 1):
			if N % i == 0:
				l.append(i)
		res += sum(l)
		for i in range(len(l) - 1):
			res += sure(l[i])
		return res


class Solution:

	def sumOfDivisors(self, N):
		r = []
		k = 0
		for i in range(1, N + 1):
			if N % i == 0:
				for j in range(1, i + 1):
					if i % j == 0:
						k = k + j
		return k


class Solution:

	def sumOfDivisors(self, N):
		x = []
		for i in range(1, N + 1):
			if N % i == 0:
				x.append(i)
		count = 0
		for i in x:
			for j in range(1, i + 1):
				if i % j == 0:
					count += j
		return count


class Solution:

	def sumOfDivisors(self, N):
		sum = 0
		for i in range(1, N + 1):
			if N % i == 0:
				for j in range(1, i + 1):
					if i % j == 0:
						sum += j
		return sum
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.sumOfDivisors(N)
		print(ans)


class Solution:

	def divisor(self, n):
		t = n
		for i in range(1, n // 2 + 1):
			if n % i == 0:
				t += i
		return t

	def sumOfDivisors(self, N):
		k = N
		t = []
		for i in range(1, N // 2 + 1):
			if N % i == 0:
				t.append(i)
				k += i
		for i in t:
			k += self.divisor(i)
		return k
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.sumOfDivisors(N)
		print(ans)


class Solution:

	def sumOfDivisors(self, n):
		s1 = []
		for i in range(1, n // 2 + 1):
			if n % i == 0:
				s1.append(i)
		s1.append(n)
		su = 0
		su = 0
		for i in s1:
			j = 1
			while j <= i // 2:
				if i % j == 0:
					su = su + j
				j += 1
			su += i
		return su
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.sumOfDivisors(N)
		print(ans)


class Solution:

	def sumOfDivisors(self, N):

		def div(x):
			sum1 = 0
			for i in range(1, x + 1):
				if x % i == 0:
					sum1 = sum1 + i
			return sum1
		sum = 0
		for i in range(1, N + 1):
			if N % i == 0:
				sum = sum + div(i)
		return sum


class Solution:

	def sumOfDivisors(self, N):
		s = 0
		l = []
		for i in range(1, N + 1):
			if N % i == 0:
				l.append(i)
		for i in l:
			for j in range(1, i + 1):
				if i % j == 0:
					s = s + j
		return s


class Solution:

	def sumOfDivisors(self, N):
		c = 1
		import math
		a = int(math.sqrt(N))
		d = []
		for i in range(1, a + 1):
			if N % i == 0:
				if i * i == N:
					d.append(i)
					continue
				d.append(i)
				d.append(N // i)
		for i in d:
			sum = 0
			if i == 1:
				continue
			b = int(math.sqrt(i))
			for j in range(1, b + 1):
				if j * j == i:
					sum = sum + j
					break
				if i % j == 0:
					sum = sum + j + i // j
			c = c + sum
		return c


class Solution:

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


class Solution:

	def sumOfDivisors(self, n):
		r = 0
		ans = 0
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				k = i
				ans = 1
				for j in range(2, int(i ** 0.5) + 1):
					if k % j == 0:
						c = 0
						while k % j == 0:
							k = k // j
							c += 1
						ans *= (j ** (c + 1) - 1) // (j - 1)
				if k > 1:
					ans *= (k ** 2 - 1) // (k - 1)
				ans1 = 0
				if n // i != i:
					ans1 = 1
					k = n // i
					for j in range(2, int(k ** 0.5) + 1):
						if k % j == 0:
							c = 0
							while k % j == 0:
								k = k // j
								c += 1
							ans1 *= (j ** (c + 1) - 1) // (j - 1)
				if k > 1:
					ans1 *= (k ** 2 - 1) // (k - 1)
				r += ans + ans1
		return r


class Solution:

	def sumOfDivisors(self, N):
		s = 0
		f = []
		g = []
		for i in range(1, N + 1):
			if N % i == 0:
				f.append(i)
		for j in f:
			for k in range(1, i + 1):
				if j % k == 0:
					g.append(k)
		return sum(g)


class Solution:

	def sumOfDivisors(self, N):
		i = 1
		sum = 0
		while i <= N:
			if N % i == 0:
				j = 1
				while j <= i:
					if i % j == 0:
						sum += j
					j += 1
			i += 1
		return sum


class Solution:

	def sumOfDivisors(self, N):
		list = []
		for i in range(1, N + 1):
			if N % i == 0:
				list.append(i)
			else:
				pass
		sum = 0
		for j in list:
			for k in range(1, j + 1):
				if j % k == 0:
					sum += k
				else:
					pass
		return sum


class Solution:

	def sumOfDivisors(self, N):
		s = 0
		for i in range(2, N + 1):
			if N % i == 0:
				for j in range(1, i + 1):
					if i % j == 0:
						s += j
		return s + 1


class Solution:

	def sumOfDivisors(self, N):

		def part(m):
			s = 0
			for i in range(1, m + 1):
				if m % i == 0:
					s = s + i
			return s
		t = 0
		for i in range(1, N + 1):
			if N % i == 0:
				t = t + part(i)
		return t


import math

class Solution:

	def sumOfDivisors(self, n):
		sum1 = 0
		for i in range(1, n + 1):
			if n % i == 0:
				for j in range(1, i + 1):
					if i % j == 0:
						sum1 += j
		return sum1


from math import sqrt

class Solution:

	def divisiorsSum(self, N):
		lim = int(sqrt(N)) + 1
		sum_d = 1 + N
		for i in range(2, lim):
			if N % i == 0:
				sum_d += i
				if N % (N // i) == 0 and N // i != i:
					sum_d += N // i
		return sum_d

	def sumOfDivisors(self, N):
		lim = int(sqrt(N)) + 1
		sum_d = 1 + self.divisiorsSum(N)
		for i in range(2, lim):
			if N % i == 0:
				sum_d += self.divisiorsSum(i)
				if N % (N // i) == 0 and N // i != i:
					sum_d += self.divisiorsSum(N // i)
		return sum_d


from math import ceil

class Solution:

	def sumOfDivisors(self, n):
		su = 0
		for i in range(1, n + 1):
			temp = 0
			if n % i == 0:
				for j in range(1, i + 1):
					if i % j == 0:
						temp += j
				su += temp
		return su


class Solution:

	def sumOfDivisors(self, N):
		s = Solution.divisor(N) + 1
		for i in range(2, N // 2 + 1):
			if N % i == 0:
				s += Solution.divisor(i)
		return s

	@staticmethod
	def divisor(n):
		s = n
		for i in range(1, n // 2 + 1):
			if n % i == 0:
				s += i
		return s


class Solution:

	def sumOfDivisors(self, N):
		divisors = []
		for i in range(1, N + 1):
			if N % i == 0:
				divisors.append(i)
		divisorsOfDivisors = []
		for i in range(len(divisors)):
			for j in range(1, divisors[i] + 1):
				if divisors[i] % j == 0:
					divisorsOfDivisors.append(j)
		return sum(divisorsOfDivisors)


class Solution:

	def sumOfDivisors(self, N):
		div = []
		for i in range(1, N // 2 + 1):
			if N % i == 0:
				div.append(i)
		div.append(N)
		sumi = 0
		for i in div:
			for j in range(1, i + 1):
				if i % j == 0:
					sumi += j
		return sumi


class Solution:

	def sumOfDivisors(self, N):
		new_list = []
		my_sum = 0
		for i in range(1, N + 1):
			if N % i == 0:
				for k in range(1, i + 1):
					if i % k == 0:
						my_sum += k
		return my_sum


class Solution:

	def sumOfDivisors(self, N):
		l = []
		t = []
		for i in range(1, N + 1):
			if N % i == 0:
				l.append(i)
		for i in l:
			for k in range(1, i + 1):
				if i % k == 0:
					t.append(k)
		return sum(t)