Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define d(x) cout << #x << " = " << (x) << endl;
- #define fr freopen("in.txt", "r", stdin);
- #define fw freopen("out.txt", "w", stdout);
- #define mem(x) memset((x), 0, sizeof((x)));
- #define pb push_back
- #define LL long long
- #define fastIO ios_base::sync_with_stdio(false)
- #define sf scanf
- #define pf printf
- #define sc1(x) scanf("%d", &x)
- #define sc2(x, y) scanf("%d %d", &x, &y)
- #define sc3(x, y, z) scanf("%d %d %d", &x, &y, &z)
- #define FOR(i, x, y) for(int i=int(x); i<int(y); i++)
- #define ROF(i, x, y) for(int i=int(x-1); i>=int(y); i--)
- #define all(c) c.begin(), c.end()
- #define unq(v) sort(all(v)), (v).erase(unique(all(v)),v.end())
- #define siz 1000000
- unsigned LL pow_of_two[10000];
- int create(){
- unsigned LL i = 0;
- unsigned LL num = 1;
- while(num <= INT_MAX and num >= 0){
- num = pow(2, i);
- pow_of_two[i] = num;
- i++;
- }
- }
- ////////////////problem link: http://codeforces.com/problemset/problem/598/A //////////////////
- int main(){
- #ifndef ONLINE_JUDGE
- clock_t tStart = clock();
- freopen("in.txt", "r", stdin);
- freopen("out.txt", "w", stdout);
- #endif
- create();
- int tc;
- cin >> tc;
- for(int tr = 1; tr <= tc; tr++){
- unsigned long long n;
- cin >> n;
- unsigned long long int totalSum = (n*(n+1))/2;
- unsigned long long int powerSum = 0;
- for(int i = 0; pow_of_two[i] <= n; i++){
- powerSum += pow_of_two[i];
- }
- //please uncomment and check this line
- //cout << totalSum - powerSum - powerSum << endl;
- long long int ans = totalSum - powerSum - powerSum;
- cout << ans << endl;
- }
- #ifndef ONLINE_JUDGE
- printf("\n>>Time taken: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement