http://codeforces.com/problemset/problem/598/A
t组数据(1≤t≤100)。给定n(1≤n≤1e9),把1到n中的2^0、2^1、2^2…..变成负数。求n个数之和。
Examples
input
2
4
1000000000
output
-4
499999998352516354
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
long long t,n;
long long f(long long n){
long long ans=n*(1+n)/2;
for (int i=0;pow(2,i)<=n;i++){
ans-=2*pow(2,i);
}
return ans;
}
int main(){
cin >> t;
while (t--){
cin >> n;
cout << f(n) << endl;
}
}