In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.

For example, for n = 4 the sum is equal to  - 1 - 2 + 3 - 4 =  - 4, because 1, 2 and 4 are 2^0, 2^1 and 2^2 respectively.

Calculate the answer for t values of n.


-----Input-----

The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed.

Each of next t lines contains a single integer n (1 ≤ n ≤ 10^9).


-----Output-----

Print the requested sum for each of t integers n given in the input.


-----Examples-----
Input
2
4
1000000000

Output
-4
499999998352516354



-----Note-----

The answer for the first sample is explained in the statement.

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
t = int(input())
for i in range(t):
	n = int(input())
	ans = n * (1 + n) // 2
	j = 0
	while 2 ** j <= n:
		ans -= 2 ** j * 2
		j += 1
	print(ans)


t = int(input())
for i in range(t):
	sum = 0
	x = int(input())
	sum = x * (x + 1) // 2
	binnum = ''
	for i in range(len(bin(x)) - 2):
		binnum = binnum + '1'
	sum = sum - int(binnum, 2) * 2
	print(int(sum))


n = int(input())
for i in range(n):
	m = int(input())
	a = m * (m + 1) // 2
	b = 1
	while b <= m:
		a = a - 2 * b
		b = b * 2
	print(a)


n = int(input())
res = []
for i in range(n):
	c = int(input())
	a = c * (c + 1) // 2
	b = 1
	while b <= c:
		a = a - b * 2
		b = b * 2
	res.append(a)
for i in res:
	print(i)


t = int(input())
for rr in range(t):
	n = int(input())
	sum = n * (n + 1) // 2
	p = 1
	while p <= n:
		sum -= 2 * p
		p = p * 2
	print(int(sum))


t = int(input())
for i in range(t):
	n = int(input())
	result = n * (n + 1) // 2
	j = 1
	while j <= n:
		result -= 2 * j
		j *= 2
	print(result)


from math import *
t = int(input())
for i in range(t):
	n = int(input())
	max1 = int(log(n, 2)) + 1
	w = n * (n + 1) // 2
	p = w - 2 * ((1 << max1) - 1)
	print(int(p))


t = int(input())
arr_n = []
for i in range(0, t):
	arr_n.append(int(input()))
i = 0
while i < t:
	example = 1
	result_2 = 0
	result = arr_n[i] * (arr_n[i] + 1) // 2
	while example <= arr_n[i]:
		result_2 += example
		example = example * 2
	print(int(result - result_2 * 2))
	i += 1


for _ in range(int(input())):
	N = int(input())
	Sum = N * (N + 1) // 2
	i = 0
	while 2 ** i <= N:
		Sum -= 2 ** (i + 1)
		i += 1
	print(Sum)


n = int(input())
powers_of_two = list()
i = 0
while 2 ** i < 10 ** 9:
	powers_of_two.append(2 ** i)
	i += 1
for _ in range(n):
	t = int(input())
	s = t * (t + 1) // 2
	for power in powers_of_two:
		if power > t:
			break
		s -= 2 * power
	print(s)


countTests = int(input())
for _ in range(countTests):
	numbers = int(input())
	stepen2 = 1
	summa = int(numbers * (numbers + 1) // 2)
	while stepen2 <= numbers:
		summa -= stepen2 * 2
		stepen2 *= 2
	print(summa)


for _ in range(int(input())):
	n = int(input())
	nc = n
	i = 0
	while nc > 0:
		nc = nc >> 1
		i += 1
	ans = (n * n + n) // 2
	ans -= 2 * ((1 << i) - 1)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = n * (n + 1) // 2
	p = 1
	s2 = 0
	while p <= n:
		s -= p
		s2 -= p
		p = p * 2
	print(s2 + s)


import statistics
import math
import datetime
import collections

def identity(*args):
	if len(args) == 1:
		return args[0]
	return args

def parsin(*, l=1, vpl=1, cf=identity, s=' '):
	if l == 1:
		if vpl == 1:
			return cf(input())
		else:
			return list(map(cf, input().split(s)))
	elif vpl == 1:
		return [cf(input()) for _ in range(l)]
	else:
		return [list(map(cf, input().split(s))) for _ in range(l)]

def main():
	for _ in range(int(input())):
		n = int(input())
		print(n * (n + 1) // 2 - 2 * ((1 << n.bit_length()) - 1))
main()


t = int(input())
for i in range(t):
	n = int(input())
	s = n * (n + 1) // 2
	x = 1
	while x <= n:
		s = s - 2 * x
		x *= 2
	print(s)


import math
t = int(input())
for x in range(t):
	n = int(input())
	print(n * (n + 1) // 2 - 2 * (2 ** (int(math.log2(n) // math.log2(2)) + 1) - 1))


array = []
t = int(input())
for x in range(t):
	n = int(input(''))
	potencia = 1
	s = 0
	while potencia <= n:
		s = s - potencia * 2
		potencia = potencia * 2
		soma = n * (n + 1) // 2
		resultado = s + soma
	array.append(resultado)
for i in range(t):
	print(array[i])


for i in range(int(input())):
	a = int(input())
	print(a * (a + 1) // 2 - int(bin(a)[2:].replace('0', '1') + '0', 2))


def translation():
	word_1 = input()
	word_2 = input()[::-1]
	print(['NO', 'YES'][word_1 == word_2])
	return

def anton_and_danik():
	games = int(input())
	wins = input()
	anton_wins = sum((i == 'A' for i in wins))
	if anton_wins * 2 > len(wins):
		print('Anton')
	elif anton_wins * 2 == len(wins):
		print('Friendship')
	else:
		print('Danik')
	return

def acoomodation():
	cnt = 0
	for _ in range(int(input())):
		(p, q) = map(int, input().split())
		if q - p >= 2:
			cnt += 1
	print(cnt)
	return

def juicer():
	(n, b, d) = map(int, input().split())
	sum_orange = 0
	cnt_empty = 0
	for orange in list(map(int, input().split())):
		if orange <= b:
			sum_orange += orange
			if sum_orange > d:
				cnt_empty += 1
				sum_orange = 0
	print(cnt_empty)
	return

def digit_game():
	for game in range(int(input())):
		breach_odd_cnt = 0
		breach_even_cnt = 0
		raze_odd_cnt = 0
		raze_even_cnt = 0
		n = int(input())
		number = input()
		breach_numbers = ''
		raze_numbers = ''
		len_number = len(number)
		idx = 1
		for digit in number:
			if idx % 2 == 0:
				breach_numbers += digit
				if digit in '13579':
					breach_odd_cnt += 1
				else:
					breach_even_cnt += 1
			else:
				raze_numbers += digit
				if digit in '13579':
					raze_odd_cnt += 1
				else:
					raze_even_cnt += 1
			idx += 1
		if len_number == 1:
			if int(number) % 2 == 0:
				print(2)
			else:
				print(1)
		elif len_number % 2 == 0:
			if breach_even_cnt >= 1:
				print(2)
			else:
				print(1)
		elif raze_odd_cnt >= 1:
			print(1)
		else:
			print(2)
	return

def modular_exponentiation():
	n = int(input())
	m = int(input())
	calc = m % int(1 << n)
	print(int(calc))
	return

def tricky_sum():
	for _ in range(int(input())):
		number = int(input())
		pow_two = 1
		while pow_two <= number:
			pow_two *= 2
		sum_formula = number * (number + 1) // 2
		trick_sum = sum_formula - 2 * pow_two + 2
		print(trick_sum)
	return
tricky_sum()


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	ans = (n + 1) * n // 2
	msk = 1
	while msk <= n:
		ans -= 2 * msk
		msk *= 2
	print(ans)


from math import log
cnt = int(input())
for i in range(cnt):
	n = int(input())
	sm = n * (n + 1) // 2
	t2l = int(log(n, 2))
	sm_2 = 2 ** (t2l + 1) - 1
	print(sm - 2 * sm_2)


t = input()
t = int(t)
while t > 0:
	s = 0
	t -= 1
	n = input()
	n = int(n)
	for i in range(0, 64):
		d = pow(2, i)
		if d <= n:
			s += d
		else:
			break
	sum = n * (n + 1) // 2
	sum -= 2 * s
	print(sum)


import math
t = int(input())
while t > 0:
	n = int(input())
	total = n * (n + 1) // 2
	twos = int(math.log(n, 2))
	minus = 0
	for i in range(0, twos + 1):
		minus += 2 ** i
	minus *= 2
	float(minus)
	ans = total - minus
	print(int(ans))
	ans = 0
	t -= 1


for i in range(int(input())):
	n = int(input())
	s = n * (n + 1) // 2
	p = 1
	while p <= n:
		s -= 2 * p
		p *= 2
	print(s)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	N = int(input())
	x = 0
	while pow(2, x + 1) <= N:
		x += 1
	print(N * (N + 1) // 2 - (pow(2, x + 2) - 2))


def imprime(n):
	b = format(n, 'b')
	m = len(b)
	print(int((1 + n) * n // 2 - (2 ** m - 1) * 2))
t = int(input())
n = [0] * t
for i in range(t):
	n[i] = int(input())
for i in range(t):
	imprime(n[i])


t = int(input())
ss = []
for i in range(t):
	n = int(input())
	s = n * (n + 1) // 2
	l = n
	exp = 0
	while l:
		l //= 2
		exp += 1
	s = s - 2 * (2 ** exp - 1)
	ss.append(s)
for s in ss:
	print(s)


import math
t = int(input())
for i in range(t):
	n = int(input())
	k = int(math.log(n) / math.log(2))
	print(n * (n + 1) // 2 - 2 ** (k + 2) + 2)


n = int(input())

def getPower2Sum(x):
	res = 1
	while x != 0:
		x >>= 1
		res <<= 1
	return res - 1
for i in range(n):
	x = int(input())
	print((x * (x + 1) >> 1) - 2 * getPower2Sum(x))


for i in range(int(input())):
	n = int(input())
	print(n * (n + 1) // 2 - ((1 << n.bit_length()) - 1) * 2)


T = int(input())
for t in range(T):
	N = int(input())
	ans = N * (N + 1) // 2
	k = 0
	while pow(2, k) <= N:
		ans -= 2 * pow(2, k)
		k += 1
	print(ans)


n = int(input())
for i in range(n):
	index = 0
	num = int(input())
	ori = (1 + num) * num // 2
	while 2 ** index <= num:
		index = index + 1
	print(ori - 2 * (2 ** index - 1))


t = int(input())
for _ in range(t):
	n = int(input())
	p = len(str(bin(n))) - 3
	total = 0
	while n >= 1:
		low = 2 ** p
		total += (low + 1 + n) * (n - low) // 2 - low
		n = low - 1
		p = p - 1
	print(int(total))


from math import log2
t = int(input())
l = []
while t != 0:
	n = int(input())
	s = n * (n + 1) // 2
	r = int(log2(n))
	expsum = 2 ** (r + 1) - 1
	l.append(int(s - 2 * expsum))
	t -= 1
for i in l:
	print(i)


from math import log
t = int(input())
for _ in range(t):
	n = int(input())
	k = int(log(n) / log(2)) + 1
	print(n * (n + 1) // 2 - 2 * 2 ** k + 2)


def degree_two(y):
	z = 1
	while z <= y:
		z *= 2
	return z
t = int(input())
ns = []
for x in range(t):
	ns.append(int(input()))
for n in ns:
	print(n * (n + 1) // 2 - 2 * (degree_two(n) - 1))


t = int(input())
ans = 0
a = [1]
(k, j) = (2, 1)
while k ** j < 10 ** 10:
	a.append(k ** j)
	j += 1
for i in range(t):
	x = int(input())
	ans = ((x + 1) ** 2 - (x + 1)) // 2
	n = 0
	while a[n] <= x:
		n += 1
	print(ans - 2 * sum(a[:n]))


n = int(input())
for i in range(n):
	k = 1
	m = int(input())
	while k <= m:
		k = k * 2
	print(m * (m + 1) // 2 - (k - 1) * 2)


import math
for i in range(int(input())):
	n = int(input())
	s = n * (n + 1) // 2
	l = [2 ** i for i in range(math.floor(math.log(n, 2)) + 1)]
	print(s - 2 * sum(l))


x = int(input())
for i in range(x):
	t = input()
	r1 = int(t)
	i = 1
	while True:
		t1 = pow(2, i)
		if r1 % t1 == r1:
			r = i - 1
			break
		i = i + 1
	print(r1 * (r1 + 1) // 2 - 2 * pow(2, r + 1) + 2)


from math import log2
for i in range(int(input())):
	n = int(input())
	print((n * n + n) // 2 - 2 * (2 ** (int(log2(n)) + 1) - 1))


t = int(input())
for test in range(t):
	n = int(input())
	s = 1
	a = 1
	i = 0
	while a * 2 <= n:
		a = a * 2
		s += a
	print(int(n * (n + 1) // 2) - s - s)


def tsum(n) -> int:
	p = 0
	while n >= 2 ** p:
		p += 1
	p += 1
	sum = 2 - 2 ** p
	if n % 2 == 0:
		x = int(n / 2)
		x *= n + 1
	else:
		x = int((n + 1) / 2)
		x *= n
	sum += x
	return int(sum)
t = input()
for i in range(int(t)):
	n = input()
	print(tsum(int(n)))


n = int(input())
list_ = [int(input()) for _ in range(n)]
for i in list_:
	idx = 0
	sum_power_2 = 0
	total_sum = i * (i + 1) // 2
	while 2 ** idx <= i:
		sum_power_2 += 2 ** idx
		idx += 1
	print(total_sum - sum_power_2 - sum_power_2)


for _ in range(int(input())):
	n = int(input())
	sum1 = i = 1
	while i < n:
		i *= 2
		sum1 += i
	if i == n:
		print(n * (n + 1) // 2 - sum1 * 2)
	else:
		print(n * (n + 1) // 2 - sum1 * 2 + i * 2)


f = lambda x: x * (x + 1) // 2 - 2 * (2 ** (len(bin(x)) - 2) - 1)
for i in range(int(input())):
	print(int(f(int(input()))))


for _ in ' ' * int(input()):
	a = int(input())

	def gh(a):
		if a == 1:
			return 1
		else:
			return 1 + gh(a // 2)
	print(-2 * (2 ** gh(a) - 1) + (a + 1) * a // 2)


for _ in [0] * int(input()):
	n = int(input())
	sum = (1 + n) * n // 2
	sum -= 2 * (2 ** (len(bin(n)) - 2) - 1)
	print(sum)


for _ in range(int(input())):
	n = int(input())
	x = n * (n + 1) // 2
	k = 0
	while 2 ** k <= n:
		if 2 ** k <= n:
			x -= 2 * 2 ** k
		k += 1
	print(x)


import math
n = int(input())
values = []
for x in range(n):
	a = int(input())
	b = 2 ** (int(math.log(a, 2)) + 1) - 1
	c = a * (a + 1) // 2
	values.append(c - b * 2)
for x in values:
	print(x)


def cal_sum(k):
	re = (1 + k) * k // 2
	i = 0
	while True:
		if 2 ** i > k:
			break
		i += 1
	return re - 2 * (2 ** i - 1)
num = int(input())
for i in range(num):
	print(cal_sum(int(input())))


T_ON = 1
DEBUG_ON = 1
MOD = 998244353

def solve():
	n = read_int()
	k = 0
	while 2 ** k <= n:
		k += 1
	print(n * (n + 1) // 2 - 2 * (2 ** k - 1))

def main():
	T = read_int() if T_ON else 1
	for i in range(T):
		solve()

def debug(*xargs):
	if DEBUG_ON:
		print(*xargs)
from collections import *
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def read_int():
	return int(input())

def read_ints():
	return list(map(int, input().split()))

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def First():
	print('First')

def Second():
	print('Second')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

def fib_to_n(n):
	f = []
	(a, b) = (0, 1)
	while a <= n:
		f.append(a)
		(a, b) = (b, a + b)
	return f

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def lcm(a, b):
	d = gcd(a, b)
	return a * b // d

def is_even(x):
	return x % 2 == 0

def is_odd(x):
	return x % 2 == 1

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))

def is_prime(n):
	if n == 1:
		return False
	for i in range(2, int(n ** 0.5) + 1):
		if n % i:
			return False
	return True

def gen_primes(n):
	P = [True for _ in range(n + 1)]
	P[0] = P[1] = False
	for i in range(int(n ** 0.5) + 1):
		if P[i]:
			for j in range(2 * i, n + 1, i):
				P[j] = False
	return P

def is_lucky(n):
	return set(list(str(n))).issubset({'4', '7'})
main()


import math
n = int(input())
for i in range(n):
	x = int(input())
	sum = (x * x + x) // 2
	l = int(math.log(x, 2))
	sum -= 2 * 2 ** (l + 1)
	print(sum + 2)


for _ in range(int(input())):
	N = int(input())
	ans = N * (N + 1) // 2
	i = 1
	while i <= N:
		ans -= 2 * i
		i <<= 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = n * (n + 1) // 2
	i = 0
	while 2 ** i <= n:
		s -= 2 ** (i + 1)
		i += 1
	print(s)


import math
num_testcases = int(input())
for _ in range(num_testcases):
	n = int(input())
	sum = n * (n + 1) // 2
	two = 1
	while two <= n:
		two *= 2
	sum -= (two - 1) * 2
	print(sum)
pass


t = int(input())
while t:
	n = int(input())
	t -= 1
	s = n * (n + 1) // 2
	p = 1
	while p <= n:
		s -= 2 * p
		p <<= 1
	print(s)


m = int(input())
arr = []
for i in range(m):
	n = int(input())
	s = n * (n + 1) // 2
	two = 1
	while two <= n:
		s -= two * 2
		two *= 2
	arr.append(s)
for i in range(m):
	print(arr[i])


tests = int(input())
for _ in range(tests):
	n = int(input())
	total = n * (n + 1) // 2
	i = 1
	res = 1
	while 2 ** i <= n:
		res += 2 ** i
		i += 1
	print(total - 2 * res)


k = int(input())
for _ in range(k):
	n = int(input())
	s = n * (n + 1) // 2
	p = 1
	while p <= n:
		s -= 2 * p
		p *= 2
	print(s)


import math
t = int(input())
for i in range(t):
	n = int(input())
	print(int(n * (n + 1) // 2) - 2 * (int(pow(2, int(math.floor(math.log(n, 2))) + 1)) - 1))


import math

def highestPowerof2(n):
	p = int(math.log(n, 2))
	return p
t = int(input())
while t > 0:
	n = int(input())
	if n % 2 == 0:
		s = int(n / 2) * (n + 1)
	else:
		s = n * int((n + 1) / 2)
	s = s - 2
	p = highestPowerof2(n)
	s1 = 4 * (pow(2, p) - 1)
	print(s - s1)
	t = t - 1


from math import log
p = int(input())
for n in range(p):
	x = int(input())
	n = int(log(x) / log(2))
	k = 2 ** (n + 1) - 1
	m = (x + x ** 2) // 2 - 2 * k
	print(m)


def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
for i in range(ii()):
	n = ii()
	s = bin(n)[2:]
	n1 = len(s)
	s = 0
	for i in range(n1):
		s += pow(2, i)
	print(n * (n + 1) // 2 - 2 * s)


for i in range(int(input())):
	n = int(input())
	(k, p) = (1, 0)
	while k <= n:
		p += 1
		k *= 2
	print(n * (n + 1) // 2 - 2 * (k - 1))


import math
t = int(input())
for i in range(t):
	s = 0
	n = int(input())
	p = int(math.log(n, 2))
	for j in range(p + 1):
		s += pow(2, j)
		k = n * (n + 1) // 2
	print(k - 2 * s)


from sys import stdin, stdout

def trace(f):

	def traced(*args, **kw):
		print('calling {} with args {}, {}'.format(f.__name__, args, kw))
		return f(*args, **kw)
	return traced

def f(x):
	print(x)

def read():
	return stdin.readline()[:-1]

def readarr(sep=None, maxsplit=-1):
	return read().split(sep, maxsplit)

def readint():
	return int(read())

def readintarr(sep=None, maxsplit=-1):
	return [int(a) for a in readarr(sep, maxsplit)]

def write(*args, **kwargs):
	sep = kwargs.get('sep', ' ')
	end = kwargs.get('end', '\n')
	stdout.write(sep.join((str(a) for a in args)) + end)

def writearr(arr, sep=' ', end='\n'):
	stdout.write(sep.join((str(a) for a in arr)) + end)
until = []
i = 2 ** 0
while i <= 10 ** 9:
	until.append(i)
	i *= 2
partial = [until[0]]
for i in range(1, len(until)):
	partial.append(partial[i - 1] + until[i])
import math
T = readint()
for t in range(T):
	n = readint()
	total = n * (n + 1) // 2
	nn = int(math.log2(n))
	total -= 2 * partial[nn]
	write(total)


for _ in range(int(input())):
	n = int(input())
	s = n * (n + 1) // 2
	x = 1
	while x <= n:
		x *= 2
		s -= x
	print(s)


for i in range(int(input())):
	s = 0
	n = int(input())
	s = n * (n + 1)
	s = s // 2
	for j in range(n):
		k = 2 ** j
		if k > n:
			break
		s -= k
		s -= k
	print(s)


n = int(input())
degs = [1]
cur = 1
while cur < 1000000000:
	cur *= 2
	degs.append(cur)
for _ in range(n):
	k = int(input())
	ar = k * (k + 1) // 2
	pos = 0
	while degs[pos] <= k:
		pos += 1
	geom = 2 ** pos - 1
	print(ar - 2 * geom)


from functools import cmp_to_key
from collections import deque, Counter
from heapq import heappush, heappop
from math import log, ceil
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def ii():
	return int(inp())

def si():
	return str(inp())

def li(lag=0):
	l = list(map(int, inp().split()))
	if lag != 0:
		for i in range(len(l)):
			l[i] += lag
	return l

def mi(lag=0):
	matrix = list()
	for i in range(n):
		matrix.append(li(lag))
	return matrix

def lsi():
	return list(map(str, inp().split()))

def print_list(lista, space=' ', **kwargs):
	print(space.join(map(str, lista)), **kwargs)

def bisect_left(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] < x:
			left = mid + 1
		else:
			right = mid
	return left

def bisect_right(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] > x:
			right = mid
		else:
			left = mid + 1
	return left

def bisect_elements(a, x):
	return bisect_right(a, x) - bisect_left(a, x)
MOD = 10 ** 9 + 7
maxN = 5
FACT = [0] * maxN
INV_FACT = [0] * maxN

def add(x, y):
	return (x + y) % MOD

def multiply(x, y):
	return x * y % MOD

def power(x, y):
	if y == 0:
		return 1
	elif y % 2:
		return multiply(x, power(x, y - 1))
	else:
		a = power(x, y // 2)
		return multiply(a, a)

def inverse(x):
	return power(x, MOD - 2)

def divide(x, y):
	return multiply(x, inverse(y))

def allFactorials():
	FACT[0] = 1
	for i in range(1, maxN):
		FACT[i] = multiply(i, FACT[i - 1])

def inverseFactorials():
	n = len(INV_FACT)
	INV_FACT[n - 1] = inverse(FACT[n - 1])
	for i in range(n - 2, -1, -1):
		INV_FACT[i] = multiply(INV_FACT[i + 1], i + 1)

def coeffBinom(n, k):
	if n < k:
		return 0
	return multiply(FACT[n], multiply(INV_FACT[k], INV_FACT[n - k]))

def create_graph(n, m, undirected=1, unweighted=1):
	graph = [[] for i in range(n)]
	if unweighted:
		for i in range(m):
			[x, y] = li(lag=-1)
			graph[x].append(y)
			if undirected:
				graph[y].append(x)
	else:
		for i in range(m):
			[x, y, w] = li(lag=-1)
			w += 1
			graph[x].append([y, w])
			if undirected:
				graph[y].append([x, w])
	return graph

def create_tree(n, unweighted=1):
	children = [[] for i in range(n)]
	if unweighted:
		for i in range(n - 1):
			[x, y] = li(lag=-1)
			children[x].append(y)
			children[y].append(x)
	else:
		for i in range(n - 1):
			[x, y, w] = li(lag=-1)
			w += 1
			children[x].append([y, w])
			children[y].append([x, w])
	return children

def dist(tree, n, A, B=-1):
	s = [[A, 0]]
	(massimo, massimo_nodo) = (0, 0)
	distanza = -1
	v = [-1] * n
	while s:
		(el, dis) = s.pop()
		if dis > massimo:
			massimo = dis
			massimo_nodo = el
		if el == B:
			distanza = dis
		for child in tree[el]:
			if v[child] == -1:
				v[child] = 1
				s.append([child, dis + 1])
	return (massimo, massimo_nodo, distanza)

def diameter(tree):
	(_, foglia, _) = dist(tree, n, 0)
	(diam, _, _) = dist(tree, n, foglia)
	return diam

def dfs(graph, n, A):
	v = [-1] * n
	s = [[A, 0]]
	v[A] = 0
	while s:
		(el, dis) = s.pop()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def bfs(graph, n, A):
	v = [-1] * n
	s = deque()
	s.append([A, 0])
	v[A] = 0
	while s:
		(el, dis) = s.popleft()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def parents_children_root_unrooted_tree(tree, n, root=0):
	q = deque()
	visited = [0] * n
	parent = [-1] * n
	children = [[] for i in range(n)]
	q.append(root)
	while q:
		all_done = 1
		visited[q[0]] = 1
		for child in tree[q[0]]:
			if not visited[child]:
				all_done = 0
				q.appendleft(child)
		if all_done:
			for child in tree[q[0]]:
				if parent[child] == -1:
					parent[q[0]] = child
					children[child].append(q[0])
			q.popleft()
	return (parent, children)

def all_longest_path_passing_from_node(parent, children, n):
	q = deque()
	visited = [len(children[i]) for i in range(n)]
	downwards = [[0, 0] for i in range(n)]
	upward = [1] * n
	longest_path = [1] * n
	for i in range(n):
		if not visited[i]:
			q.append(i)
			downwards[i] = [1, 0]
	while q:
		node = q.popleft()
		if parent[node] != -1:
			visited[parent[node]] -= 1
			if not visited[parent[node]]:
				q.append(parent[node])
		else:
			root = node
		for child in children[node]:
			downwards[node] = sorted([downwards[node][0], downwards[node][1], downwards[child][0] + 1], reverse=True)[0:2]
	s = [node]
	while s:
		node = s.pop()
		if parent[node] != -1:
			if downwards[parent[node]][0] == downwards[node][0] + 1:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][1])
			else:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][0])
		longest_path[node] = downwards[node][0] + downwards[node][1] + upward[node] - min([downwards[node][0], downwards[node][1], upward[node]]) - 1
		for child in children[node]:
			s.append(child)
	return longest_path
for test in range(ii()):
	n = ii()
	s = n * (n + 1) // 2
	po = 1
	while po <= n:
		s -= 2 * po
		po *= 2
	print(s)


import math
x = int(input())
for i in range(x):
	n = int(input())
	s = n * (n + 1) // 2
	pow2 = 1
	while pow2 <= n:
		s -= pow2 * 2
		pow2 *= 2
	print(s)


t = int(input())
x = []
x = [2 ** i for i in range(0, 32)]
for i in range(t):
	q = int(input())
	k = 0
	while x[k] <= q:
		k += 1
	ans = (1 + q) * q // 2
	print(ans - 2 * (2 ** k - 1))


import math
ans = 0
a = int(input())
for index in range(a):
	n = int(input())
	ans = (1 + n) * n // 2
	b = int(math.log(n, 2)) + 1
	for i in range(b):
		i += 1
		ans = ans - 2 ** i
	print(ans)


import math
for _ in range(int(input())):
	n = int(input())
	sumofall = n * (n + 1) // 2
	pow2 = int(math.log(n, 2)) + 1
	sumof2 = 2 ** pow2 - 1
	ans = int(sumofall - 2 * sumof2)
	print(ans)


from math import log2

def sum_until_n(n):
	return n * (n + 1) // 2

def sum_of_squares(n):
	return 2 ** (int(log2(n)) + 1) - 1
m = int(input())
res = []
for i in range(m):
	n = int(input())
	k = int(sum_until_n(n) - 2 * sum_of_squares(n))
	res.append(k)
for v in res:
	print(v)


import sys
import collections
input = sys.stdin.readline

def rints():
	return map(int, input().strip().split())

def rint():
	return int(input().strip())

def rintas():
	return [int(i) for i in input().strip().split()]

def gcd(a, b):
	if a == 0:
		return b
	return gcd(a % b, a)
n = rint()
for _ in range(n):
	t = rint()
	total = t * (t + 1) // 2
	s = 0
	for i in range(t + 1):
		if 2 ** i > t:
			break
		else:
			s += 2 ** i
	print(total - 2 * s)


a = [2 ** i for i in range(30)]
l = 0
import math
for i in range(len(a)):
	l += a[i]
	a[i] = l
t = int(input())
for _ in range(t):
	n = int(input())
	k = int(math.log2(n))
	l = n * (n + 1) // 2
	print(l - 2 * a[k])


import math
for _ in range(int(input())):
	n = int(input())
	res = n * (n + 1) // 2
	x = int(math.log(n, 2))
	x += 1
	su = 2 ** x - 1
	res -= 2 * su
	print(res)


import math
for iii in range(int(input())):
	n = int(input())
	t = int(math.log(n, 2))
	o = n * (n + 1) // 2
	print(o - 2 * 2 ** (t + 1) + 2)


for _ in range(int(input())):
	n = int(input())
	total = int(n * (n + 1) // 2)
	sub = 2
	total_sub = 1
	while True:
		if sub > n:
			break
		total_sub = total_sub + sub
		sub = sub * 2
	print(total - 2 * total_sub)


t = int(input())
for i in range(t):
	n = int(input())
	sum1 = (1 + n) * n // 2
	sum2 = 0
	j = 0
	while 2 ** j <= n:
		sum2 += 2 ** j
		j += 1
	print(sum1 - 2 * sum2)


import math
for i in range(int(input())):
	n = int(input())
	a = int(math.log(n, 2))
	print(n * (n + 1) // 2 - 2 * (2 ** (a + 1) - 1))


t = int(input())
for i in range(t):
	n = int(input())
	suma = n * (n + 1) // 2
	two = 1
	while two <= n:
		suma -= two * 2
		two <<= 1
	print(suma)


m = int(input())
for j in range(m):
	n = int(input())
	sum = n * (n + 1) // 2
	k = 0
	while 2 ** k <= n:
		sum -= 2 * 2 ** k
		k += 1
	print(sum)


t = int(input())
while t:
	n = int(input())
	sum1 = n * (n + 1) // 2
	num = 1
	sum2 = 0
	while num <= n:
		sum2 += num
		num *= 2
	print(sum1 - sum2 * 2)
	t -= 1


from math import log, floor
for case in range(int(input())):
	n = int(input())
	power = int(log(n, 2))
	ans = n * (n + 1) // 2 - int(2 ** (power + 2))
	ans = int(ans) + 2
	print(ans)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	k = int(math.log2(n)) + 1
	k = 2 * ((1 << k) - 1)
	n = n * (n + 1) // 2 - k
	print(n)


t = int(input())
for _ in range(t):
	n = int(input())
	t1 = n * (n + 1) // 2
	n2 = n.bit_length()
	t2 = 2 * (1 - 2 ** n2) // (1 - 2)
	t3 = t1 - t2
	print(t3)


t = int(input())
for i in range(t):
	n = int(input())
	s = (0 + n) * (n + 1) // 2
	for i in range(35):
		if 2 ** i <= n:
			s -= 2 * 2 ** i
	print(s)


t = int(input())
for i in range(t):
	n = int(input())
	res = (n + 1) * n // 2
	cur_t = 1
	while cur_t <= n:
		res -= 2 * cur_t
		cur_t *= 2
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	ans = n * (n + 1) // 2
	st = 1
	while st <= n:
		ans -= 2 * st
		st *= 2
	print(ans)


import math
t = int(input())
for i in range(t):
	n = int(input())
	ans = n * (n + 1) // 2
	k = 1
	while k <= n:
		ans -= k + k
		k *= 2
	print(ans)


max_n = 10 ** 9
t = int(input())
a = []
b = 1
while b < max_n:
	a.append(b)
	b *= 2
for _ in range(t):
	n = int(input())
	s = (n + 1) * n // 2
	for b in a:
		if b > n:
			break
		s -= 2 * b
	print(s)


a = [2 ** i for i in range(31)]
for i in range(int(input())):
	n = int(input())
	x = n * (n + 1) // 2
	c = 0
	for j in a:
		if j <= n:
			c += j
		else:
			break
	print(x - c * 2)


t = int(input())
dp = [0] * 30
i = 2
c_i = 1
dp[0] = 1
while c_i < 30:
	dp[c_i] = dp[c_i - 1] + i
	i *= 2
	c_i += 1

def b_s(l, h, v):
	if l > h:
		return l - 1
	m = (l + h) // 2
	if 2 ** m > v:
		return b_s(l, m - 1, v)
	elif 2 ** m < v:
		return b_s(m + 1, h, v)
	else:
		return m
for _ in range(t):
	s = int(input())
	t_s = b_s(0, len(dp), s)
	print(s * (s + 1) // 2 - dp[t_s] * 2)


import math
n = int(input())
for i in range(n):
	a = int(input())
	k = int(math.log2(a)) + 2
	s = a * (a + 1) // 2 - 2 ** k + 2
	print(s)


n = int(input())
a = []
for i in range(n):
	a.append(int(input()))
for b in a:
	sumi = 0
	sumi = b * (b + 1) // 2
	po = 0
	while 2 ** po <= b:
		sumi -= 2 ** (po + 1)
		po += 1
	print(sumi)


import math
t = int(input())

def process(n):
	sum = n * (n + 1) // 2
	power = int(math.log2(n))
	sum2 = (1 << power + 1) - 1
	sum = sum - 2 * sum2
	return sum
for testNo in range(t):
	n = int(input())
	print(process(n))


def pow_2(n):
	st = 1
	s = 0
	while st <= n:
		s += st * 2
		st *= 2
	return s
n = int(input())
for i in range(n):
	k = int(input())
	summa = (1 + k) * k // 2 - pow_2(k)
	print(summa)


t = int(input())
for i in range(t):
	n = int(input())
	gg = (n + n * n) // 2
	power = 0
	hh = 0
	while 1 << power <= n:
		power += 1
	power += 1
	hh = (1 << power) - 2
	print(gg - hh)


def evensum(n):
	return n * (n + 1)

def oddSum(n):
	return n * n
for _ in range(int(input())):
	n = int(input())
	pow2 = 1
	s = n * (n + 1) // 2
	while pow2 <= n:
		s = s - int(pow2 * 2)
		pow2 = int(pow2 * 2)
	print(int(s))


for _ in range(int(input())):
	n = int(input())
	sum = n * (n + 1) // 2
	d = 1
	while d <= n:
		sum -= 2 * d
		d *= 2
	print(sum)


for _ in range(int(input())):
	x = int(input())
	ans = x * (x + 1) // 2 - 2 * ((1 << x.bit_length()) - 1)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = n * (n + 1) // 2
	b = bin(n)
	z = len(b) - 3
	p = pow(2, z + 1) - 1
	print(s - 2 * p)


t = int(input())
import math

def solve(n):
	full = (1 + n) * n // 2
	powers_sum = 2 ** (int(math.log2(n)) + 1) - 1
	print(full - 2 * powers_sum)
for _ in range(t):
	solve(int(input()))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	t = I()
	a = [I() for _ in range(t)]
	r = []
	for c in a:
		k = (c + 1) * c // 2
		for i in range(33):
			ii = 2 ** i
			if ii > c:
				break
			k -= ii * 2
		r.append(k)
	return '\n'.join(map(str, r))
print(main())


def tricky_sum(n):
	total = n * (n + 1) // 2
	other = 1
	while other <= n:
		total -= 2 * other
		other *= 2
	return total
t = int(input())
for _ in range(t):
	print(tricky_sum(int(input())))


def main():
	t = int(input())
	for tt in range(t):
		n = int(input())
		ans = n * (n + 1) // 2
		two = 1
		while two <= n:
			ans -= 2 * two
			two *= 2
		print(ans)
main()


def solve(x):
	rt = x * (x + 1) // 2
	tmp = 1
	while tmp <= x:
		rt -= tmp * 2
		tmp *= 2
	return rt
n = int(input())
for _ in range(n):
	xx = int(input())
	print(solve(xx))


def s(n):
	tot = 0
	k = 1
	while k <= n:
		tot += 2 * k
		k *= 2
	return n * (n + 1) // 2 - int(tot)
for i in range(int(input())):
	print(s(int(input())))


def s(n):
	return n * (n + 1) // 2

def t(n):
	a = 1
	ret = 0
	while a <= n:
		ret += a
		a *= 2
	return ret
for _ in range(int(input())):
	n = int(input())
	print(s(n) - 2 * t(n))


for _ in range(int(input())):
	n = int(input())
	a = 1
	while a <= n:
		a *= 2
	print(n * (n + 1) // 2 - 2 * (a - 1))


for i in range(int(input())):
	n = int(input())
	(counter, ans) = (1, n * (n + 1) // 2)
	while counter <= n:
		counter *= 2
	print(ans - 2 * counter + 2)


inp = int(input())
for x in range(1, inp + 1):
	n = int(input())
	a = 0
	for i in range(0, 30):
		if pow(2, i) > n:
			break
		else:
			a = pow(2, i + 1) - 1
	sum_ = n * (n + 1) // 2 - 2 * a
	print(sum_)


import math
for aaaa in range(int(input())):
	n = int(input())
	s2 = 0
	for i in range(int(math.log(n, 2) + 1)):
		s2 += int(2 ** i)
	print(int(int(int(n * (n + 1)) // 2) - int(s2 * 2)))


import math
for i in range(int(input())):
	x = int(input())
	r = int(math.log(x, 2) + 1)
	a = x * (x + 1) // 2
	ans = a - 2 * (2 ** r - 1)
	print(ans)


n = int(input())
X = [int(input()) for _ in range(n)]
for i in X:
	print(i * (i + 1) // 2 - 2 * (2 ** i.bit_length() - 1))


import math
t = int(input())
for i in range(t):
	n = int(input())
	p = int(math.log2(n))
	s1 = pow(2, p)
	s2 = 0
	while s1 >= 1:
		s2 += s1
		s1 = s1 // 2
	s3 = n * (n + 1) // 2
	print(s3 - 2 * s2)


n = int(input())
for test in range(n):
	num = int(input())
	res = (1 + num) * num >> 1
	deg = 0
	while 2 ** deg <= num:
		deg += 1
	res -= 2 * (2 ** deg - 1)
	print(res)


def pow2(n):
	if n == 1:
		return 0
	return 1 + pow2(n // 2)

def row_sum(n):
	return n * (n + 1) // 2 - (1 << pow2(n)) * 4 + 2
for i in range(int(input())):
	print(row_sum(int(input())))


t = int(input())

def sum(x):
	k = 1
	sum = (1 + x) * x // 2
	while k <= x:
		sum -= k * 2
		k *= 2
	return sum
for i in range(t):
	n = int(input())
	print(sum(n))


t = int(input())
for test in range(t):
	n = int(input())
	s = (1 + n) * n >> 1
	p = 1
	while p <= n:
		p <<= 1
		s -= p
	print(s)


t = int(input())
while t:
	n = int(input())
	s2 = int(n * int(n + 1) // 2)
	s = 1
	k = 1
	while s <= n:
		s = 2 * s
		k += s
	k = k - s
	print(s2 - 2 * k)
	t -= 1


t = int(input())
result = []
for _ in range(t):
	num = int(input())
	power = 0
	temp = 1
	while temp <= num:
		temp *= 2
		power += 1
	power -= 1
	sum = num * (num + 1) // 2 - 2 ** (power + 2) + 2
	result.append(int(sum))
for res in result:
	print(res)


for i in range(int(input())):
	n = int(input())
	total = 0
	i = 1
	total = n * (n + 1) // 2
	diff = []
	j = 1
	while j <= n:
		diff.append(j)
		j = j * 2
	ans = total - 2 * sum(diff)
	print(ans)


def solve(x):
	classic_sum = (1 + x) * x // 2
	pow_sum = 0
	tmp = 1
	while tmp <= x:
		pow_sum += tmp
		tmp *= 2
	return classic_sum - 2 * pow_sum
n = int(input())
for i in range(n):
	print(solve(int(input())))


t = int(input())
for i in range(t):
	n = int(input())
	num = 1
	sum = n * (n + 1) // 2
	while num <= n:
		num = num * 2
	print(sum - 2 * num + 2)


x = int(input())
y = 0
while y < x:
	a = int(input())
	b = (1 + a) * a // 2
	c = 0
	d = 30
	e = []
	while c < d:
		e = e + [2 ** c]
		c = c + 1
	c = 0
	d = 30
	while c < d:
		if a >= e[c]:
			b = b - e[c] * 2
			c = c + 1
		else:
			break
	print(b)
	y = y + 1


import math
num = int(input())
for i in range(num):
	Sum = -1
	number = int(input())
	Sum += (2 + number) * (number - 1) // 2
	for i in range(1, number + 1):
		a = pow(2, i)
		if a <= number:
			Sum -= 2 * a
		else:
			break
	print(Sum)


from math import pow
for i in range(int(input())):
	n = int(input())
	sub = 0
	k = 0
	sum1 = n * (n + 1) // 2
	while 2 ** k <= n:
		sub += 2 ** k
		k += 1
	print(int(sum1 - 2 * sub))


a = []
i = 0
while 2 ** i <= 1000000000:
	a.append(2 ** i)
	i += 1
l = len(a)
t = int(input())
for i in range(0, t):
	n = int(input())
	if n % 2 == 0:
		total = int(n / 2) * (n + 1)
	else:
		total = int((n + 1) / 2) * n
	for i in range(0, l):
		if a[i] > n:
			break
		else:
			total -= 2 * a[i]
	print(int(total))


def nextPowerOf2(n):
	count = 0
	if n and (not n & n - 1):
		return n * 2
	while n != 0:
		n >>= 1
		count += 1
	return 1 << count
t = int(input())
for i in range(t):
	n = int(input())
	an = n * (n + 1) // 2
	w = nextPowerOf2(n)
	if w != n:
		w = w // 2
	st = str(bin(w))
	r = len(st) - 3
	print(an - 2 * (2 ** (r + 1) - 1))


t = int(input())
for i in range(t):
	n = int(input())
	sum = 0
	i = 0
	while True:
		a = pow(2, i)
		if a > n:
			break
		else:
			sum = sum + a
		i += 1
	print(n * (1 + n) // 2 - 2 * sum)


t = int(input())
for i in range(t):
	n = int(input())
	o = n * (n + 1) // 2
	p = 1
	while p <= n:
		o = o - 2 * p
		p = p * 2
	print(o)


t = int(input())
for i in range(t):
	n = int(input())
	s = n * (n + 1) // 2
	k = 1
	y = 1
	while True:
		y *= 2
		k += 1
		if y > n:
			k -= 1
			break
	s2 = 2 ** (k + 1) - 2
	print(s - s2)


t = int(input())
ma = []
i = 1
while i <= t:
	m = int(input())
	s = m * (m + 1) // 2
	k = 1
	while k <= m:
		s = s - 2 * k
		k = k * 2
	ma.append(s)
	i = i + 1
i = 1
while i <= t:
	print(ma[i - 1])
	i = i + 1


for t in range(int(input())):
	n = int(input())
	ans = n * (n + 1) // 2
	cnt = 0
	while n > 0:
		n = n // 2
		cnt += 1
	print(ans - 2 * (2 ** cnt - 1))


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
d = defaultdict(int)
t = I()
for i in range(t):
	n = I()
	ans = 0
	x = 1
	while x <= n:
		ans += x
		x *= 2
	print(n * (n + 1) // 2 - 2 * ans)


import math

def nullptr(num):
	powers = []
	i = 1
	while i <= num:
		if i | num:
			powers.append(i)
		i <<= 1
	neg = sum(powers) * -2
	return neg
line = int(input())
if 0 < line <= 100:
	for _ in range(line):
		tail = int(input())
		if 0 < tail <= 1000000000:
			neg = nullptr(tail)
			head = 1
			pair = tail / 2.0
			pos = (head + tail) * tail // 2
			print(pos + neg)


cases = int(input())
for _ in range(cases):
	n = int(input())
	two_power = 0
	i = 1
	while i <= n:
		i *= 2
		two_power += 1
	two_power -= 1
	total = (1 + n) * n // 2 - 2 * (2 ** (two_power + 1) - 1)
	print(total)


arr = []
for i in range(37):
	arr.append(2 ** i)
t = int(input())
for i in range(t):
	n = int(input())
	f = 0
	s = (1 + n) * n // 2
	for j in range(37):
		if arr[j] <= n:
			f -= 2 * arr[j]
		else:
			break
	print(s + f)


t = int(input())
list = []
for x in range(t):
	list.append(int(input()))
for elem in list:
	sum = elem * (elem + 1) // 2
	x = 1
	while x <= elem:
		sum -= x * 2
		x *= 2
	print(sum)


for _ in range(int(input())):
	n = int(input())
	print(n * (n + 1) // 2 - 2 * (2 ** n.bit_length() - 1))
3


t = int(input())
while t > 0:
	n = int(input())
	s = n * (n + 1) // 2
	i = 1
	t -= 1
	while i <= n:
		s -= 2 * i
		i *= 2
	print(s)


for _ in range(int(input())):
	n = int(input())
	x = n * (n + 1) // 2
	y = 0
	num = 1
	while num <= n:
		y += num
		num *= 2
	print(x - y * 2)


t = int(input())
for _ in range(t):
	n = int(input())
	sum2 = 0
	cur = 1
	while cur <= n:
		sum2 += cur
		cur *= 2
	print(n * (1 + n) // 2 - 2 * sum2)


t = int(input())
for _ in range(t):
	n = int(input())
	(p, x) = (0, 1)
	while 2 * x <= n:
		x *= 2
		p += 1
	res = n * (n + 1) // 2 - 2 * (2 ** (p + 1) - 1)
	print(res)


from math import log2
t = int(input())
res = []
for _ in range(t):
	n = int(input())
	r = n * (n + 1) // 2 - 2 ** (int(log2(n)) + 2) + 2
	res += [str(r)]
print('\n'.join(res))


t = int(input())
for i in range(0, t):
	n = int(input())
	sum = n * (n + 1) // 2
	x = pow(2, 0)
	j = 0
	while x <= n:
		sum -= 2 * x
		j += 1
		x = pow(2, j)
	print(sum)


import math
n = int(input())
for i in range(n):
	i = int(input())
	s = i * (i + 1) // 2
	(d, j) = (0, 1)
	while j <= i:
		d += 2 * j
		j *= 2
	print(s - d)


ary = [int(input()) for _ in range(int(input()))]
for p in ary:
	s = p * (p + 1) // 2
	log = 0
	while p > 0:
		log += 1
		p //= 2
	s -= 2 * (2 ** log - 1)
	print(s)


for i in '.' * int(input()):
	(a, b) = (int(input()), 1)
	while b <= a:
		b *= 2
	print(a * (a + 1) // 2 - 2 * (b - 1))


import math
t = int(input())
for i in range(t):
	n = int(input())
	print(n * (n + 1) // 2 - 2 * (int(pow(2, int(math.log2(n)) + 1)) - 1))


t = int(input())
for o in range(t):
	x = int(input())
	ans = x * (x + 1) // 2
	num = 1
	while num <= x:
		ans -= 2 * num
		num *= 2
	print(ans)


s = 0
t = int(input())
i = 0
a = list()
for j in range(t):
	n = int(input())
	s = 0
	i = 0
	summa = int((n + 1) * n // 2)
	while 2 ** i <= n:
		s += 2 ** i
		i += 1
	a.append(summa - 2 * s)
for k in range(t):
	print(a[k])


n = int(input())
ans = []
pow_2 = [1]
for i in range(60):
	pow_2.append(pow_2[-1] * 2)
for i in range(n):
	cur = int(input())
	ans1 = cur * (cur + 1) // 2
	j = 0
	while pow_2[j] <= cur:
		ans1 -= 2 * pow_2[j]
		j += 1
	ans.append(ans1)
for e in ans:
	print(e)


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, sin, cos, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(1000000000)
INF = float('inf')
(YES, Yes, yes, NO, No, no) = ('YES', 'Yes', 'yes', 'NO', 'No', 'no')
(dy4, dx4) = ([0, 1, 0, -1], [1, 0, -1, 0])
(dy8, dx8) = ([0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1])

def inside(y, x, H, W):
	return 0 <= y < H and 0 <= x < W

def ceil(a, b):
	return (a + b - 1) // b

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	g = gcd(a, b)
	return a / g * b

def euclidean_distance(y1, x1, y2, x2):
	return sqrt((y1 - y2) ** 2 + (x1 - x2) ** 2)

def manhattan_distance(y1, x1, y2, x2):
	return abs(y1 - y2) + abs(x1 - x2)

def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		ans = (1 + N) * N // 2
		for i in range(60):
			if 2 ** i <= N:
				ans -= 2 ** i * 2
		print(ans)
main()


import math
from decimal import *
getcontext().prec = 30
l1 = input()
l1 = int(l1)
for i in range(l1):
	x = Decimal(input())
	sumplus = Decimal(x * (x + 1) / 2)
	num = Decimal(1)
	summinus = Decimal(0)
	while num <= x:
		summinus += num
		num = Decimal(int(num * 2))
	print(Decimal(sumplus - summinus * 2))


def log2(x):
	count = 0
	while x >= 2:
		count += 1
		x /= 2
	return count
l = int(input())
for _ in range(l):
	a = int(input())
	if a % 2 == 0:
		part = int(a / 2)
		sum = (a + 1) * part
	else:
		part = int((a + 1) / 2)
		sum = a * part
	r = 2 ** log2(a) * 2 - 1
	print(sum - 2 * r)


import sys
import math
inputlines = sys.stdin.readlines()
number_of_testcases = int(inputlines[0])

def find_largest_2_power(number):
	largest_power = 0
	while number > 1:
		largest_power += 1
		number //= 2
	return largest_power
for i in range(number_of_testcases):
	number = int(inputlines[i + 1])
	largest_power = find_largest_2_power(number)
	sum_till_n = number * (number + 1) // 2
	sum_of_powers = math.pow(2, largest_power + 1) - 1
	final_ans = int(sum_till_n) - int(2 * sum_of_powers)
	print(final_ans)


m = int(input())
while m:
	n = int(input())
	sum = n * (n + 1) // 2
	i = 1
	m -= 1
	while i <= n:
		sum -= 2 * i
		i *= 2
	print(sum)


z = int(input())
import math
for j in range(z):
	n = int(input())
	if n % 2 == 0:
		total = n // 2 * n + n // 2
	else:
		total = (n // 2 + 1) * n
	minus = 0
	temp = 0
	while abs(minus) < n:
		minus += 2 ** temp
		temp += 1
	print(total - minus * 2)


def ans(n):
	a = 0
	i = 1
	while i <= n:
		a = a + i
		i = i * 2
	sum = (n + 1) * n // 2 - 2 * a
	print(sum)

def loop(k):
	while k != 0:
		n = int(input(''))
		ans(n)
		k = k - 1
k = int(input(''))
loop(k)


n = int(input())
s = 0
c = 0
for i in range(n):
	k = int(input())
	s = k * (k + 1) // 2
	t = 1
	while t <= k:
		c += t
		t *= 2
	print(s - c * 2)
	s = 0
	c = 0


def prs(x):
	s = 0
	i = 1
	while i <= x:
		s += i
		i *= 2
	return 2 * s
for _ in range(int(input())):
	n = int(input())
	print(n * (n + 1) // 2 - prs(n))


from math import floor, log2

def get_sum(x):
	return x * (x + 1) // 2 + 2 - 2 ** (floor(log2(x)) + 2)
t = int(input())
ans = list()
for i in range(t):
	n = int(input())
	ans.append(get_sum(n))
print('\n'.join(map(str, ans)))


for _ in range(int(input())):
	n = int(input())
	total = n * (n + 1) // 2
	c = 1
	while c <= n:
		total = total - 2 * c
		c = c * 2
	print(total)


for i in range(int(input())):
	p = 1
	q = 0
	n = m = int(input())
	n = q = (n ** 2 + n) // 2
	while p <= m:
		q -= p * 2
		p = p * 2
	print(q)


import math
n = int(input())
for i in range(n):
	num = int(input())
	first_part = num * (num + 1) // 2
	power = math.floor(math.log2(num))
	second_part = 2 ** (power + 1) - 1
	answer = first_part - 2 * second_part
	print(answer)


n = int(input())
for it in range(n):
	x = int(input())
	res = x * (x + 1) // 2
	m = 1
	while m <= x:
		res -= 2 * m
		m *= 2
	print(res, sep='\n')


m = int(input())
for i in range(m):
	n = int(input())
	s = int((n + 1) * n // 2)
	f = False
	for j in range(n):
		if 2 ** j <= n:
			s -= int(2 ** (j + 1))
		else:
			break
	print(s)


import math
test_cases = int(input())

def power(n):
	return int(math.log2(n))

def sum_powers_of_two(n):
	return 2 ** (power(n) + 1) - 1

def sum_of_n_terms(n):
	return n * (n + 1) // 2
for i in range(test_cases):
	n = int(input())
	print(sum_of_n_terms(n) - 2 * sum_powers_of_two(n))


t = int(input())
array = []
for i in range(t):
	array.append(int(input()))
for i in range(t):
	print(array[i] * (1 + array[i]) // 2 - 2 * (1 - 2 ** len(bin(array[i])[2:])) // (1 - 2))


import math
for _ in range(int(input())):
	a = int(input())
	s1 = (1 + a) * a // 2
	k = int(math.log2(a))
	s2 = 2 ** k * 2 - 1
	print(s1 - 2 * s2)


from math import log
from decimal import Decimal

def Find_N(a):
	N = log(a) / log(2)
	return N
essays = int(input())
data = []
for i in range(essays):
	data.append(int(input()))
for j in range(essays):
	LastN = int(Find_N(data[j]))
	positive = int(Decimal(data[j]) * Decimal(data[j] + 1) / 2)
	negative = -(1 - 2 ** (LastN + 1))
	print(Decimal(positive) - Decimal(2 * negative))


t = int(input())
while t:
	n = int(input())
	sum = n * (n + 1) // 2
	i = 1
	t = t - 1
	while i <= n:
		sum -= 2 * i
		i = i * 2
	print(sum)


from math import floor, log2
t = int(input())
arr = []
for i in range(t):
	n = int(input())
	arr.append(n)
for n in arr:
	print(n * (n + 1) // 2 - 2 ** (floor(log2(n)) + 2) + 2)


import math
t = int(input())
for i in range(t):
	n = int(input().strip())
	l = [-1]
	k = int(math.log(n, 2))
	for i in range(k):
		l.append(2 * l[i])
	u = n * (n + 1) // 2 + 2 * sum(l)
	print(u)


t = int(input())
for _ in range(t):
	n = int(input())
	result = n * (n + 1) // 2
	for i in range(100):
		if 2 ** i <= n:
			result -= 2 * 2 ** i
		else:
			break
	print(result)


import math
for _ in range(int(input())):
	n = int(input())
	a = math.log(n, 2)
	a = a - a % 1
	a = int(a)
	s = 2 ** (a + 1) - 1
	b = (1 + n) * n // 2
	print(b - 2 * s)


cleversum = lambda x: x * (x + 1) // 2 - (1 << x.bit_length() + 1) + 2
t = int(input())
for i in range(t):
	n = int(input())
	print(cleversum(n))


t = int(input())
for i in range(t):
	x = int(input())
	ans = x * (x + 1) // 2
	cur = 1
	while cur <= x:
		ans -= 2 * cur
		cur *= 2
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = n * (n + 1) // 2
	m = 1
	while m <= n:
		ans -= m * 2
		m *= 2
	print(ans)


num = int(input())
while num > 0:
	n = int(input())
	sum_of_numbers = n * (n + 1) // 2
	power = 1
	sum_of_powers = 0
	while power <= n:
		sum_of_powers += power
		power *= 2
	print(sum_of_numbers - 2 * sum_of_powers)
	num -= 1


import math
t = int(input())
for _ in range(t):
	n = int(input())
	s = n * (n + 1) // 2
	s1 = 0
	n1 = 1
	while n1 <= n:
		s1 = s1 + n1
		n1 = n1 * 2
	print(s - 2 * s1)


import math
t = int(input())
for case in range(t):
	n = int(input())
	sum = n * (n + 1) // 2
	l = math.floor(math.log(n, 2))
	sum -= 2 * (2 ** (l + 1) - 1)
	print(sum)


sol = lambda n: n * (n + 1) // 2 - 2 * (2 ** (len(bin(n)) - 2) - 1)
for tc in range(int(input())):
	print(sol(int(input())))


for _ in range(int(input())):
	n = int(input())
	print(str(n * (n + 1) // 2 + 2 - (2 << n.bit_length())))


from bisect import bisect
two = []
for i in range(1000000000):
	tmp = 2 ** i
	if tmp <= 1000000000:
		two.append(2 ** i)
	else:
		break
for _ in range(int(input())):
	n = int(input())
	result = n * (n + 1) // 2
	result -= 2 * sum(two[:bisect(two, n)])
	print(result)


(pow2, num) = ([1], 1)
while num <= 10000000000.0:
	num = num << 1
	pow2.append(num)
for t in range(int(input())):
	n = int(input())
	for num in pow2:
		if num > n:
			b = num - 1 << 1
			break
	if n & 1:
		print((n + 1) // 2 * n - b)
	else:
		print(n // 2 * (n + 1) - b)


import math
a = []
for i in range(30):
	a.append(2 ** i)
	if i > 0:
		a[i] += a[i - 1]
n = int(input())
while n:
	x = int(input())
	m = 2 * a[int(math.log(x, 2))]
	print(x * (x + 1) // 2 - m)
	n -= 1


import sys
n = int(sys.stdin.readline())
for i in range(n):
	val = int(sys.stdin.readline())
	lim = 1
	sum = val * (val + 1) // 2
	while lim * 2 <= val:
		lim *= 2
	sum -= (lim * 2 - 1) * 2
	print(sum)


import math

def arithmticSeries(a, n, d):
	return n * (2 * a + (n - 1) * d) // 2

def geometrySeries(r, n):
	return (1 - r ** n) // (1 - r)
t = int(input())
while t > 0:
	m = int(input())
	x = arithmticSeries(int(1), m, int(1))
	k = int(math.log(m, 2))
	y = geometrySeries(int(2), k + 1)
	print(x - 2 * y)
	t -= 1


x = int(input())
for i in range(x):
	a = 1
	y = int(input())
	if y % 2 == 1:
		z = y + (y - 1) // 2 * y
	else:
		z = y // 2 * (y + 1)
	while a <= y:
		z -= a * 2
		a *= 2
	print(z)


n = int(input())
for _ in range(n):
	m = int(input())
	su = m * (m + 1) // 2
	i = 0
	sa = 0
	while 2 ** i <= m:
		sa += 2 ** i
		i += 1
	su -= 2 * sa
	print(su)


nCases = int(input())
for _ in range(nCases):
	n = int(input())
	regSum = n * (n + 1) // 2
	remove = 0
	i = 0
	while True:
		power = 2 ** i
		if power > n:
			break
		remove += 2 * power
		i += 1
	print(regSum - remove)


def somatorio(x):
	if x % 2 == 0:
		return (1 + x) * (x // 2)
	else:
		return (1 + x) // 2 * x
n_casos = int(input())
resposta_final = []
for caso in range(n_casos):
	entrada = int(input())
	resposta = somatorio(entrada)
	pot2 = 0
	while 2 ** pot2 <= entrada:
		resposta = resposta - 2 * 2 ** pot2
		pot2 += 1
	resposta_final.append(resposta)
for resposta in resposta_final:
	print(int(resposta))


for i in range(int(input())):
	a = int(input())
	p = a * (a + 1) // 2
	t = 0
	for j in range(a):
		if 2 ** j <= a:
			t += 2 ** j
		else:
			break
	print(p - t - t)


m = int(input())
data = []
i = 1
while i <= m:
	k = input()
	i += 1
	data.append(k)
num = [int(x) for x in data]
for i in range(m):
	s = int((1 + num[i]) * num[i] // 2)
	st2 = 0
	pst = -1
	while st2 <= num[i]:
		pst += 1
		s = s - 2 * st2
		st2 = 2 ** pst
	print(s)


l = [pow(2, i) for i in range(31)]
for _ in range(int(input())):
	t = int(input())
	total = t * (t + 1) // 2
	x = 0
	while l[x] <= t:
		x += 1
	p = -(2 * sum(l[:x]))
	print(total + p)


testnumber = int(input())
for tn in range(testnumber):
	n = int(input())
	z = 1
	while z <= n:
		z *= 2
	s = n * (n + 1) // 2 - 2 * (z - 1)
	print(s)


t = int(input())
results = dict()
negative_part = dict()
b = [1 << i for i in range(0, 31)]

def _biggest_m(n):
	for (index, value) in enumerate(b):
		if n == value:
			return index
		if n < value:
			return index - 1

def _calculate(n):
	_positive_part = n * (n + 1) >> 1
	_m = _biggest_m(n)
	try:
		return _positive_part - negative_part[_m]
	except KeyError:
		negative_part[_m] = 2 * (b[_m + 1] - 1)
		return _positive_part - negative_part[_m]
_values = list()
for x in range(0, t):
	_values.append(int(input()))
for n in _values:
	try:
		print(results[n])
	except KeyError:
		results[n] = _calculate(n)
		print(results[n])


for q in range(int(input())):
	n = int(input())
	res = n * (n + 1) // 2
	n2 = 0
	p = 0
	while 1 << p <= n:
		res -= 2 * (1 << p)
		p += 1
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	ss = n * (n + 1) // 2
	n1 = n
	c = 0
	while n1 >= 1:
		c += 1
		n1 /= 2
	s2 = pow(2, c) - 1
	print(ss - 2 * s2)


T = int(input())
for _ in range(T):
	N = int(input())
	tmpN = N
	p = 0
	while tmpN > 0:
		tmpN = tmpN >> 1
		p += 1
	x = N * (N + 1) // 2
	y = (1 << p + 1) - 2
	print(x - y)


import sys

def max_2_power(n):
	s = bin(n)[2:]
	l = len(s)
	if n < 2 ** l:
		return l - 1
	return l
sys.stdin.readline()
for line in sys.stdin:
	try:
		n = int(line.strip('\n'))
		s1 = n * (n + 1) // 2
		n2 = max_2_power(n)
		s2 = 2 ** (n2 + 1) - 1
		r = s1 - 2 * s2
		sys.stdout.write(str(r) + '\n')
	except ValueError:
		break


import sys, math
t = int(input())
for x in range(t):
	n = int(input())
	sum = n * (n + 1) // 2
	j = 1
	tmp = 0
	while j <= n:
		tmp += j
		j *= 2
	print(sum - 2 * tmp)


def check(q):
	s = 0
	st = 1
	while st <= q:
		s += st
		st *= 2
	return -s
n = int(input())
for i in range(n):
	t = int(input())
	s = t * (t + 1) // 2
	s += 2 * check(t)
	print(s)


for t in range(int(input())):
	x = int(input())
	a = len(bin(x)) - 2
	b = 2 ** a - 1
	print(x * (x + 1) // 2 - 2 * b)


from itertools import takewhile, count
tests = [int(input()) for _ in range(int(input()))]
for n in tests:
	powers = (2 ** i for i in count())
	powers = takewhile(lambda x: x <= n, powers)
	print('%d' % ((n * n + n) // 2 - 2 * sum(powers)))


t = int(input())
for _ in range(t):
	n = int(input())
	s = n * (n + 1) // 2
	cur = 1
	while cur <= n:
		s -= cur * 2
		cur *= 2
	print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	m = 1
	i = 1
	l = []
	while m <= n:
		l.append(m)
		m = 2 ** i
		i = i + 1
	s = n * (n + 1) // 2
	s = s - 2 * sum(l)
	print(s)


n = int(input())
for z in range(n):
	num = int(input())
	total = num * (1 + num) // 2
	power = 0
	while True:
		dec = 2 ** power
		if dec > num:
			break
		total -= dec * 2
		power += 1
	print(total)


for _ in range(int(input())):
	(ans, sum) = (0, 0)
	n = int(input())
	j = 1
	ans = n * (n + 1) // 2
	while j <= n:
		ans -= j * 2
		j *= 2
	print(ans)


t = int(input())
for p in range(t):
	n = int(input())
	sum = 0
	number = 1
	nsum = n * (n + 1) // 2
	while number <= n:
		sum += number
		number *= 2
	print(nsum - sum * 2)


for _ in range(int(input())):
	n = int(input())
	sum1 = n * (n + 1) // 2
	t = 1
	while t <= n:
		t = t * 2
		sum1 -= t
	print(sum1)


q = int(input())
res = []
for i in range(0, q):
	num = int(input())
	summ = num * (num + 1) // 2
	stepen = 0
	while 2 ** stepen <= num:
		summ -= 2 * 2 ** stepen
		stepen += 1
	res.append(summ)
for i in res:
	print(i)


number_of_numbers = int(input())
results = []
for i in range(number_of_numbers):
	number = int(input())
	result = number * (number + 1) // 2
	power_of_two = len(bin(number)) - 3
	result -= 2 ** (power_of_two + 2) - 2
	results.append(str(int(result)))
for result in results:
	print(result)


from math import log2, pow

def trickly_sum(up):
	powers = [int(pow(2, i)) for i in range(int(log2(up)) + 1)]
	return up * (up + 1) // 2 - 2 * sum(powers)
n = int(input())
res = []
for i in range(n):
	limit = int(input())
	res += [trickly_sum(limit)]
print(*res, sep='\n')


def solve(n):
	r = n * (n + 1) // 2
	i = 1
	while i <= n:
		r -= i * 2
		i *= 2
	return r
t = int(input())
for i in range(t):
	print(solve(int(input())))


for i in range(int(input())):
	summ = 0
	summ2 = 1
	b = 1
	a = int(input())
	summ = (1 + a) * a // 2
	while b * 2 <= a:
		b *= 2
		summ2 += b
	print(int(summ - summ2 * 2))


t = int(input())
for _ in range(t):
	n = int(input())
	a = 0
	for i in range(50):
		if 2 ** i == n:
			a = i
			break
		elif 2 ** i > n:
			a = i - 1
			break
	b = []
	[b.append(2 ** i) for i in range(a + 1)]
	print(n * (n + 1) // 2 - 2 * sum(b))


import math
t = int(input())
for _ in range(t):
	n = int(input())
	m = 1
	if n % 2 == 0:
		result = int(n / 2) * (n + 1)
	else:
		result = n * int((n + 1) / 2)
	while m <= n:
		result -= 2 * m
		m *= 2
	print(int(result))


def smartSum(n):
	s = n * (n + 1) // 2
	power = 0
	current = 1
	while current <= n:
		power += 1
		current *= 2
	diff = (current - 1) * 2
	return int(s - diff)
t = input()
for i in range(int(t)):
	n = input()
	if int(n) == 1000000000:
		print(499999998352516354)
	else:
		print(smartSum(int(n)))


t = int(input())
while t:
	t -= 1
	n = int(input())
	p = 1
	while p <= n:
		p *= 2
	p = 2 * p - 2
	if n % 2 == 1:
		n = n * int((n + 1) / 2)
	else:
		n = int(n / 2) * (n + 1)
	print(n - p)


for i in range(int(input())):
	num = int(input())
	res = (1 + num) * num // 2
	i = 0
	while 2 ** i <= num:
		res -= 2 ** (i + 1)
		i += 1
	print(res)


import math
t = int(input())
while t > 0:
	n = int(input())
	po = int(math.log(n) / math.log(2))
	ans = n * (n + 1) // 2 - 2 * (2 ** (po + 1) - 1)
	print(ans)
	t -= 1


def main():
	sm = 0
	a = [2 ** i for i in range(31)]
	t = int(input())
	for j in range(t):
		n = int(input())
		sm = n * (n + 1) // 2
		i = 0
		while a[i] <= n:
			sm -= 2 * a[i]
			i += 1
		print(sm)
main()


import sys
sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def SI():
	return sys.stdin.readline()[:-1]

def MI():
	return map(int, sys.stdin.readline().split())

def MI1():
	return map(int1, sys.stdin.readline().split())

def MF():
	return map(float, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LI1():
	return list(map(int1, sys.stdin.readline().split()))

def LF():
	return list(map(float, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]

def main():
	t = II()
	for _ in range(t):
		n = II()
		s = n * (n + 1) // 2
		e = 1
		while e <= n:
			e <<= 1
		ans = s - (e - 1) * 2
		print(ans)
main()


for i in range(int(input())):
	k = int(input())
	b = k * (k + 1) // 2
	j = 0
	for i in range(k):
		if j < k:
			j = j + 2 ** i
		else:
			break
	print(b - 2 * j)


import math
from decimal import Decimal
n = int(input())
lst = []
for i in range(0, n):
	ele = int(input())
	lst.append(ele)
for i in lst:
	s = i * (i + 1) // 2
	sq = math.log(i, 2)
	sq = int(sq)
	ss = 2 * (pow(2, sq + 1) - 1)
	s -= ss
	print(int(s))


from math import floor, log2

def solve(n):
	result = n * (n + 1) // 2
	for x in range(floor(log2(n)) + 1):
		result -= 2 * 2 ** x
	return result

def main():
	n_requests = int(input())
	for _ in range(n_requests):
		print(solve(int(input())))
main()


import math
import itertools
t = int(input())
for _ in range(t):
	n = int(input())
	pre = n * (n + 1) // 2
	p = 1
	while p <= n:
		p *= 2
		pre -= p
	print(pre)


n = int(input())
lst = []
for i in range(n):
	lst.append(int(input()))
for l in lst:
	m = 0
	temp = l
	while temp != 0:
		temp = int(temp / 2)
		m += 1
	if l % 2 == 0:
		print(int(int(l / 2) * (l + 1)) + int(2 * (1 - 2 ** m)))
	else:
		print(int(l * int((l + 1) / 2)) + int(2 * (1 - 2 ** m)))


for t in range(int(input())):
	n = int(input())
	soma = n * (n + 1) // 2
	n2 = 1
	neg = 0
	while n2 <= n:
		neg += n2
		n2 *= 2
	print(int(soma - neg * 2))


t = int(input())
pw = [2 ** x for x in range(31)]
for T in range(t):
	n = int(input())
	s = n * (n + 1) // 2
	p = 0
	while pw[p] <= n:
		s -= pw[p] * 2
		p += 1
	print(s)


import sys
from math import log2
input = sys.stdin.readline

def main():
	ans = []
	for i in range(int(input())):
		n = int(input())
		k = int(log2(n))
		r = n * (n + 1) // 2 - 2 * ((1 << k + 1) - 1)
		ans.append(str(r))
	print('\n'.join(ans))
main()


t = int(input())
for i in range(t):
	n = int(input())
	sumn = n * (n + 1) // 2
	cnt = 1
	while cnt <= n:
		sumn -= 2 * cnt
		cnt *= 2
	print(sumn)


import math

def biexpo(n, p):
	r = 1
	while p > 0:
		if p % 2:
			r = r * n
			p = p - 1
		else:
			n = n ** 2
			p = p // 2
	return r
for _ in range(int(input())):
	n = int(input())
	ans1 = n * (n + 1) // 2
	n = int(math.log(n, 2))
	ans2 = biexpo(2, n + 1) - 1
	ans2 = 2 * ans2
	print(ans1 - ans2)


from sys import stdin
n = int(stdin.readline().rstrip())
for _ in range(n):
	cur = int(stdin.readline().rstrip())
	s = cur * (cur + 1) // 2
	pow_sum = 0
	cur_pow = 1
	while cur_pow <= cur:
		pow_sum += cur_pow
		cur_pow *= 2
	print(s - pow_sum - pow_sum)


t = int(input())
for _ in range(t):
	n = int(input())
	res = n * (n + 1) // 2
	num = 1
	while num <= n:
		res -= 2 * num
		num *= 2
	print(res)


import sys
inf = float('inf')
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
(mod, MOD) = (1000000007, 998244353)
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
T = int(input())
while T > 0:
	n = int(input())
	initial = n * (n + 1) // 2
	i = 1
	while i <= n:
		initial -= 2 * i
		i *= 2
	print(initial)
	T -= 1


n = int(input())
for i in range(n):
	j = 0
	d = 1
	t = int(input())
	c = t * (t + 1) // 2
	while d <= t:
		d *= 2
		j += 1
	print(c - 2 * d + 2)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	res = n * (n + 1) // 2
	power = int(math.log2(n))
	res -= 2 * (2 ** (power + 1) - 1)
	print(res)


import itertools as it
import functools
import operator
import collections
import math
import sys

def solve(x):
	simple_sum = x * (x + 1) // 2
	pow = -1
	while x > 0:
		x >>= 1
		pow += 1
	sum_power_of_twos = 2 ** (pow + 1) - 1
	return simple_sum - 2 * sum_power_of_twos

def p(*args, **kwargs):
	return print(*args, file=sys.stderr, **kwargs)

def main():
	t = int(input())
	xs = [int(input()) for _ in range(t)]
	results = [solve(x) for x in xs]
	for res in results:
		print(res)

def __starting_point():
	main()
__starting_point()


power = [0] * 31
pre = [0] * 31

def Sum(n):
	x = 1
	for i in range(31):
		power[i] = x
		x *= 2
	pre[0] = 1
	for i in range(1, 31):
		pre[i] = pre[i - 1] + power[i]
	ans = n * (n + 1) // 2
	for i in range(31):
		if power[i] > n:
			ans -= 2 * pre[i - 1]
			break
	return ans
n = int(input())
while n:
	t = int(input())
	print(Sum(t))
	n = n - 1


for _ in range(int(input())):
	n = int(input())
	sumi = n * (n + 1) // 2
	for i in range(0, 64):
		if 2 ** i <= n:
			sumi -= 2 * 2 ** i
		else:
			break
	print(sumi)


t = int(input())
for _ in range(t):
	n = int(input())
	s_all = n * (n + 1) // 2
	s_pow = 0
	i = 1
	while i < n + 1:
		s_pow += i
		i *= 2
	s_pow *= 2
	print(s_all - s_pow)


def enumeration(a):
	y = 0
	res = 0
	while 2 ** y <= a:
		res += -1 * 2 ** y
		y += 1
	return res * 2
t = int(input())
for i in range(t):
	n = int(input())
	sum = n * (n + 1) // 2
	print(sum + enumeration(n))


t = int(input())
L = [int(input()) for _ in range(t)]
from math import *
for i in range(t):
	r = L[i] * (L[i] + 1) // 2
	p = 1
	while p <= L[i]:
		p *= 2
		r = r - p
	print(r)


def sum_n(n):
	return n * (n + 1) // 2

def main():
	mode = 'filee'
	if mode == 'file':
		f = open('test.txt', 'r')
	get = lambda : [int(x) for x in (f.readline() if mode == 'file' else input()).split()]
	[t] = get()
	for z in range(t):
		[n] = get()
		hold = sum_n(n)
		j = 1
		while j <= n:
			j = j << 1
			hold -= j
		print(hold)
	if mode == 'file':
		f.close()

def __starting_point():
	main()
__starting_point()


import math
q = int(input())
for _ in range(q):
	n = int(input())
	ans = n * (n + 1) // 2
	for i in range(n):
		if 2 ** i <= n:
			ans -= 2 * 2 ** i
		else:
			break
	print(ans)


for i in range(int(input())):
	n = int(input())
	r = 1
	s = 0
	while r <= n:
		s += r
		r *= 2
	print(str(n * (n + 1) // 2 - 2 * s))


from math import *
for _ in range(int(input())):
	n = int(input())
	sn = n * (n + 1) // 2
	ln = int(log2(n))
	d = int(2 * (2 ** ln - 1)) + 1
	sn = sn - 2 * d
	print(sn)


for i in range(int(input())):
	n = int(input())
	r = 1
	while r <= n:
		r *= 2
	print(n * (n + 1) // 2 - 2 * (r - 1))


from math import log, floor

def solve(n):
	ans = n * (n + 1) // 2
	x = floor(log(n, 2))
	ans -= 2 ** (x + 2) - 2
	return ans
for _ in range(int(input())):
	n = int(input())
	print(solve(n))


def sumtwo(n):
	ans = 0
	i = 0
	while 2 ** i <= n:
		ans += 2 ** i
		i += 1
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	print(int(-2 * sumtwo(n) + (n + 1) * n // 2))


integer = int(input())
results = []

def calculate(n):
	total = (n + 1) * n // 2
	i = 1
	while i <= n:
		total -= 2 * i
		i *= 2
	return total
for case in range(integer):
	results.append(calculate(int(input())))
for result in results:
	print(result)


import math

def ans(n):
	first = n * (n + 1)
	terms_gp = math.floor(math.log2(n)) + 1
	second = -(1 - 2 ** terms_gp)
	return (first >> 1) - 2 * second
t = int(input())
for i in range(t):
	n = int(input())
	print(ans(n))


def solve(n):
	sum = (1 + n) * n // 2
	x = 1
	while x <= n:
		sum -= 2 * x
		x *= 2
	return sum
t = int(input())
for _ in range(t):
	print(solve(int(input())))


n = int(input())
for i in range(n):
	x = int(input())
	k = len(bin(x)) - 2
	an = x * (x + 1) // 2 - 2 * (2 ** k - 1)
	print(an)


n = int(input())
for i in range(n):
	x = int(input())
	y = 0
	z = x * (x + 1) // 2
	a = bin(x)[2:]
	for j in range(len(a)):
		y = y + 2 ** j
	print(z - 2 * y)


def genezis(n):
	ans = n * (n + 1) // 2
	i = 1
	while i <= n:
		ans -= 2 * i
		i *= 2
	return ans
t = int(input())
for i in range(t):
	n = int(input())
	print(genezis(n))


import math
for i in range(int(input())):
	step = 0
	m_sum = 0
	inp = int(input())
	print((inp * (inp + 1) >> 1) - ((1 << int(math.log(inp, 2) + 1)) - 1) * 2)


t = int(input())
for _ in range(t):
	inp = int(input())
	print(inp * (inp + 1) // 2 - 2 * (2 ** (len(bin(inp)) - 2) - 1))


from math import log2, floor
t = int(input())
for j in range(t):
	n = int(input())
	s = n * (n + 1) // 2
	k = floor(log2(n))
	p = 2 ** (k + 1) - 1
	print(s - 2 * p)


import math
t = int(input())
for i in range(t):
	n = int(input())
	t = int(math.log(n, 2)) + 2
	if n % 2 == 0:
		print(int(n / 2) * (n + 1) - 2 ** t + 2)
	else:
		print(int((n + 1) / 2) * n - 2 ** t + 2)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = n * (n + 1) // 2
	pw = 1
	while pw <= n:
		s -= 2 * pw
		pw *= 2
	print(s)


def sd(a):
	ans = 0
	i = 1
	while True:
		if i > a:
			break
		ans += i
		i *= 2
	return ans
n = int(input())
a = [int(input()) for i in range(n)]
for i in range(n):
	s = (a[i] + 1) * a[i] // 2 - sd(a[i]) * 2
	print(s)


def sumPower2(n):
	i = 0
	tot = 0
	while True:
		k = 2 ** i
		if k > n:
			return tot
		tot += 2 ** i
		i += 1
for _ in range(int(input())):
	n = int(input())
	nsum = n * (n + 1) // 2
	p2sum = sumPower2(n)
	print(nsum - 2 * p2sum)


import sys
from math import floor, sqrt, ceil, factorial, gcd, pi
from itertools import chain, combinations, permutations, accumulate
from collections import Counter, defaultdict, OrderedDict
from array import array
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
mod = 1000000007

def solve():
	t = int(sys.stdin.readline())
	for _ in range(t):
		n = int(sys.stdin.readline())
		tot = n * (n + 1) // 2
		i = 0
		while pow(2, i) <= n:
			tot -= 2 * pow(2, i)
			i += 1
		print(tot)
solve()


import math
t = int(input())
for _ in range(t):
	n = int(input())
	sumn = n * (n + 1) // 2
	max2p = math.floor(math.log(n) / math.log(2))
	sum2 = 2 ** (max2p + 1) - 1
	print(sumn - 2 * sum2)


import math
for x in range(int(input())):
	a = int(input())
	b = 1 + int(math.log2(a))
	print((a * a + a + 4 - 2 ** (b + 2)) // 2)


t = int(input())
for a in range(t):
	n = int(input())
	i = 1
	while 2 * i <= n:
		i *= 2
	ans = n * (n + 1) // 2 - 4 * i + 2
	print(ans)


a = int(input())
if a >= 1 and a <= 100:
	total = 0
	while a > 0:
		num = int(input())
		if num >= 1 and num <= 1000000000:
			time = 0
			while True:
				if num - 2 ** time < 0:
					break
				time += 1
			time = time - 1
			t = 0
			while time >= 0:
				t = t + 2 ** time
				time = time - 1
			total = (1 + num) * num // 2 - 2 * t
			print(total)
			total = 0
		a = a - 1


def main(t):
	resultados = []
	for i in range(t):
		n = int(input())
		res = n * (n + 1) // 2
		x = int(1)
		while x <= n:
			res -= 2 * int(x)
			x *= 2
		resultados.append(res)
	for j in resultados:
		print(j)
	return 0
num = int(input())
main(num)


import math
t = int(input())
for i in range(t):
	n = int(input())
	p = int(math.log2(n))
	t1 = n * (n + 1) // 2
	t2 = 2 ** (p + 1) - 1
	print(t1 - t2 - t2)


import math
import fractions
N = int(input())

def crazy_sum(N):
	arifmetic = fractions.Fraction(N * (1 + N), 2)
	if N == 1:
		return arifmetic - 2
	steps = int(math.floor(math.log2(N)))
	geometric = 2 * (1 - 2 ** steps) * -1 + 1
	return round(int(arifmetic - 2 * geometric))
for i in range(N):
	t = int(input())
	print(crazy_sum(t), flush=True)


t = int(input())
s = [1]
while s[-1] < 1000000000:
	s += [s[-1] * 2]
ans = []
for i in range(t):
	n = int(input())
	m = 0
	while s[m] < n:
		if s[m + 1] > n:
			break
		if s[m + 1] == n:
			m += 1
			break
		m += 1
	b = int('1' * (m + 1), 2)
	ans += [str((n + 1) * n // 2 - b - b)]
print('\n'.join(ans))


t = int(input())
result = list()
for i in range(t):
	n = int(input())
	s = n * (n + 1) // 2
	s1 = 1
	while s1 <= n:
		s -= s1 * 2
		s1 *= 2
	result.append(s)
for elem in result:
	print(elem)


def powLeqN(n):
	n = n | n >> 1
	n = n | n >> 2
	n = n | n >> 4
	n = n | n >> 8
	n = n | n >> 16
	return n
t = int(input())
for i in range(t):
	num = int(input())
	n = powLeqN(num)
	s = 2 * n
	ans = num * (num + 1) // 2
	ans -= s
	print(ans)


x = int(input())
for i in range(x):
	n = int(input())
	sum1 = 0
	i = 0
	while True:
		a = pow(2, i)
		if a > n:
			break
		else:
			sum1 = sum1 + a
		i += 1
	print(n * (1 + n) // 2 - 2 * sum1)


import math

def program():
	n = int(input())
	sum = n * (n + 1) // 2
	terms = int(math.log(n, 2)) + 1
	gpsum = 2 ** terms - 1
	ans = sum - 2 * gpsum
	print(ans)
t = int(input())
for i in range(t):
	program()


t = int(input())
while t > 0:
	k = int(input())
	sum2 = 0
	sum1 = k * (k + 1) >> 1
	i = 1
	while i <= k:
		sum2 = sum2 + i
		i *= 2
	print(sum1 - 2 * sum2)
	t -= 1


for x in range(int(input())):
	a = int(input())
	sum1 = a * (a + 1) // 2
	k = 0
	for i in range(a):
		if k < a:
			k = k + 2 ** i
		else:
			break
	print(sum1 - 2 * k)


t = int(input())
for _ in range(t):
	n = int(input())
	series_sum = n * (n + 1) // 2
	pow_of_two = 1
	while pow_of_two <= n:
		pow_of_two *= 2
	print(series_sum - 2 * pow_of_two + 2)


import sys

def powersOfTwo():
	i = 0
	while True:
		yield (2 ** i)
		i += 1
T = int(input())
for _ in range(T):
	N = int(input())
	ans = N * (N + 1) // 2
	for p in powersOfTwo():
		if p > N:
			break
		ans -= 2 * p
	print(ans)


t = int(input())
answers = []
for number in range(t):
	num = int(input())
	answers.append((1 + num) * num // 2)
	i = 1
	while i <= num:
		answers[number] -= 2 * i
		i *= 2
for i in answers:
	print(int(i))


for i in range(int(input())):
	x = int(input())
	s = x * (x + 1) // 2
	c = 1
	while c <= x:
		s -= c * 2
		c = c * 2
	print(s)


t = int(input())
for t in range(t):
	n = int(input())
	s = n * (n + 1) // 2
	v = 1
	while v < n + 1:
		s -= 2 * v
		v = v * 2
	print(s)


import math
t = int(input())
for i in range(t):
	n = int(input())
	a1 = int(math.log2(n)) + 1
	suma1 = n * (n + 1) // 2
	suma2 = 2 * (2 ** a1 - 1)
	print(suma1 - suma2)


for _ in range(int(input())):
	n = int(input())
	sum_all = n * (n + 1) // 2
	highest_pow_2 = 0
	curr = 1
	while curr <= n:
		curr *= 2
		highest_pow_2 += 1
	print(sum_all - 2 ** (highest_pow_2 + 1) + 2)


a = int(input())
for i in range(a):
	b = int(input())
	Sum = (b + 1) * b // 2
	power = 0
	while not 2 ** power > b:
		power += 1
	for j in range(power):
		Sum -= 2 * 2 ** j
	print(int(Sum))


def form_l(num):
	s = []
	i = 0
	while True:
		if 2 ** i > num:
			break
		s.append(2 ** i)
		i += 1
	s.append(2 ** i)
	return s

def cal_sum(k, s):
	re = (1 + k) * k // 2
	index1 = 0
	for i in range(len(s)):
		if s[i] > k:
			index1 = i
			break
	return re - 2 * sum(s[:index1])
num = int(input())
l = []
for i in range(num):
	l.append(int(input()))
is_2 = form_l(max(l))
for each in l:
	print(cal_sum(each, is_2))


def log2(n):
	i = 1
	while i <= n:
		i *= 2
	return i
t = int(input())
for i in range(t):
	n = int(input())
	print(n * (n + 1) // 2 - 2 * (log2(n) - 1))


def TwoThePowersum(n, sum):
	pow2 = 1
	iterate = 0
	while pow2 <= n:
		sum = sum - 2 ** iterate
		pow2 = 2 ** iterate
		iterate += 1
	return sum
test = int(input())
for i in range(test):
	number = int(input())
	sum = number * (number + 1) // 2
	ans = TwoThePowersum(number, sum)
	print(ans + 1)


def main():
	res = []
	for _ in range(int(input())):
		n = int(input())
		res.append(n * (n + 1) // 2 + 2 - (2 << n.bit_length()))
	print('\n'.join(map(str, res)))
main()


def solve():
	n = int(input())
	sm = (1 + n) * n // 2
	i = 1
	while i <= 1073741824:
		if i <= n:
			sm -= 2 * i
		else:
			break
		i *= 2
	print(sm)
t = int(input())
for i in range(t):
	solve()


def magic_sum(number):
	s = number * (number + 1) // 2
	powers = len(bin(number)) - 2
	minusStr = '1' * powers + '0'
	minus = int(minusStr, 2)
	return s - minus
n = int(input())
ans = []
for i in range(n):
	ans.append(magic_sum(int(input())))
for i in range(n):
	print(ans[i])


import math
t = int(input())
for i in range(t):
	num = int(input())
	sum = sum2 = 0
	k = 0
	while True:
		if int(2 ** k) > num:
			break
		else:
			k += 1
	for i in range(k):
		sum2 += 2 ** i
	sum = num * (num + 1) // 2
	print(sum - 2 * sum2)


n = int(input())
for i in range(n):
	k = int(input())
	aggiungi = k * (k + 1) // 2
	esp = 0
	while k > 1:
		k = k // 2
		esp += 1
	togli = (2 ** (esp + 1) - 1) * 2
	print(aggiungi - togli)


n = int(input())
for i in range(n):
	q = int(input())
	s = q * (q + 1) // 2
	w = 1
	while w <= q:
		s -= 2 * w
		w *= 2
	print(s)


import math

def main():
	t = int(input())
	for i in range(t):
		num = int(input())
		step_2 = 2 ** (math.floor(math.log(num, 2)) + 1) - 1
		print(num * (num + 1) // 2 - 2 * step_2)
main()


T = int(input())
for cas in range(T):
	n = int(input())
	res = n * (n + 1) // 2
	for i in range(40):
		if 1 << i > n:
			break
		else:
			res -= 2 * (1 << i)
	print(res)


nb_test = int(input())
for _ in range(nb_test):
	ins = int(input())
	sums = ins * (ins + 1) // 2
	twos = 1
	while twos <= ins:
		twos *= 2
		sums -= twos
	print(sums)


def foo():
	n = int(input())
	e = 0
	if n % 2 == 0:
		sm = (n + 1) * (n // 2)
	else:
		sm = (n + 2) * (n // 2 + 1) - (n + 1)
	while 2 ** e <= n:
		sm -= 2 * 2 ** e
		e += 1
	print(sm)
for _ in range(int(input())):
	foo()


T = int(input())

def solve(n):
	ans = n * (n + 1) // 2
	acc = 1
	while acc <= n:
		ans -= 2 * acc
		acc *= 2
	return ans
for t in range(T):
	N = int(input())
	print(solve(N))


for i in range(int(input())):
	x = int(input())
	ans = x * (x + 1) // 2
	sub = 1
	while sub <= x:
		ans -= 2 * sub
		sub *= 2
	print(ans)


from math import log
from math import floor
n = int(input())
for i in range(n):
	num = int(input())
	print(num * (num + 1) // 2 - 2 * (2 ** (floor(log(num, 2)) + 1) - 1))


def Pow(a):
	for i in range(31):
		a.append(Quick(2, i))
	return

def Quick(x, y):
	ans = 1
	while y:
		if y & 1:
			ans *= x
		x = x * x
		y = y >> 1
	return ans
import bisect
a = []
Pow(a)
t = eval(input())
while t:
	t -= 1
	n = eval(input())
	q = max(bisect.bisect(a, n), bisect.bisect_left(a, n))
	print(n * (n + 1) // 2 - 2 * (a[q] - 1))


two = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824]
n = int(input())
for _ in range(n):
	x = int(input())
	s = (1 + x) * x // 2
	for i in two:
		if i <= x:
			s -= 2 * i
		else:
			break
	print(s)


t = int(input())
total = []
for i in range(t):
	n = int(input())
	dos = 1
	pot = 0
	while dos <= n:
		pot += dos
		dos *= 2
	tot = (n + 1) * n // 2 - pot * 2
	total.append(int(tot))
for num in total:
	print(num)


table = [1 << i for i in range(32)]
testCases = int(input())
for _ in range(testCases):
	upper_bound = int(input())
	temp_sum = 0
	for binary_number in table:
		if binary_number <= upper_bound:
			temp_sum += binary_number
		else:
			break
	print(upper_bound * (upper_bound + 1) // 2 - 2 * temp_sum)


import sys
from math import log2

def solve():
	n = int(input())
	ans = n * (n + 1) // 2
	tt = int(log2(n))
	tt += 1
	q = 2
	rr = (1 - (1 << tt)) // (1 - q)
	ans -= 2 * rr
	return ans
t = int(input())
for i in range(t):
	print(solve())


import math
n = int(input())
ans = []
for i in range(0, n):
	x = int(input())
	if x % 2 == 1:
		ans.append(x * int((x + 1) / 2) - pow(2, int(math.log(x, 2) + 2)) + 2)
	else:
		ans.append(int(x / 2) * (x + 1) - pow(2, int(math.log(x, 2) + 2)) + 2)
for i in range(0, n):
	print(ans[i])


for i in range(int(input())):
	n = int(input())
	s = n * (n + 1) // 2
	b = 0
	m = pow(2, b)
	while m <= n:
		s -= 2 * m
		b += 1
		m = pow(2, b)
	print(s)


x = int(input())
for i in range(x):
	y = int(input())
	n = 0
	while 2 ** n <= y:
		n = n + 1
	sum = y * (y + 1) // 2 - 2 * (2 ** n - 1)
	print(sum)


k = int(input())
for i in range(k):
	num = int(input())
	result = num * (num + 1) // 2
	i = 1
	while i <= num:
		result -= 2 * i
		i *= 2
	print(int(result))


num_queries = int(input())
for _ in range(num_queries):
	n = int(input())
	power = 1
	total = n * (n + 1) // 2
	while power <= n:
		total -= power * 2
		power *= 2
	print(total)


def count(n):
	sum = (1 + n) * n // 2
	multiplier = 1
	factor = 2
	while multiplier <= n:
		sum -= 2 * multiplier
		multiplier *= factor
	return sum
t = int(input())
results = [0] * t
for i in range(t):
	n = int(input())
	results[i] = count(n)
for ans in results:
	print(ans)


n = int(input())
k = 1
for i in range(1, n + 1):
	b = int(input())
	rez = b * (b + 1) // 2
	k = 1
	while k <= b:
		rez -= k * 2
		k *= 2
	print(rez, end='\n')


n = int(input())
for i in range(n):
	t = int(input())
	bint = str(bin(t))[2:]
	pows = len(bint) - 1
	print((1 + t) * t // 2 - (-1 + 2 ** (pows + 1)) * 2)


l = []
for i in range(31):
	l += [2 ** i]
for i in range(int(input())):
	n = int(input())
	s = n * (n + 1) // 2
	t = []
	for i in l:
		if i <= n:
			t += [i]
		else:
			print(s - 2 * sum(t))
			break


import math
for _ in range(int(input())):
	n = int(input())
	n1 = int(math.log(n, 2))
	s = n * (n + 1) // 2
	y = sum([2 ** x for x in range(n1 + 1)])
	print(s - 2 * y)


t = int(input())
d = []
i = 1
while i <= 1000000000:
	d.append(i)
	i *= 2
for i in range(t):
	n = int(input())
	s = n * (n + 1) // 2
	for k in d:
		if k <= n:
			s -= 2 * k
	print(s)


tc = int(input())
for _ in range(tc):
	n = int(input())
	res = n * (n + 1) // 2
	for i in range(30):
		if 2 ** i <= n:
			res -= 2 ** (i + 1)
	print(res)


import math
tc = int(input())
while tc != 0:
	tc -= 1
	n = int(input())
	print(n * (n + 1) // 2 - 2 * (2 ** (int(math.log2(n)) + 1) - 1))


import math
t = int(input())
for i in range(t):
	k = int(input())
	ans = k * (k + 1) // 2
	pw = 2 ** (math.floor(math.log2(k)) + 1) - 1
	print(ans - 2 * pw)


import math as m
t = int(input())
for i in range(t):
	n = int(input())
	ans = n * (n + 1) // 2
	power = 1
	while power <= n:
		power *= 2
	power -= 1
	ans = ans - 2 * power
	print(ans)


t = int(input())
for i in range(0, t):
	n = int(input())
	s = (n + n * n) // 2
	d = 1
	while d <= n:
		s -= d * 2
		d *= 2
	print(s)


T = int(input())
while T:
	T -= 1
	n = int(input())
	ans = (1 + n) * n // 2
	i = 1
	while i <= n:
		ans -= i * 2
		i *= 2
	print(ans)


import itertools
o = [2 ** i for i in itertools.takewhile(lambda x: 2 ** x < 10 ** 9, itertools.count())]
c = int(input()) + 1
for c in range(1, c):
	n = int(input())
	a = [x for x in o if x <= n]
	s = n * (n + 1) // 2 - 2 * sum([x for x in o if x <= n])
	print(s)


for t in range(int(input())):
	n = int(input())
	deg = 1
	while deg <= n:
		deg <<= 1
	print(n * (n + 1) // 2 - 2 * (deg - 1))


def solve(n):
	s = n * (n + 1) // 2
	m = 0
	while 2 ** m <= n:
		s -= 2 ** (m + 1)
		m += 1
	return s
N = int(input())
for p in range(N):
	print(solve(int(input())))


q = int(input())
for _ in range(q):
	n = int(input())
	if n > 1:
		bin_n = bin(n)[3:]
		step_two = n - int(bin_n, 2)
		print((1 + n) * n // 2 - step_two * 4 + 2)
	else:
		print(-1)


for _ in range(int(input())):
	(t, p) = (int(input()), 0)
	sum = t * (t + 1) // 2
	for x in range(t + 1):
		if 1 << x > t:
			break
		else:
			p -= 1 << x
	print(sum + 2 * p)


t = int(input())
l = []
for i in range(t):
	n = int(input())
	j = 0
	s = 0
	while pow(2, j) <= n:
		s = s + pow(2, j)
		j += 1
	total = n * (n + 1) // 2
	y = total - s
	l.append(-1 * s + y)
for k in l:
	print(k)


two = []
power = 0
while 2 ** power <= 10 ** 9:
	two.append(2 ** power)
	power += 1
for _ in range(int(input())):
	n = int(input())
	value = n * (n + 1) // 2
	two_value = 0
	for val in two:
		if val > n:
			break
		two_value += val
	print(value - 2 * two_value)


import sys
t = int(input())
for i in range(t):
	n = int(input())
	sum = n * (n + 1) // 2
	for i in range(30):
		if 1 << i <= n:
			sum = sum - 2 * (1 << i)
	print(sum)


import math
from decimal import Decimal
n = input()
n = int(n)
for i in range(n):
	curr = input()
	curr = Decimal(curr)
	ans = curr * (curr + 1)
	ans /= 2
	minus = Decimal(math.log2(curr))
	minus = math.floor(minus)
	minus = pow(2, minus + 1) - 1
	ans -= minus
	ans -= minus
	ans = int(ans)
	print(ans)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
T = int(input())
for i in range(T):
	n = int(input())
	total = n * (n + 1) // 2
	i = 0
	while 2 ** i <= n:
		total -= 2 ** (i + 1)
		i += 1
	print(total)


n = int(input())
for i in range(n):
	a = int(input())
	s = (1 + a) * a // 2
	pl = 1
	while pl <= a:
		s -= 2 * pl
		pl *= 2
	print(s)


N = int(input())
for _ in range(N):
	a = int(input())
	b = a.bit_length()
	res = a * (a + 1) // 2 - (2 ** b - 1) * 2
	print(res)


def log(x):
	(l, r) = (-1, 32)
	while r - l > 1:
		m = (r + l) // 2
		if pow(2, m) <= x:
			l = m
		else:
			r = m
	if l < 0:
		return r
	return l

def sum_range(l, u):
	v1 = l * (l + 1) // 2
	v2 = u * (u - 1) // 2
	return v2 - v1
t = int(input())
for _ in range(t):
	n = int(input())
	lg = log(n)
	s = 0
	for i in range(lg):
		low = 2 ** i
		up = 2 ** (i + 1)
		s -= low
		s += sum_range(low, up)
	s -= 2 ** lg
	s += sum_range(2 ** lg, n + 1)
	print(s)


for i in range(int(input())):
	x = int(input())
	y = len(bin(x)) - 2
	s = 2 ** y - 1
	print(x * (x + 1) // 2 - 2 * s)


for _ in range(int(input())):
	n = int(input())
	ans = n * (n + 1) // 2
	pow2 = 1
	while pow2 <= n:
		ans -= pow2 * 2
		pow2 *= 2
	print(ans)


t = int(input())
i = 1
while i <= t:
	x = int(input())
	all_numbers = x * (x + 1) // 2
	m = 0
	n = 0
	while n < x:
		n = 2 ** (m + 1) - 1
		m += 1
	m -= 1
	r = 2 ** (m + 1) - 1
	r = -r
	result = all_numbers + r
	print(int(r + result))
	i += 1


cou = int(input())
m = []
minus = 0
st = 0
for i in range(cou):
	m.append(int(input()))
for i in range(len(m)):
	st = 0
	summa = 0
	minus = 0
	summa = (1 + m[i]) * m[i] // 2
	while minus < m[i]:
		minus += 2 ** st
		st += 1
	print(summa - minus * 2)


for _ in range(int(input().strip())):
	n = int(input().strip())
	binS = str(bin(n))[2:]
	x = len(binS) - binS.index('1') - 1
	print(n * (n + 1) // 2 - pow(2, x + 2) + 2)


for i in range(int(input())):
	N = int(input())
	twos = 0
	total = N * (N + 1) // 2
	while N > 1:
		twos += 1
		N = N // 2
	print(int(total - 2 * (2 ** (twos + 1) - 1)))


import math
x = int(input())
for i in range(x):
	n = int(input())
	sqreSum = 2 ** int(math.log2(n) + 1) - 1
	ans = n * (n + 1) // 2 - 2 * sqreSum
	print(ans)


for t in range(int(input())):
	n = int(input())
	sum1 = n * (n + 1) // 2
	for i in range(31):
		if 2 ** i > n:
			break
		sum1 = sum1 - 2 * 2 ** i
	print(sum1)


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	SUM = (1 + n) * n // 2
	for i in range(35):
		if 2 ** i <= n:
			SUM -= 2 * 2 ** i
	print(SUM)


from math import *
a = int(input())
for i in range(a):
	b = int(input())
	c = log(b) / log(2)
	c = int(c)
	half = 2 ** c + 2 ** c - 1
	total = b * (b + 1) // 2
	total = total - half
	print(int(total - half))


import math
t = int(input())
while t:
	t -= 1
	n = int(input())
	s = n * (n + 1) // 2
	i = 1
	while i <= n:
		s = s - 2 * i
		i = i * 2
	print(s)


def tricky(n):
	st = 1
	res = n * (n + 1) // 2
	while st <= n:
		st *= 2
		res -= st
	return res
m = int(input())
for i in range(m):
	print(tricky(int(input())))


for __ in range(int(input())):
	a = int(input())
	i = 1
	while i <= a:
		i *= 2
	print(a * (a + 1) // 2 - 2 * (i - 1))


t = int(input())
for i in range(0, t):
	n = int(input())
	pow_of_two = 1
	answer = n * (n + 1) // 2
	n >>= 1
	while n:
		pow_of_two <<= 1
		answer -= 2 * pow_of_two
		n >>= 1
	print(answer - 2)


max_n = 1000 * 1000 * 1000
t = int(input())
power_of_two = [1]
sum_of_two = [1]
while power_of_two[-1] * 2 <= max_n:
	power_of_two.append(power_of_two[-1] * 2)
	sum_of_two.append(sum_of_two[-1] + power_of_two[-1])
for i in range(0, t):
	n = n1 = int(input())
	n2 = n1 + 1
	if n1 % 2 == 0:
		n1 //= 2
	else:
		n2 //= 2
	sum = n1 * n2
	index = 0
	for x in power_of_two:
		if 2 * x > n:
			index = power_of_two.index(x)
			break
	print(sum - 2 * sum_of_two[index])


t = int(input())
i = 0
a = []
for i in range(t):
	a.append(0)
	a[i] = int(input())
d = 1
s = 0
for i in range(t):
	s = a[i] * (a[i] + 1) // 2
	while d <= a[i]:
		s -= 2 * d
		d *= 2
	print(s)
	d = 1
	s = 0


t = int(input())
for i in range(0, t):
	n = int(input())
	p = 1
	subSum = 0
	while p <= n:
		subSum += p
		p *= 2
	print(int((n + 1) * n // 2 - 2 * subSum))


from math import log
t = int(input().strip())
ll = []
for i in range(t):
	l = int(input().strip())
	ll.append(l * (l + 1) // 2 - 2 * (2 ** int(log(l, 2) + 1) - 1))
for i in range(t):
	print(ll[i])


import math
for _ in range(int(input())):
	n = int(input())
	totalSum = n * (n + 1) // 2
	val = int(math.floor(math.log2(n)))
	powerSum = int(math.pow(2, val + 1) - 1)
	totalSum -= 2 * powerSum
	print(totalSum)


import math

def hpn(num):
	a = []
	p = int(math.log(num, 2))
	for i in range(p + 1):
		a.append(2 ** i)
	return a
for _ in range(int(input())):
	n = int(input())
	x = hpn(n)
	s = n * (n + 1) // 2
	print(s - 2 * sum(x))


from math import log
a = input()
b = []
for i in range(int(a)):
	b.append(int(input()))

def sumLessPowersOfTwo(N):
	sumToN = int(N * (1 + N) // 2)
	n = int(log(N, 2) + 1)
	sumOfTwos = 2 ** n - 1
	return sumToN - 2 * sumOfTwos
for i in b:
	print(sumLessPowersOfTwo(i))


t = int(input())
a = 1
d = 1
for i in range(t):
	n = int(input())
	sum = a * n + n * (n - 1) * d // 2
	for i in range(n):
		h = pow(2, i)
		if h > n:
			break
		sum = sum - 2 * h
	print(sum)


T = int(input())
for t in range(T):
	n = int(input())
	sum = n * (n + 1) // 2
	x = 1
	while x <= n:
		sum -= 2 * x
		x *= 2
	print(sum)


t = int(input())
for i in range(t):
	n = int(input())
	sum = n * (n + 1) // 2
	digits = 1
	while n >> digits != 0:
		digits += 1
	sum -= 2 * ((1 << digits) - 1)
	print(sum)


import sys
import math
import bisect

def main():
	for _ in range(int(input())):
		n = int(input())
		ans = n * (n + 1) // 2
		tmp = 0
		i = 1
		while i <= n:
			tmp += i
			i <<= 1
		print(ans - tmp - tmp)
main()


from math import log
n = int(input())
for i in range(n):
	x = int(input())
	k = int(log(x, 2)) + 1
	s = x * (x + 1) // 2
	tricky_sum = s - 2 * (2 ** k - 1)
	print(tricky_sum)


t = int(input())
for _ in range(t):
	n = int(input())
	s = (n + 1) * n // 2
	i = 1
	while True:
		if i <= n:
			s -= 2 * i
			i *= 2
		else:
			break
	print(s)


from math import *

def getsum(n):
	s = getmax2(n)
	res = (n + 1) * n // 2 - 4 * s + 2
	return res

def getmax2(n):
	return 2 ** int(log(n, 2))
n = int(input())
for i in range(n):
	print(getsum(int(input())))


t = int(input())
for _ in range(t):
	n = int(input())
	s = 1
	while s <= n:
		s = s << 1
	ss = n // 2 * (n + 1) if n % 2 == 0 else (n + 1) // 2 * n
	print(ss - (s << 1) + 2)


for num in range(int(input())):
	factor = 1
	to_sub = 0
	limit = int(input())
	while factor <= limit:
		to_sub += factor
		factor *= 2
	print((1 + limit) * limit // 2 - 2 * to_sub)


from math import log2
n = int(input())
for i in range(n):
	nn = int(input())
	sq = int(log2(nn))
	sum = nn * (nn + 1) // 2
	po = 1 << sq
	print(sum - (po * 2 + (po - 1) * 2))


import math
for _ in range(int(input())):
	n = int(input())
	f = 1 << int(math.log(n, 2)) + 1
	print(int(n * (1 + n) // 2 - 2 * (-1 * (1 - f))))


numbers = int(input())
answer = list()
while numbers != 0:
	number = int(input())
	sub = 1
	maxVal = number * (number + 1) // 2
	i = 2
	while i <= number:
		sub += i
		i *= 2
	maxVal -= 2 * sub
	answer.append(maxVal)
	numbers -= 1
print(*answer, sep='\n')


import math

def gauss_sum(n):
	return int(n * (n + 1) // 2)

def power_two_sum(n):
	if n == 0:
		return 0
	x = int(math.log(n, 2))
	return 2 ** (x + 1) - 1
num_lines = int(input())
inputs = []
for i in range(num_lines):
	inputs.append(int(input()))
for i in inputs:
	res = gauss_sum(i) - 2 * power_two_sum(i)
	print(res)


t = int(input())
array = []
for i in range(t):
	array.append(int(input()))
for i in range(t):
	n = 0
	alg_sum = int(array[i] * (1 + array[i]) // 2)
	while array[i] > 0:
		array[i] = int(array[i] / 2)
		n += 1
	alg_sum -= 2 * (1 - 2 ** n) // (1 - 2)
	print(alg_sum)


import sys
t = int(input())
for i in range(t):
	n = int(input())
	sum = n * (n + 1) // 2
	mask = 1
	while mask <= n:
		sum -= mask << 1
		mask <<= 1
	print(sum)


import math
t = int(input())
for i in range(0, t):
	n = int(input())
	a = n * (n + 1) // 2
	x = math.log(n, 2)
	x = int(x)
	b = 2 * (pow(2, x + 1) - 1)
	print(a - b)


n = int(input())
l = n * [0]
for i in range(n):
	a = int(input())
	l[i] = a * (a + 1) // 2 - 2 * (2 ** (len(bin(a)) - 2) - 1)
for i in l:
	print(i)


import sys
import math
line = sys.stdin.readline()
numInputs = int(line)
outputs = [0] * numInputs
for i in range(numInputs):
	num = int(sys.stdin.readline())
	total = num * (num + 1) // 2
	max2 = int(math.log(num, 2))
	neg = 2 ** (max2 + 1) - 1
	outputs[i] = int(total - neg * 2)
for i in range(numInputs):
	sys.stdout.write(str(outputs[i]) + '\n')


for i in range(int(input())):
	power = 1
	n = int(input())
	Sum = n * (n + 1) // 2
	while power <= n:
		Sum -= power * 2
		power *= 2
	print(Sum)


import math
for i in range(int(input())):
	z = int(input())
	s = int(math.log(z, 2))
	print(z * (z + 1) // 2 - (2 ** (s + 1) - 1) * 2)


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


t = int(input())
res = []
for _ in range(t):
	n = int(input())
	r = n * (n + 1) // 2
	i = 1
	while i <= n:
		r -= 2 * i
		i *= 2
	res += [str(r)]
print('\n'.join(res))


n = int(input())
result = ''
for i in range(n):
	t = int(input())
	s = (t + 1) * t // 2
	cur2 = 1
	while cur2 <= t:
		s -= cur2 * 2
		cur2 *= 2
	result += str(s) + '\n'
print(result)


from math import log
for i in range(int(input())):
	n = int(input())
	x = int(log(n, 2))
	s = 0
	for j in range(x + 1):
		s += 2 ** j
	print(n * (n + 1) // 2 - 2 * s)


t = int(input())

def quad(n):
	i = 0
	s = 0
	while True:
		cnt = 2 ** i
		if cnt <= n:
			s += cnt
		else:
			return s
		i += 1
for _ in range(t):
	n = int(input())
	su = ((1 + n) * n - 4 * quad(n)) // 2
	print(int(su))


n = int(input())
sums = [0 for i in range(n)]
for i in range(n):
	num = int(input())
	if num % 2 == 0:
		sums[i] = (num + 1) * (num >> 1)
	else:
		sums[i] = num * (num - 1 >> 1) + num
	to_devide = 1
	while to_devide <= num:
		sums[i] -= to_devide << 1
		to_devide = to_devide << 1
for res in sums:
	print(res)


m = int(input())
k = []
import math
while m > 0:
	k = k + [int(input())]
	m = m - 1
s = []
while m < len(k):
	n = k[m]
	sq = (1 + n) * n // 2
	i = int()
	while 2 ** i <= n:
		sq = sq - 2 * 2 ** i
		i = i + 1
	s = s + [sq]
	m = m + 1
m = 0
while m < len(s):
	print(s[m])
	m = m + 1


import math
t = int(input())
while t > 0:
	n = int(input())
	ans = n * (n + 1) // 2
	x = math.log2(n)
	y = 2 ** (int(x) + 1) - 1
	ans -= 2 * y
	if n == 1:
		ans = -1
	print(ans)
	t = t - 1


q = int(input())
for i in range(q):
	w = int(input())
	x = 0
	x = (1 + w) * (w // 2)
	if w % 2 != 0:
		x += w // 2 + 1
	for j in range(30):
		b = 2 ** j
		if b <= w:
			x -= b * 2
	print(x)


for i in range(int(input())):
	a = int(input())
	(Sum, counter) = (0, 1)
	while counter <= a:
		Sum += counter
		counter *= 2
	print(a * (a + 1) // 2 - 2 * Sum)


num_of_test_cases = int(input())
for _ in range(num_of_test_cases):
	n = int(input())
	(val, summation) = (1, 0)
	while val <= n:
		summation += val
		val *= 2
	sum_n_terms = n * (n + 1) // 2
	final_ans = sum_n_terms - 2 * summation
	print(final_ans)


n = int(input())
for k in range(n):
	a = int(input())
	suma = a * (a + 1) // 2
	i = 0
	while 2 ** i <= a:
		suma -= 2 ** i * 2
		i += 1
	print(suma)


for _ in range(int(input())):
	n = int(input())
	b = 1
	while b <= n:
		b *= 2
	print(n * (n + 1) // 2 - 2 * (b - 1))


a = []
i = 0
k = pow(2, i)
while k <= 1000000000:
	k = pow(2, i)
	a.append(k)
	i = i + 1
t = int(input())
for i in range(t):
	n = int(input())
	total = 0
	for i in range(len(a)):
		if a[i] <= n:
			total = total + a[i]
		else:
			break
	total1 = int(n * (n + 1) // 2)
	print(total1 - 2 * total)


for _ in ' ' * int(input()):
	a = int(input())
	s = 1
	i = 1
	while True:
		z = 2 * s
		if z <= a:
			s = z
			i += 1
		else:
			break
	print(-2 * (2 ** i - 1) + (a + 1) * a // 2)


from math import log, floor
t = int(input())
for i in range(t):
	n = int(input())
	a = floor(log(n, 2))
	sum1 = (1 + n) * n // 2
	sum2 = 2 ** (a + 1) - 1
	print(sum1 - 2 * sum2)


import math
t = int(input())
for w in range(t):
	n = int(input())
	s = n * (n + 1) // 2
	k = int(math.log2(n))
	s1 = pow(2, k + 1) - 1
	print(s - 2 * s1)


t = int(input())
while t:
	n = int(input())
	s = n * (n + 1) // 2
	k = len(format(n, 'b'))
	s_pair = 2 ** k - 1
	print(s - 2 * s_pair)
	t -= 1


import math
t = int(input())
for a in range(t):
	n = int(input())
	pa = n * (1 + n) // 2
	v = int(math.log(n, 2)) + 1
	pg = 2 ** v - 1
	soma = pa - 2 * pg
	print(int(soma))


import sys

class Scanner:

	def __init__(self):
		self.current_tokens = []

	def remaining_tokens(self):
		return len(self.current_tokens)

	def nextline(self):
		assert self.remaining_tokens() == 0, 'Reading next line with remaining tokens'
		return input()

	def nexttokens(self):
		return self.nextline().split()

	def nexttoken(self):
		if len(self.current_tokens) == 0:
			self.current_tokens = self.nexttokens()
		assert self.remaining_tokens() > 0, 'Not enough tokens to parse.'
		return self.current_tokens.pop(0)

	def nextints(self, n=-1):
		if n == -1:
			return list(map(int, self.nexttokens()))
		else:
			return [self.nextint() for i in range(n)]

	def nextint(self):
		return int(self.nexttoken())

def quit():
	sys.exit(0)
stdin = Scanner()
nextint = stdin.nextint
nextints = stdin.nextints
nextline = stdin.nextline
T = nextint()
for i in range(T):
	n = nextint()
	s = n * (n + 1) // 2
	p = 1
	while p <= n:
		s -= p * 2
		p = p * 2
	print(int(s))


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	res = n * (n + 1) // 2
	i = 1
	while i <= n:
		res -= 2 * i
		i *= 2
	print(res)
t = int(input())
for i in range(t):
	solve()


import math
t = int(input())
for i in range(t):
	n = int(input())
	z = n * (n + 1) // 2
	x = int(math.log2(n))
	s = 1 + 2 * (2 ** x - 1)
	print(z - 2 * s)


from math import log2
for _ in range(int(input())):
	n = int(input())
	sum1 = n * (n + 1) // 2
	sum2 = int(pow(2, int(log2(n)) + 1) - 1)
	print(sum1 - 2 * sum2)


def printCount(n):
	d = n * (n + 1) // 2
	ms = mostSignificant(n)
	print(d - 2 * ((ms << 1) - 1))

def mostSignificant(n):
	i = -1
	while n > 0:
		n = n & i
		i = i << 1
	return -i >> 2
t = int(input())
arr = []
for i in range(t):
	arr.append(int(input()))
for i in range(t):
	printCount(arr[i])


count = int(input())
for i in range(0, count):
	number = int(input())
	sum = (1 + number) * number // 2
	sum_square = 0
	for num in range(0, number + 1):
		square = 2 ** num
		if square <= number:
			sum_square += square
		else:
			break
	print(sum - sum_square * 2)


import logging
import copy
import sys
import functools
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

def solve(n):
	s = (1 + n) * n // 2
	l = 1
	pow2 = 1
	while True:
		l *= 2
		if l <= n:
			pow2 += l
		else:
			break
	log(l, pow2)
	return s - 2 * pow2

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		print(solve(n))

def log(*message):
	logging.debug(message)
main()


t = int(input())
while t:
	n = int(input())
	Sum = n * (n + 1) // 2
	(sub, i) = (0, 1)
	while i <= n:
		sub += i
		i <<= 1
	print(Sum - 2 * sub)
	t -= 1


import math
for t in range(int(input())):
	n = int(input())
	x = int(math.log(n, 2))
	s = 0
	for i in range(x + 1):
		s = s + 2 ** i
	y = n * (n + 1) // 2
	print(y - 2 * s)


def sum_of_all(n: int) -> int:
	if n % 2 == 0:
		return n // 2 * (n + 1)
	else:
		return (n + 1) // 2 * n

def sum_of_powers(n: int) -> int:
	sum = 0
	current_power = 1
	while current_power <= n:
		sum += current_power
		current_power *= 2
	return sum
t = int(input())
for i in range(t):
	n = int(input())
	print(sum_of_all(n) - 2 * sum_of_powers(n))


def solve(n):
	a = (1 + n) * n // 2
	(p, b) = (1, 0)
	while p <= n:
		b += p
		p *= 2
	return a - 2 * b

def main():
	for _ in range(int(input())):
		n = int(input())
		print(solve(n))
main()


import sys
from math import log2

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().strip('\n')
for _ in range(int(input())):
	n = int(input())
	s = n * (n + 1) // 2
	term = int(log2(n))
	g = 2 ** (term + 1) - 1
	print(s - 2 * g)


n = int(input())
for _ in range(n):
	m = int(input())
	s1 = m * (m + 1) // 2
	k = 1
	while k <= m:
		k *= 2
	s2 = 2 * (k - 1)
	print(s1 - s2)


test = int(input())
for _ in range(test):
	n = int(input())
	ans = n * (n + 1) // 2
	i = 1
	while i <= n:
		ans -= 2 * i
		i += i
	print(ans)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		(power, s, chk) = (0, 0, 1)
		while chk <= n:
			s += chk
			power += 1
			chk = pow(2, power)
		print(n * (n + 1) // 2 - 2 * s)
main()


import math
t = int(input())
s = []
r = []
for i in range(1, t + 1):
	s.append(int(input()))
a = [int(2 ** i) for i in range(0, math.ceil(math.log2(10 ** 9)) + 1)]
for i in s:
	summ = i * (i + 1) // 2
	z = summ - sum(a[:int(math.log2(i)) + 1]) * 2
	r.append(z)
for x in r:
	print(x)


t = int(input())
for _ in range(t):
	n = int(input())
	x = n * (n + 1) // 2
	i = 0
	while 2 ** i <= n:
		x -= 2 ** (i + 1)
		i += 1
	print(x)


tests = int(input())
for i in range(tests):
	n = int(input())
	ans = n * (n + 1) // 2
	p2 = 1
	while p2 <= n:
		ans -= p2 * 2
		p2 *= 2
	print(ans)


def answer(n):
	opredelitel_Stepeni = 1
	sum_step = 0
	while opredelitel_Stepeni <= n:
		sum_step += opredelitel_Stepeni
		opredelitel_Stepeni *= 2
	summ = n * (n + 1) // 2 - sum_step * 2
	return summ
t = int(input())
while t > 0:
	n = int(input())
	print(answer(n))
	t = t - 1


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'
import math

def solve():
	t = int(input())
	for _ in range(t):
		n = int(input())
		cout << int(n * (n + 1) // 2 - int(2 * (math.pow(2, int(math.log2(n)) + 1) - 1))) << endl

def main():
	solve()
main()


n = int(input())
for _ in range(n):
	x = int(input())
	res = x * (x + 1) // 2
	pow2 = 1
	while pow2 <= x:
		res -= 2 * pow2
		pow2 *= 2
	print(res)


import math
t = int(input())
for _ in range(t):
	num = int(input())
	gpn = math.floor(math.log(num) / math.log(2) + 1)
	nsum = num * (num + 1) // 2
	gpsum = pow(2, gpn) - 1
	print(int(nsum - 2 * gpsum))


def solve(n):
	ans = n * (n + 1) // 2
	pows = (1 << len(bin(n)) - 2) - 1
	return ans - pows * 2
t = int(input())
for i in range(t):
	n = int(input())
	print(solve(n))


t = int(input())
for i in range(t):
	n = int(input())
	l = -1
	k = 0
	while 2 ** k <= n:
		k += 1
	if n > 1:
		l -= 2
	if n > 2:
		l += 3
	if n > 3:
		l -= 2 ** 2
		for i in range(3, k):
			a = 2 ** (i - 1)
			b = 2 ** i
			l -= b
			l += (b + a) * (b - a - 1) // 2
		if 2 ** (k - 1) < n:
			l += (2 ** (k - 1) + 1 + n) * (n - 2 ** (k - 1)) // 2
	print(l)


def main():
	N = int(input())
	twopows = [2 ** i for i in range(31)]
	for i in range(N):
		a = int(input())
		ans = 0
		for t in twopows:
			if a < t:
				break
			ans -= t * 2
		ans += a * (a + 1) // 2
		print(ans)
main()


L = [2 ** k for k in range(31)]
L[-1] = 10 ** 9 + 1

def d(L, n, i):
	for k in range(1, n):
		if L[k - 1] <= i < L[k]:
			return k - 1
n = int(input())
for k in range(n):
	s = int(input())
	print(s * (s + 1) // 2 + 2 * (1 - 2 ** (d(L, 31, s) + 1)))


n = int(input())
for i in range(n):
	a = int(input())
	t1 = a * (a + 1) // 2
	p = 1
	while a >= 1:
		a //= 2
		p += 1
	t1 -= 2 ** p
	print(t1 + 2)


from sys import stdin
import math
t = int(stdin.readline())
for i in range(0, t):
	n = int(stdin.readline())
	a = (1 + n) * n // 2
	b = -int(2 * (1 - math.pow(2, int(math.log(n, 2) + 1))))
	print('%d' % (a - b))


import math
l = []
for i in range(30):
	a = pow(2, i)
	if a <= pow(10, 9) + 1:
		l.append(a)
zz = int(input())
for aa in range(zz):
	n = int(input())
	som = n * (n + 1) // 2
	s = 0
	for j in l:
		if j <= n:
			s = s + j
	print(int(som) - 2 * int(s))


for i in range(int(input())):
	n = int(input())
	res = n * (n + 1) // 2
	down = 1
	while down <= n:
		down *= 2
		res -= down
	print(res)


t = int(input())
for j in range(t):
	n = int(input())
	sum1 = n * (n + 1) >> 1
	ct = 0
	while 1 << ct <= n:
		sum1 -= 2 * (1 << ct)
		ct += 1
	print(sum1)


def sol():
	n = int(input())
	tot = n * (n + 1) // 2
	sub = 0
	p = 1
	while p <= n:
		sub += p
		p <<= 1
	print(tot - sub * 2)
cas = int(input())
for i in range(cas):
	sol()


for i in range(int(input())):
	S = int(input())
	if S % 2 == 0:
		Sum = (1 + S) // 2 * (S + 1)
	else:
		Sum = (1 + S + 1) // 2 * S
	j = 1
	a = 0
	while j <= S:
		Sum = Sum - j * 2
		j = j * 2
	print(Sum)


def sum_func(n):
	a = (n + 1) * n // 2
	k = 1
	while k <= n:
		a = a - k * 2
		k = k * 2
	return a
t = int(input())
k = 0
while k < t:
	v = int(input())
	print(sum_func(v))
	k = k + 1


from math import log
for x in range(int(input())):
	n = int(input())
	a = n * (n + 1) // 2
	b = 0
	p = 0
	while p <= log(n, 2):
		b += 2 ** p
		p += 1
	print(a - 2 * b)


a = int(input())
for i in range(a):
	b = int(input())
	sum = b * (b + 1) // 2
	n = 0
	negsum = 0
	while 2 ** n <= b:
		negsum = negsum + 2 ** n
		n = n + 1
	total = sum - 2 * negsum
	print(total)


from sys import stdin, stdout
import math
T = int(stdin.readline())
for __ in range(T):
	N = int(input())
	sn = N * (N + 1) // 2
	pow = int(math.log(N, 2))
	s2 = 2 ** (pow + 1) - 1
	print(sn - 2 * s2)


for _ in [0] * int(input()):
	n = int(input())
	s = (n + 1) * n // 2
	p = 1
	while p <= n:
		s -= 2 * p
		p <<= 1
	print(s)


import math

def TrickySum(n):
	if n % 2 == 0:
		sum = int(n / 2) * (n + 1)
	else:
		sum = int((n + 1) / 2) * n
	sub = 0
	for i in range(0, n + 1):
		power = 2 ** i
		if power > n:
			return sum - sub
		elif power <= n:
			sub += power * 2
	sum = sum - sub
	return int(sum)
for _ in range(int(input())):
	x = TrickySum(int(input()))
	print(int(x))


from math import *
a = int(input())
for i in range(a):
	per = int(input())
	answer = per * (per + 1) // 2
	answer -= 2 * (2 ** (int(log2(per)) + 1) - 1)
	print(answer)


from sys import stdin, stdout
import math
t = int(stdin.readline())
for i in range(t):
	n = int(stdin.readline())
	suma_i = int(n * (n + 1) // 2)
	m = 1
	while m <= n:
		suma_i += -2 * m
		m *= 2
	print(suma_i)


f = lambda : map(int, input().split())
n = int(input())
for i in range(n):
	a = int(input())
	j = 1
	es = 0
	while j <= a:
		es += j
		j *= 2
	print(a * (a + 1) // 2 - 2 * es)


n = int(input())
while n > 0:
	i = int(input())
	t = i * (i + 1) // 2
	t -= 2 ** (i.bit_length() + 1)
	t += 2
	print(t)
	n -= 1


for t in range(int(input())):
	n = int(input())
	print(n * (n + 1) // 2 - 2 * ((1 << n.bit_length()) - 1))


from math import log2
num = int(input())
powers = [1] * 32
for i in range(1, 32):
	powers[i] = 2 ** i + powers[i - 1]
for i in range(num):
	n = int(input())
	print(n * (n + 1) // 2 - 2 * powers[int(log2(n))])


t = int(input())
from math import log2
for i in range(t):
	x = int(input())
	ans = x * (x + 1) // 2 - 2 * 2 ** (int(log2(x)) + 1) + 2
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	d = 0
	while 2 ** (d + 1) <= n:
		d += 1
	sum1 = 2 ** (d + 1) - 1
	if n % 2 == 0:
		sum2 = (n + 1) * (n // 2)
	else:
		sum2 = (n + 1) * (n // 2) + n // 2 + 1
	print(sum2 - 2 * sum1)


def smaller_power(n):
	cpow = -1
	while n:
		n >>= 1
		cpow += 1
	return 1 << cpow
t = int(input())
for _ in range(t):
	n = int(input())
	sum_full = n * (n + 1) // 2
	sum_powers = (smaller_power(n) << 1) - 1
	print(sum_full - (sum_powers << 1))


n = int(input())
for i in range(n):
	n1 = int(input())
	l = 0
	count = 0
	while n1 >= 2 ** l:
		l += 1
		count += 2 ** l
	print(n1 * (n1 + 1) // 2 - count)


def lg(n):
	t = 0
	while n:
		n //= 2
		t += 1
	return t

def ans(n):
	q = n * (n + 1) // 2
	return int(q - 2 ** lg(n) * 2 + 2)
t = int(input())
for i in range(t):
	n = int(input())
	print(ans(n))


from math import log2
t = int(input())
for i in range(t):
	n = int(input())
	c = n * (n + 1) // 2
	l = int(log2(n)) + 1
	c -= 2 * (2 ** l - 1)
	print(c)


import math
sum = 0
t = int(input())
mas = []
c = 0
minus = 0
result = 0
for i in range(t):
	mas.append(int(input()))
for i in range(t):
	sum = int(mas[i] * (mas[i] + 1) // 2)
	c = math.log2(mas[i])
	c = math.floor(c) + 1
	minus = 2 ** c - 1
	result = sum - minus - minus
	print(int(result))


num_lines = int(input())
for line in range(num_lines):
	n = int(float(input()))
	s = n * (n + 1) // 2
	i = 1
	while i <= n:
		s -= i * 2
		i = i << 1
	print(int(s))


t = int(input())
b = [1] * 31
for i in range(1, 31):
	b[i] = 2 * b[i - 1]
for i in range(t):
	n = int(input())
	f = list(filter(lambda x: x <= n, b))
	result = n * (n + 1) // 2 - 2 * sum(f)
	print(result)


def solve(n):
	sum = n * (n + 1) >> 1
	a = 1
	while a <= n:
		sum -= 2 * a
		a *= 2
	return sum
t = int(input())
for i in range(t):
	n = int(input())
	print(solve(n))


t = int(input())
for i in range(t):
	n = int(input())
	minus = 2 ** (len(bin(n)) - 2) - 1
	print(n * (n + 1) // 2 - 2 * minus)


def sol(n):
	supposing_sum = n * (n + 1) // 2
	desired_sum = 0
	current_num = 1
	while current_num <= n:
		desired_sum += current_num
		current_num *= 2
	return supposing_sum - desired_sum * 2
t = int(input())
for i in range(t):
	n = int(input())
	print(sol(n))


t = int(input())
while t:
	a = int(input())
	x = 1
	sum = 0
	n = 1
	while x <= a:
		sum -= x
		x = 2 ** n
		n += 1
	h = a * (a + 1) // 2
	print(sum * 2 + h)
	t -= 1


import math
cnt = int(input())
power = [1]
for i in range(1, 31):
	power.append(power[-1] * 2)
for i in range(cnt):
	n = int(input())
	ans = (n + 1) * n // 2
	for i in range(math.floor(math.log2(n)) + 1):
		ans -= 2 * power[i]
	print(ans)


t = int(input())
while t > 0:
	n = int(input())
	su1 = 0
	num = 1
	s = 0
	su1 = n * (n + 1) // 2
	while num <= n:
		s = s + num
		num = num * 2
	print(su1 - s * 2)
	t = t - 1


import sys
(t,) = map(int, sys.stdin.readline().split())
for _ in range(t):
	(n,) = map(int, sys.stdin.readline().split())
	k = 0
	while 2 ** (k + 1) <= n:
		k += 1
	print(n * (n + 1) // 2 - 2 * (2 ** (k + 1) - 1))


for _ in range(int(input())):
	n = int(input())
	import math as m
	temp = n
	val = 0
	while temp > 0:
		temp = temp // 2
		val += 1
	s = 2 * (pow(2, val) - 1)
	s2 = n * (n + 1) // 2
	print(s2 - s)


from math import *

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		x = n * (n + 1)
		x = x // 2
		y = log(n, 2)
		y = int(y)
		y = y + 1
		z = 2 ** y - 1
		x = x - 2 * z
		print(x)
main()


from math import floor, log
t = int(input())
for _ in range(t):
	n = int(input())
	sumOfFirstN = n * (n + 1) // 2
	lastPowerOfTwo = floor(log(n, 2)) + 1
	powersOfTwo = 2 ** lastPowerOfTwo - 1
	print(sumOfFirstN - 2 * powersOfTwo)


for t in range(int(input())):
	a = int(input())
	ans = a * (a + 1) // 2
	power = 1
	while power <= a:
		ans -= power * 2
		power *= 2
	print(ans)


Z = int(input())
for _ in range(0, Z):
	n = int(input())
	p = 1
	while p <= n:
		p *= 2
	print(n * (n + 1) // 2 - 2 * (p - 1))


for X in range(int(input())):
	n = int(input())
	s = n * (n + 1) // 2
	x = 0
	while 2 ** x <= n:
		s -= 2 ** (x + 1)
		x += 1
	print(s)


for i in range(int(input())):
	n = int(input())
	rez = n * (n + 1) // 2
	c = 1
	while c <= n:
		c *= 2
		rez -= c
	print(rez)


def solve():
	n = int(input())
	res = n * (n + 1) // 2
	i = 1
	while i <= n:
		res -= 2 * i
		i *= 2
	print(res)
t = int(input())
for i in range(t):
	solve()


def f(x):
	if x == 1:
		return 1
	else:
		c = 0
		while x >= 2:
			c += 1
			x = x // 2
		ans = 2 ** (c + 1) - 1
		return ans
for i in range(int(input())):
	x = int(input())
	ans = x * (x + 1) // 2
	ans -= 2 * f(x)
	print(ans)


from sys import stdin
import math
live = True
if not live:
	stdin = open('data.in', 'r')
tests = int(stdin.readline().strip())
for test in range(tests):
	n = int(stdin.readline().strip())
	np1 = n + 1
	l = int(math.log(n, 2)) + 1
	if n % 2 == 0:
		n //= 2
	if np1 % 2 == 0:
		np1 //= 2
	print(int(n * np1 - 2 ** (l + 1) + 2))
if not live:
	stdin.close()


def power(n):
	sol = 0
	while n >= 1:
		sol += 1
		n = n >> 1
	return sol - 1

def sol(n):
	x = power(n)
	sum = n * (n + 1) // 2
	sum2 = int(pow(2, x + 1)) - 1
	return sum - 2 * sum2
t = input()
t = int(t)
for i in range(t):
	n = input()
	n = int(n)
	print(int(sol(n)))


t = int(input())
n = []
for i in range(t):
	n.append(int(input()))
for i in n:
	sum1 = (1 + i) * i // 2
	j = 0
	g = 0
	while j <= i:
		if j == 2 ** g:
			sum1 = sum1 - 2 * j
			g = g + 1
		j = 2 ** g
	print(sum1)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	logi = int(math.log(n, 2))
	print(n * (n + 1) // 2 - 2 * (2 ** (logi + 1) - 1))


t = int(input())
for i in range(t):
	n = int(input())
	negative_sum = 0
	positive_sum = n * (1 + n) // 2
	for j in range(n):
		x = 2 ** j
		if x > n:
			break
		negative_sum -= 2 * x
	print(negative_sum + positive_sum)


dua = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912]
t = int(input())
for i in range(t):
	n = int(input())
	tot = n * (n + 1) // 2
	for i in range(len(dua)):
		if dua[i] <= n:
			tot -= 2 * dua[i]
		else:
			break
	print(tot)


num_itera = int(input())
powers_two = 0
for i in range(num_itera):
	total = 0
	n = int(input())
	total = n * (n + 1) // 2
	for i in range(n):
		powers_two = 2 ** i
		if powers_two <= n:
			total -= powers_two * 2
		else:
			break
	print(total)


from __future__ import division
import math

def __solve(n):
	ans = int(math.log(n) / math.log(2))
	return ans
t = int(input())
while t:
	n = int(input())
	powr = __solve(n)
	sum = n * (n + 1) // 2 - 2 * (2 ** (powr + 1) - 1)
	print(sum)
	t -= 1


count = int(input())
for _ in range(count):
	n = int(input())
	part_sum = 2 * 1 + n - 1
	part_sum *= n
	part_sum = int(part_sum // 2)
	step = 0
	in_step = 0
	while True:
		in_step = 2 ** step
		if in_step > n:
			break
		part_sum -= 2 * in_step
		step += 1
	print(int(part_sum))


def main():
	m = int(input())
	for i in range(m):
		v = int(input())
		sum_v = v * (v + 1) // 2
		sum_2 = 0
		c = 0
		while 2 ** c <= v:
			sum_2 += 2 ** c
			c += 1
		print(str(sum_v - 2 * sum_2))
main()


def Solve():
	n = int(input())
	s = (1 + n) * n // 2
	i = 1
	while i <= n:
		s -= i * 2
		i *= 2
	print(s)
t = int(input())
for i in range(0, t):
	Solve()


def lg(x, tol=1e-13):
	res = 0.0
	while x < 1:
		res -= 1
		x *= 2
	while x >= 2:
		res += 1
		x /= 2
	fp = 1.0
	while fp >= tol:
		fp /= 2
		x *= x
		if x >= 2:
			x /= 2
			res += fp
	return res
t = int(input())
s = []
k = []
for i in range(101):
	k.append(int(2 ** i))
for i in range(t):
	s.append(int(input()))
su = [0] * t
l = 0
z = 2
q = 0
f = [0] * t
we = True
sum1 = [0] * t
for i in range(t):
	su[i] = s[i] * (s[i] + 1) // 2
	f[i] = int(lg(s[i], 2))
	for j in range(f[i] + 1):
		sum1[i] += k[j]
	print(su[i] - 2 * sum1[i])


def Input():
	tem = input().split()
	ans = []
	for it in tem:
		ans.append(int(it))
	return ans
from collections import Counter
T = Input()[0]
for tt in range(T):
	n = Input()[0]
	tem = 0
	power_2 = 1
	while power_2 <= n:
		tem += power_2
		power_2 *= 2
	ans = (n + 1) * n // 2 - 2 * tem
	print(ans)


n = int(input())
for j in range(n):
	t = int(input())
	s = (1 + t) * t // 2
	e = 0
	while 2 ** e <= t:
		s -= 2 ** e * 2
		e += 1
	print(s)


from math import log2
t = int(input())
for q in range(t):
	n = int(input())
	cur_sum = n * (n + 1) // 2
	deg = int(log2(n)) + 1
	cur_sum -= 2 * (2 ** deg - 1)
	print(cur_sum)


for t in range(int(input())):
	n = int(input())
	temp = 1
	summa = n * (n + 1) // 2
	while temp <= n:
		summa -= 2 * temp
		temp *= 2
	print(summa)


tricky_sum = lambda n: n * (n + 1) // 2 - 2 ** (len(bin(n)) - 1) + 2
for _ in range(int(input())):
	print(tricky_sum(int(input())))


import math
import sys
input_file = sys.stdin
input_file.readline()
for line in input_file.readlines():
	n = int(line.rstrip())
	if n % 2 == 0:
		running_sum = (n + 1) * int(n / 2)
	else:
		running_sum = (n + 1) * int(math.floor(n / 2)) + int(math.ceil(n / 2))
	powers = 1
	while powers <= n:
		running_sum -= 2 * powers
		powers = powers * 2
	print(running_sum)


t = int(input())
for k in range(t):
	n = int(input())
	s = n * (n + 1) // 2
	p = 1
	x = 0
	while p <= n:
		x += p
		p *= 2
	print(s - x - x)


import sys
from math import log

def main():
	(_, *l) = map(int, sys.stdin.read().strip().split())
	out = []
	for n in l:
		ap = n * (1 + n) // 2
		t = int(log(n, 2)) + 1
		gp = 2 ** t - 1
		out.append(ap - 2 * gp)
	return out
print(*main(), sep='\n')


import math

def tricky_sum(n):
	sum_pow_two = 0
	num = 1
	while num <= n:
		sum_pow_two += num
		num *= 2
	return n * (n + 1) // 2 - 2 * sum_pow_two
t = int(input())
for _ in range(t):
	print(tricky_sum(int(input())))


n = int(input())
for i in range(n):
	j = s = x = 0
	y = int(input())
	while x * 2 < y + 1:
		x = 1 << j
		s = x + s
		j += 1
	ans = y * (y + 1) // 2 - 2 * s
	print(ans)


t = int(input())
while t != 0:
	n = int(input())
	a = n * (n + 1) // 2
	b = 1
	while b <= n:
		a = a - 2 * b
		b = b * 2
	print(a)
	t -= 1


import math
t = int(input())
a = []
while t > 0:
	t -= 1
	n = int(input())
	r = math.trunc(math.log2(n))
	s = (n + 1) * n // 2
	s2 = 2 ** (r + 1) - 1
	a.append(s - 2 * s2)
for i in a:
	print(i)


from math import log
N = int(input())
for i in range(N):
	X = int(input())
	SUM = X * (X + 1) // 2
	for i in range(int(log(X, 2)) + 1):
		SUM -= 2 * 2 ** i
	print(SUM)


t = int(input())
while t:
	t = t - 1
	n = int(input())
	k = bin(n)[2:]
	x = n * (n + 1) // 2
	i = 0
	y = 0
	while 1:
		y = y + 2 ** i
		i = i + 1
		if i >= len(k):
			break
	print(x - 2 * y)


t = int(input())
l = []
for j in range(31):
	x = 2 ** j
	l.append(x)
p = []
r = []
for i in range(t):
	n = int(input())
	add = n * (n + 1) // 2
	for k in range(len(l)):
		p.append(l[k])
		if len(p) > n:
			break
	for s in range(len(p)):
		if p[s] <= n:
			r.append(p[s])
	q = sum(r) * 2
	result = add - q
	print(result)
	p.clear()
	r.clear()


from math import log
for i in range(int(input())):
	n = int(input())
	b = log(n, 2) // 1
	s = n * (n + 1) // 2
	k = int(2 ** (b + 1) - 1)
	print(int(s - 2 * k))


n = int(input())
for j in range(n):
	a = int(input())
	sum = 0
	if a % 2 == 0:
		sum = (a + 1) * (a // 2)
	else:
		sum = a * (a // 2 + 1)
	sumx = 0
	x = 1
	for i in range(100):
		if x <= a:
			sumx += x * 2
			x *= 2
	sum -= sumx
	print(sum)


from math import log
r = lambda : int(input())
for _ in range(r()):
	a = r()
	t = int(log(a, 2))
	s = a * (a + 1) // 2 - int(sum((2 ** x for x in range(t + 1)))) * 2
	print(int(s))


n = int(input())
mass = []
for i in range(n):
	mass.append(int(input()))
list_sum = []

def sum_of_powers(a):
	summ = 0
	pow2 = 1
	while pow2 <= a:
		summ += pow2
		pow2 *= 2
	return summ
for elem in mass:
	print(int((1 + elem) * elem // 2 - 2 * sum_of_powers(elem)))


n = int(input())
l = []
while n > 0:
	a = int(input())
	n1 = 0
	while 2 ** n1 <= a:
		if 2 ** (n1 + 1) > a:
			sum1 = 2 ** (n1 + 1) - 1
		n1 += 1
	ans = a * (a + 1) // 2
	ans = int(ans - 2 * sum1)
	print(ans)
	n -= 1


import math
t = int(input())
for i in range(t):
	n = int(input())
	a = n * (1 + n) // 2
	k = math.floor(math.log(n, 2))
	b = 2 ** (k + 1) - 1
	print(a - 2 * b)


import math
for _ in range(int(input())):
	n = int(input())
	s = n * (n + 1) // 2
	k = 2 * (2 ** math.ceil(math.log2(n + 1)) - 1)
	print(s - k)


import sys
import math

def powertwoSum(n):
	total = n * (n + 1) // 2
	sum = 0
	for i in range(30):
		power = pow(2, i)
		if power > n:
			break
		else:
			sum += power
	return total - sum - sum

def main():
	n = int(sys.stdin.readline())
	for _ in range(n):
		x = int(sys.stdin.readline())
		print(powertwoSum(x))
main()


n = int(input())
for i in range(n):
	x = int(input())
	s = x * (1 + x) // 2
	xx = len(bin(x)) - 3
	s -= 2 * (2 ** xx * 2 - 1)
	print(s)


def ssum(n):
	if n < 1:
		return 0
	return (1 + n) * n // 2
n = int(input())
res = [int(input()) for _ in range(n)]
ssumed = [ssum(x) for x in res]
for (i, v) in enumerate(res):
	k = 0
	while 2 ** k <= v:
		ssumed[i] -= 2 * 2 ** k
		k += 1
for v in ssumed:
	print(v)


for t in range(int(input())):
	n = int(input())
	sm = n * (n + 1) // 2
	check = 1
	cnt = 0
	while check <= n:
		check += check
		cnt += 1
	minus = 2 ** cnt - 1
	sm -= 2 * minus
	print(sm)


import math
num = int(input())
for d in range(num):
	a = int(input())
	i = 1
	h = 0
	sum = a * (a + 1) // 2
	for i in range(0, a + 1):
		k = pow(2, i)
		if k <= a:
			sum -= 2 * k
		else:
			break
	print(sum)


t = int(input())
for _ in range(t):
	n = int(input())
	c = 0
	while 2 ** (c + 1) <= n:
		c += 1
	print(n * (n + 1) // 2 - 2 * (2 ** (c + 1) - 1))


import decimal
import math
D = decimal.Decimal
n = int(input())
while n:
	m = int(input())
	total = int(m * D((m + 1) / 2))
	i = 1
	while True:
		total -= 2 * i
		if i <= D(m / 2):
			i *= 2
		else:
			break
	print(total)
	n -= 1


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	init = 1
	res = 0
	while init <= n:
		res -= init
		init *= 2
	res = res * 2
	res += n * (n + 1) // 2
	print(res)


t = int(input().strip())
while t:
	n = int(input().strip())
	ans = n * (n + 1) // 2
	for i in range(31):
		if 1 << i <= n:
			ans -= 2 * (1 << i)
		else:
			break
	print(ans)
	t -= 1


def np(x):
	i = 0
	n = 0
	while n <= x:
		n = 2 ** i
		i = i + 1
	return i - 1
for i in range(int(input())):
	x = int(input())
	p = np(x)
	r = x * (x + 1) // 2
	h = 2 * 2 ** p - 2
	print(int(r) - int(h))


import math
t = int(input())
for x in range(t):
	n = int(input())
	pSum = n * (n + 1) // 2
	temp = math.log2(n) // math.log2(2)
	temp = int(temp) + 1
	nSum = 2 ** temp - 1
	print(pSum - 2 * nSum)


import math
for _ in range(int(input())):
	i = int(input())
	s = i * (i + 1) // 2
	n = int(math.log2(i))
	d = pow(2, n + 1) - 1
	print(s - 2 * d)


t = int(input())
for i in range(t):
	n = int(input())
	s = (1 + n) * n // 2
	for j in range(32):
		if 2 ** j <= n:
			s -= 2 ** j
			s -= 2 ** j
	print(s)


p = int(input())
for q in range(p):
	n = int(input())
	sum = n * (n + 1) // 2
	b = bin(n)[2:]
	l = len(b)
	t = 0
	for i in range(l):
		t += int('1' + '0' * i, 2)
	print(sum - 2 * t)


__author__ = 'suvasish'
t = int(input())
for g in range(0, t):
	val = int(input())
	tsum = val * (val + 1) // 2
	i = 1
	while i <= val:
		tsum -= i * 2
		i *= 2
	print(tsum)


query = int(input())
for _ in range(query):
	num = int(input())
	s = num + num * (num - 1) // 2
	for i in range(num + 1):
		if 2 ** i > num:
			break
	p = 2 * (2 ** i - 1)
	print(s - p)


x = int(input())
for i in range(x):
	y = int(input())
	s = 0
	c = 0
	k = 0
	s = s + y * (y + 1) // 2
	while 2 ** c <= y:
		k = k + 2 ** c
		c = c + 1
	print(s - 2 * k)


import math
t = int(input())
for i in range(t):
	n = int(input())
	k = math.log(n, 2)
	f = n * (n + 1) // 2
	k1 = int(math.floor(k))
	su = 0
	for j in range(k1 + 1):
		su += 2 ** j
	print(f - 2 * su)


t = int(input())
a = t * [0]
for i in range(t):
	n = int(input())
	a[i] = n * (n + 1) // 2
	j = 0
	while 2 ** j <= n:
		a[i] -= 2 * 2 ** j
		j += 1
for z in range(t):
	print(a[z])


import sys
t = int(sys.stdin.readline())
for i in range(0, t):
	n = int(sys.stdin.readline())
	s = n * (n + 1) // 2
	j = 1
	s1 = 0
	while j <= n:
		s1 += j
		j *= 2
	print(s - s1 * 2)


t = int(input())
for i in range(t):
	n = int(input())
	s1 = (1 + n) * n // 2
	s2 = 0
	j = 0
	while 2 ** j <= n:
		s2 += 2 ** j
		j += 1
	print(s1 - s2 * 2)


t = int(input())
wyn = []
for i in range(t):
	n = int(input())
	wyn += [(1 + n) * n // 2]
	m = 1
	while m <= n:
		wyn[i] -= 2 * m
		m *= 2
for i in wyn:
	print(i)


t = int(input())
for test in range(t):
	n = int(input())
	a = 1
	cnt = 0
	while a <= n:
		a *= 2
		cnt += 1
	print(n * (n + 1) // 2 - 2 * (2 ** cnt - 1))


def binary_log(x):
	return len(bin(x)) - 2

def sum_of_cons(x):
	return x * (x + 1) // 2
t = int(input())
for _ in range(t):
	n = int(input())
	print(sum_of_cons(n) - 2 * (2 ** binary_log(n) - 1))


n = int(input())
f = lambda a: a * (a + 1) // 2 - 2 * (2 ** (len(bin(a)) - 2) - 1)
for i in range(n):
	print(f(int(input())))


import math
t = int(input())
for _ in range(t):
	n = int(input())
	print(n * (n + 1) // 2 - ((1 << n.bit_length()) - 1) * 2)


t = int(input())
for r in range(0, t):
	tot = 0
	o = int(input())
	x = 0
	while 2 ** x <= o:
		x = x + 1
	print(o * (o + 1) // 2 - 2 * (2 ** x - 1))


import math

def cal(val):
	k = int(math.log2(val))
	return (1 + val) * val // 2 - 2 * (2 ** (k + 1) - 1)
N = int(input())
for i in range(N):
	print(cal(int(input())))


def tricky(n):
	two_pow = [0]
	ini_sum = n * (n + 1) // 2
	i = 0
	while two_pow[-1] <= n:
		two_pow.append(2 ** i)
		i += 1
	two_pow.pop()
	while two_pow:
		ini_sum -= 2 * two_pow.pop()
	return ini_sum
t = int(input())
for i in range(t):
	n = int(input())
	print(tricky(n))


from math import floor, log
for _ in range(int(input())):
	n = int(input())
	p = n * (n + 1) // 2
	f = floor(log(n, 2))
	p -= 2 * (2 ** (f + 1) - 1)
	print(p)


from math import log2, ceil
for _ in range(int(input())):
	n = int(input())
	gp = pow(2, int(log2(n)) + 1) - 1
	total = n * (n + 1) // 2
	print(total - 2 * gp)


x = int(input())
while x:
	n = int(input())
	sum = n * (n + 1) // 2
	y = 1
	x = x - 1
	while y <= n:
		sum = sum - 2 * y
		y = y * 2
	print(sum)


t = int(input())
while t > 0:
	n = int(input())
	s = n * (n + 1) // 2
	pt = 0
	p = 1
	while pt < n:
		pt = pt + p
		p = p * 2
	print(s - 2 * pt)
	t = t - 1


t = int(input())
while t > 0:
	n = int(input())
	temp = n
	count = 0
	while temp != 0:
		count = count + 1
		temp = temp // 2
	temp = 2 * (pow(2, count) - 1)
	print(n * (n + 1) // 2 - temp)
	t = t - 1


import math
n = int(input())
a = []
for i in range(n):
	a.append(int(input()))

def powerof2(n):
	pow2 = []
	for i in range(int(math.log(n, 2)) + 1):
		pow2.append(pow(2, i))
	return pow2
for i in range(n):
	value = a[i]
	pow2 = powerof2(value)
	results = (value + 1) * value // 2 - 2 * sum(pow2)
	print(results)


from math import log

def f(n):
	m = int(log(n, 2))
	return n * (n + 1) // 2 - (2 ** (m + 2) - 2)
cases = int(input())
for _ in range(cases):
	print(f(int(input())))


t = int(input())
for _ in range(t):
	n = int(input())
	output = n * (n + 1) // 2
	tmp = 1
	while tmp <= n:
		output -= 2 * tmp
		tmp *= 2
	print(output)


from math import log2
t = int(input())
answer = []
for i in range(t):
	n = int(input())
	d = int(log2(n))
	answer += [n * (n + 1) // 2 - 2 * (2 ** (d + 1) - 1)]
print('\n'.join(map(str, answer)))


t = int(input())
for r in range(t):
	n = int(input())
	sum = n * (n + 1) // 2
	a = 1
	while a <= n:
		sum -= 2 * a
		a *= 2
	print(int(sum))


inputNum = int(input())
for inputs in range(0, inputNum):
	n = int(input())
	sum = int('0', 36)
	power = int('0', 36)
	while 2 ** power <= n:
		sum -= 2 * 2 ** power
		power += 1
	sum += (1 + n) * n >> 1
	print(sum)


import math
for t in range(int(input())):
	n = int(input())
	sn = (1 + n) * n // 2
	d = 1 + int(math.log2(n))
	sd = 2 ** d - 1
	print(str(sn - 2 * sd))


for _ in range(int(input())):
	N = int(input())
	ans = N * (N + 1) // 2
	count = 0
	while N != 0:
		N = N // 2
		count += 1
	print(ans - (pow(2, count + 1) - 2))


def pow(n):
	c = 0
	while n >= 2:
		n = n // 2
		c += 1
	return c + 1
for _ in range(int(input())):
	n = int(input())
	c = pow(n)
	a = 2 ** c - 1
	b = n * (n + 1) // 2
	count = b - 2 * a
	print(count)


t = int(input())
while t:
	n = int(input())
	ans = n * (n + 1) // 2
	for i in range(40):
		if 2 ** i <= n:
			ans -= 2 * 2 ** i
	print(ans)
	t -= 1


t = int(input())
import math
tests = []
for _ in range(t):
	tests.append(int(input()))

def solve(n):
	(i, t) = (int(1), 0)
	while i <= n:
		t += i
		i *= 2
	return t
for n in tests:
	s = int(n * (n + 1) // 2)
	m = int(solve(n) * 2)
	print(int(s - m))


t = int(input())
for x in range(t):
	n = int(input())
	a = n * (n + 1) // 2
	z = 1
	while z <= n:
		a = int(a - 2 * z)
		z *= 2
	print(a)


n = int(input())
for i in range(n):
	Sum1 = 0
	st = 1
	a = int(input())
	Sum = a * (a + 1) // 2
	while st <= a:
		st *= 2
	Sum1 = Sum - 2 * (st - 1)
	print(Sum1)


for i in range(int(input())):
	n = int(input())
	(z, m) = (0, 0)
	while n >= 2 ** m:
		z += 2 ** m
		m += 1
	print(n * (n + 1) // 2 - 2 * z)


t = int(input())
for i in range(t):
	n = int(input())
	n1 = n
	q = 1
	while n1 != 0:
		n1 = n1 // 2
		q *= 2
	q = q // 2
	print(n * (n + 1) // 2 - 2 * (2 * q - 1))


t = int(input())
while t:
	t -= 1
	n = int(input())
	j = 0
	m = 0
	while 2 ** j <= n:
		m += 2 ** j
		j += 1
	s = n * (n + 1) // 2 - 2 * m
	print(s)


import math
for _ in range(int(input())):
	n = int(input())
	p = int(math.log2(n))
	s = n * (n + 1) // 2
	q = 2 * (2 ** p - 1)
	print(s - 2 * (q + 1))


import math
test = int(input())
for _ in range(test):
	N = int(input())
	limit = int(math.log2(N))
	total_sum = N * (N + 1) // 2
	final_ans = total_sum - 2 * (pow(2, limit + 1) - 1)
	print(final_ans)


t = int(input())
while t:
	f = int(input())
	n = 1
	t_total = 0
	n_total = (1 + f) * f // 2
	while n < f + 1:
		t_total += n
		n = n * 2
	t_total = t_total
	print(n_total - 2 * t_total)
	t -= 1


tests = int(input())
for test in range(tests):
	n = int(input().strip())
	res = n * (n + 1) // 2
	largesttwo = -1
	for i in range(40):
		if n >> i & 1 == 1:
			largesttwo = i
	for i in range(largesttwo + 1):
		res -= 2 * 2 ** i
	print(res)


import math
t = int(input())
while t:
	t = t - 1
	n = int(input())
	sum = n * (n + 1) // 2
	i = 1
	while i <= n:
		sum = sum - 2 * i
		i = i * 2
	print(sum)


def smartSum(n):
	s = n * (n + 1) // 2
	power = 0
	current = 1
	while current <= n:
		power += 1
		current *= 2
	diff = (current - 1) * 2
	return int(s - diff)
t = input()
for i in range(int(t)):
	n = input()
	print(smartSum(int(n)))


for u in range(int(input())):
	n = int(input())
	s = n * (n + 1) // 2
	x = 0
	z = 0
	while 2 ** z <= n:
		x = x + 2 ** z
		z = z + 1
	print(s - 2 * x)


t = int(input())
ns = []
for _ in range(t):
	ns.append(int(input()))
for n in ns:
	s = 0
	if n % 2 == 0:
		s = int((n + 1) * (n // 2))
	else:
		s = int(n * (n - 1) // 2 + n)
	temp = 1
	powers = 0
	ts = 0
	while temp <= n:
		powers += 1
		ts += temp
		temp *= 2
	if powers != 0:
		s -= ts + ts
	print(s)


n = int(input())
for i in range(n):
	x = abs(int(input()))
	p = x * (x + 1) // 2
	q = 1
	while q <= x:
		p -= q * 2
		q *= 2
	print(p)


import math
from decimal import *
import sys
from fractions import Fraction
T = int(input())
for j in range(0, T):
	n = int(input())
	t = 1
	lt = 0
	while 2 * t <= n:
		t *= 2
		lt += 1
	n2 = Fraction(n * (n + 1)) / Fraction(2)
	print(n2 - 2 * (2 * t - 1))


t = int(input())
data = []
for i in range(t):
	data.append(int(input()))
for i in range(t):
	sum = data[i] * (data[i] + 1) // 2
	n = 0
	while data[i] > 0:
		data[i] //= 2
		n += 1
	sum += 2 * (1 - 2 ** n)
	print(sum)


for i in range(int(input())):
	x = int(input())
	n = x * (x + 1) // 2
	k = 1
	while True:
		if k <= x:
			n = n - 2 * k
			k = k * 2
		else:
			break
	print(n)


n = int(input())
two = [2 ** i for i in range(100)]
for i in range(n):
	x = int(input())
	res = x * (x + 1) // 2
	j = 0
	while two[j] <= x:
		j += 1
		continue
	res -= 2 * sum(two[:j])
	print(res)