four-square-2

Rahul has recently been obsessed with mathematics, and spends most of his time reading the research notes of his equally eccentric math professor. On one of the pages of the research notes, Rahul finds a scribble that says, " the number of ways to represent a number as sum of four squares would be the ultimate answer to Life, the Universe and Everything", now since he doesn't have enough time to calculate this for all the numbers, he asks your help. 
Given a number N, your task is to print the number of ways it can be represented as sum of four squares.

Input:
First line contains number of test cases T. Next T lines contains a single number N.

Output: 
For each test case print number of ways a given N can be represented as the sum of four squares

Constraints:
1 ≤ T ≤ 1000
1 ≤ N ≤ 10^10

SAMPLE INPUT
4
1
2
3
4

SAMPLE OUTPUT
8
24
32
24

Explanation

Example for n=1 there are eight ways to represent one as sum of four squares
1^2 + 0^2 + 0^2 + 0^2
0^2 + 1^2 + 0^2 + 0^2   
0^2 + 0^2 +1^2 + 0^2
0^2 + 0^2 +0^2 + 1^2
(-1)^2 + 0^2 + 0^2 + 0^2
0^2 + (-1)^2 + 0^2 + 0^2
0^2 + 0^2 + (-1)^2 + 0^2 
0^2 + 0^2 + 0^2 + (-1)^2

Source: hackerearth | Difficulty: EASY
Tags: Number theory

Mathematics


Solutions:
'''
Created by anirudhmenon on 13/03/16
https://www.hackerearth.com/problem/algorithm/four-square-2/

Uses jacobis method
Wikipedia link: https://en.wikipedia.org/wiki/Jacobi%27s_four-square_theorem
'''

import math


def evenJacobi(number):
	# 24 times sum of odd divisors
	divisor = getAllDivisors(number)
	answer = sum(divisor)

	print(answer*24)



def oddJacobi(number):
	# 8 times sum of odd divisors
	divisor = getAllDivisors(number)
	answer = sum(divisor)

	print(8*answer)



def getAllDivisors(number):
	sqRoot = int(math.sqrt(number))
	divisors = []

	# Iterate through all the divisors and append odd number to the list
	for i in range(1, sqRoot + 1):
		if n%i == 0:
			if(i%2 != 0):
				divisors.append(i)
			newDivisor = n/i
			if i != newDivisor and newDivisor%2!=0:
				divisors.append(n/i)

	return divisors



def jacobiTheorem(number):
	if number%2 == 0:
		evenJacobi(number)
	else:
		oddJacobi(number)



# Enter number of test cases
t = int(input())

while t > 0:
	# Enter number
	n = int(eval(input()))
	jacobiTheorem(n)
	t = t - 1


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
import math
def div(n):
	sum=0
	for i in range(1,int(math.sqrt(n))+1):
		if n%i == 0:
			if i*i == n and i%4!=0:
				sum = sum+i
				break
			if i%4 !=0:
				sum = sum+i
			if (n/i)%4!=0:
				sum = sum+(n/i)
	return sum
	
	
t=eval(input())
while t>0:
	t-=1
	x=eval(input())

	print(8*div(x))



'''
Jacobi Four Sqaure Theorem
https://en.wikipedia.org/wiki/Jacobi%27s_four-square_theorem

The number of ways to represent n as the sum of four squares is eight times the sum of the divisors of n if n is odd and 24 times the sum of the odd divisors of n if n is even

'''
import math

def jacobiFourSquare(n):
	if (n % 2 == 0) :
		print(evenJFS(n))
	else :
		print(oddJFS(n))
	return

def evenJFS(n):
	#  24 times the sum of the odd divisors of n
	# print allDivisors(n)
	allDivisor = allDivisors(n)
	oddDivisors = []
	for i in allDivisor :
		if (i % 2 != 0) :
			oddDivisors.append(i)
	# print oddDivisors
	return 24 * sum(oddDivisors)
	
def oddJFS(n):
	# eight times the sum of the divisors of n 
	return 8 * sum(allDivisors(n))

	
def allDivisors(n) :
	
	divisors = []
	sqrt = int(math.sqrt( n ))
	for i in range(1, sqrt + 1) :	
		if (n % i == 0) :
			divisors.append(i)
			divisors.append(n // i)
	return list(set(divisors))
	

t = int(eval(input()))

while(t):
	val = int(eval(input()))
	
	jacobiFourSquare(val)
	t= t - 1