Given a number N, find the even factor sum of the number N.
 
Example 1:
Input: 
N = 30 
Output: 
48 
Explanation:
Even dividers sum 2 + 6 + 10 + 30 = 48
Example 2:
Input: 
N = 18 
Output: 
26 
Explanation:
Even dividers sum 2 + 6 + 18 = 26
Your Task:
You don't need to read input or print anything. Your task is to complete the function evenFactors() which takes an integer N as input parameters and returns an integer, number of even factors of N.
 
Expected Time Complexity: O(sqrt(N))
Expected Space Complexity: O(1)
 
Constraints:
1 <= N <= 10^{9}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

    def evenFactors (self, N):

        # code here

Solutions:
class Solution:

	def evenFactors(self, N):
		sum = 0
		for i in range(2, N + 1):
			if i % 2 == 0 and N % i == 0:
				sum = sum + i
		return sum


import math

class Solution:

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


class Solution:

	def evenFactors(self, N):
		i = 2
		s = 0
		while i <= N:
			if N % i == 0:
				s = s + i
			i = i + 2
		return s


import math

class Solution:

	def evenFactors(self, N):
		if N == 2:
			return 3
		(lim, s) = (int(math.sqrt(N)) + 1, 0)
		for i in range(1, lim):
			if N % i == 0:
				if i != N // i:
					if i % 2 == 0:
						s += i
					if N // i % 2 == 0:
						s += N // i
				elif i % 2 == 0:
					s += i
		return s


import math

class Solution:

	def evenFactors(self, N):
		s = 0
		if N == 2:
			return 3
		for i in range(1, int(math.sqrt(N)) + 1):
			if N % i == 0:
				if i % 2 == 0 and N // i % 2 == 0 and (i != N // i):
					s += i
					s += N // i
				elif i % 2 != 0 and N // i % 2 == 0:
					s += N // i
				elif i % 2 == 0 and N // i % 2 != 0:
					s += i
				elif i % 2 == 0 and i == N // i:
					s += i
				else:
					pass
		return s


class Solution:

	def evenFactors(self, N):
		if N == 2:
			return 3
		ans = 0
		for i in range(1, N + 1):
			if i & 1 == 0 and N % i == 0:
				ans += i
		return ans


class Solution:

	def evenFactors(self, N):
		if N == 2:
			return 3
		sum1 = 0
		for i in range(2, N + 1, 2):
			if N % i == 0:
				sum1 += i
		return sum1


class Solution:

	def evenFactors(self, N: int) -> int:
		from math import sqrt
		if N < 2:
			return 0
		if N == 2:
			return 3
		result = 0
		if N % 2 == 0:
			result += N
		for i in range(2, int(sqrt(N)) + 1):
			if N % i == 0:
				if i == N // i:
					if i % 2 == 0:
						result += i
				else:
					if N % (N // i) == 0:
						if N // i % 2 == 0:
							result += N // i
					if i % 2 == 0:
						result += i
		return result


class Solution:

	def evenFactors(self, N):
		if N == 2:
			return N + 1
		count = 0
		for i in range(2, N + 1, 2):
			if N % i == 0:
				count = count + i
		return count


class Solution:

	def evenFactors(self, N):
		if N == 2:
			return 3
		if N == 1:
			return 0
		sum = 0
		c = []
		for i in range(1, N):
			if N % i == 0:
				c.append(i)
		c = c + [N]
		for i in c:
			if i % 2 == 0:
				sum = sum + i
		return sum


from math import *

class Solution:

	def evenFactors(self, N):
		if N == 2:
			return 3
		s = 0
		a = int(sqrt(N))
		for i in range(1, a + 1):
			m = N // i
			if N % i == 0 or N % m == 0:
				if m % 2 == 0:
					s += m
				if i % 2 == 0:
					s += i
		if a * a == N and s != 0:
			return s - a
		return s


class Solution:

	def evenFactors(self, N):
		if N == 2:
			return 3
		if N == 1:
			return 0
		s = 0
		i = 2
		while i <= N:
			if N % i == 0:
				s += i
			i += 2
		return s
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.evenFactors(N))


import math

class Solution:

	def evenFactors(self, N):
		if N == 2:
			return 3
		res = 0
		for i in range(1, int(math.sqrt(N)) + 1):
			if N % i == 0:
				if i % 2 == 0:
					res += i
				if int(N / i) % 2 == 0 and int(N / i) != i:
					res += int(N / i)
		return res
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.evenFactors(N))


import math

class Solution:

	def evenFactors(self, N):
		if N == 2:
			return 3
		if N == 1:
			return 0
		l = []
		n = N
		s = math.sqrt(n)
		i = 1
		while i <= s:
			if n % i == 0:
				if n / i == i:
					l.append(i)
				else:
					l.append(i)
					l.append(int(n / i))
			i += 1
		x = 0
		for i in range(len(l)):
			if l[i] & 1 == 0:
				x += l[i]
		return x


class Solution:

	def evenFactors(self, N):
		sum = 0
		if N == 2:
			return 3
		for i in range(1, int(pow(N, 0.5)) + 1):
			if N % i == 0:
				if i == int(N / i) and i % 2 == 0:
					sum += i
				elif i != int(N / i):
					if i % 2 == 0 and int(N / i) % 2 != 0:
						sum += i
					if i % 2 != 0 and int(N / i) % 2 == 0:
						sum += int(N / i)
					if i % 2 == 0 and int(N / i) % 2 == 0:
						sum = sum + i + int(N / i)
		return sum