Given a number N.Find the minimum sum of its factors.
Example 1:
Input:
N=10
Output:
7
Explanation:
There are two ways to factories N, which are
10=1*10(sum=10+1=11)
10=2*5(sum=2+5=7)
Thus, the answer is 7.
Example 2:
Input:
N=12
Output:
7
Explanation:
There are  ways to factorise N, which are
12=12*1(sum=12+1=13)
12=3*4(sum=3+4=7)
12=6*2(sum=6+2=8)
12=2*3*2(sum=2+3+2=7).
Your Task:
You don't need to read input or print anything. Your task is to complete the function sumOfFactors() which takes a number N as an input parameter and returns the minimum sum of its factors.
Expected Time Complexity:O(N^{1/2})
Expected Auxillary Space:O(1)
Constraints:
1<=N<=10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:      

    def sumOfFactors(self,N):

        #code here

Solutions:
class Solution:

	def sumOfFactors(self, N):
		if N <= 2:
			return 1
		p = N
		k = int(N ** 0.5)
		s = 0
		for i in range(2, k + 1):
			while N % i == 0:
				s += i
				N = N // i
		if s == 0:
			return p + 1
		if N != 1:
			return s + N
		return s


def isprime(n):
	for i in range(2, n):
		if n % i == 0:
			return False
	return True

class Solution:

	def sumOfFactors(self, N):
		total = 0
		num = N
		if N <= 2:
			return 1
		i = 2
		while i * i <= num:
			while num % i == 0:
				total += i
				num //= i
			i += 1
		if num == N:
			total += 1 + num
		elif num > 1:
			total += num
		return total


class Solution:

	def sumOfFactors(self, N):
		s = 0
		x = N
		if N <= 2:
			return 1
		i = 2
		while i * i <= x:
			while x % i == 0:
				s += i
				x //= i
			i += 1
		if x == N:
			s += 1 + x
		elif x > 1:
			s += x
		return s
import math
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.sumOfFactors(N)
		print(ans)


def isprime(n):
	for i in range(2, n):
		if n % i == 0:
			return False
	return True

class Solution:

	def sumOfFactors(self, N):
		total = 0
		num = N
		if N <= 2:
			return 1
		i = 2
		while i * i <= num:
			while num % i == 0:
				total += i
				num //= i
			i += 1
		if num == N:
			total += 1 + num
		elif num > 1:
			total += num
		return total
import math
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.sumOfFactors(N)
		print(ans)


class Solution:

	def sumOfFactors(self, num):
		original = num
		primeSum = 0
		if num == 1:
			return 1
		if num == 2:
			return 1
		if num == 4:
			return 4
		i = 2
		while i * i <= num:
			while num % i == 0:
				primeSum += i
				num //= i
			i += 1
		primeSum += num if num != 1 else 0
		return primeSum + 1 if primeSum == original else primeSum


import math

class Solution:

	def sumOfFactors(self, N):
		total = 0
		num = N
		if N <= 2:
			return 1
		i = 2
		while i * i <= num:
			while num % i == 0:
				total += i
				num //= i
			i += 1
		if num == N:
			total += 1 + num
		elif num > 1:
			total += num
		return total