# 【Educational Codeforces Round 1A】【水题】Tricky Sum 1~n之和减去2的幂

A. Tricky Sum
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 20,21 and 22 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 ofn to be processed.

Each of next t lines contains a single integer n (1 ≤ n ≤ 109).

Output

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

Sample test(s)
input
2
4
1000000000

output
-4
499999998352516354

Note

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

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T> inline void gmax(T &a,T b){if(b>a)a=b;}
template <class T> inline void gmin(T &a,T b){if(b<a)a=b;}
const int N=0,M=0,Z=1e9+7,ms63=1061109567;
int casenum,casei;
int n;
int main()
{
scanf("%d",&casenum);
for(casei=1;casei<=casenum;casei++)
{
scanf("%d",&n);
LL sum=(LL)(n+1)*n/2;//全部都算为正
for(int bit=1;bit<=n;bit<<=1)
{
sum-=bit;
sum-=bit;
}
printf("%lld\n",sum);
}
return 0;
}
/*
【题意】

【类型】

【分析】

【时间复杂度&&优化】
O(log(n))

【数据】
1000000000

*/

#### Educational Codeforces Round 36 (Rated for Div. 2) 题解

2018-01-13 23:16:24

#### Educational Codeforces Round 38 (Rated for Div. 2) B. Run For Your Prize

2018-02-17 13:35:37

#### Educational Codeforces Round 46 (Rated for Div. 2) A Codehorses T-shirts

2018-06-28 08:41:58

#### Codeforces Educational Codeforces Round 41 (Rated for Div. 2) B. Lecture Sleep

2018-04-05 10:35:27

#### Educational Codeforces Round 40 (Rated for Div. 2) B. String Typing

2018-03-24 07:32:45

#### CF-Educational Codeforces Round 44 (Rated for Div. 2)-A-Chess Placing

2018-05-22 04:28:33

#### Educational Codeforces Round 46 (Rated for Div. 2) B - Light It Up

2018-06-28 08:42:52

#### Codeforces Round #392 (Div. 2)E. Broken Tree

2017-01-20 19:16:32

#### Codeforces Educational Codeforces Round 42 (Rated for Div. 2) B. Students in Railway Carriage 填放人数

2018-04-11 12:58:13

#### Codeforces Educational Codeforces Round 45 (Rated for Div. 2)题解

2018-06-10 21:50:33