Advertisement
arfin97

Weird Unsigned substraction 2 full

Jun 26th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define d(x)                cout << #x << " = " << (x) << endl;
  4. #define fr                  freopen("in.txt", "r", stdin);
  5. #define fw                  freopen("out.txt", "w", stdout);
  6. #define mem(x)              memset((x), 0, sizeof((x)));
  7. #define pb                  push_back
  8. #define LL                  long long
  9. #define fastIO              ios_base::sync_with_stdio(false)
  10. #define sf                  scanf
  11. #define pf                  printf
  12. #define sc1(x)              scanf("%d", &x)
  13. #define sc2(x, y)           scanf("%d %d", &x, &y)
  14. #define sc3(x, y, z)        scanf("%d %d %d", &x, &y, &z)
  15. #define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
  16. #define ROF(i, x, y)        for(int i=int(x-1); i>=int(y); i--)
  17. #define all(c)              c.begin(), c.end()
  18. #define unq(v)              sort(all(v)), (v).erase(unique(all(v)),v.end())
  19. #define siz 1000000
  20.  
  21. unsigned LL pow_of_two[10000];
  22.  
  23. int create(){
  24.     unsigned LL i = 0;
  25.     unsigned LL num = 1;
  26.     while(num <= INT_MAX and num >= 0){
  27.         num = pow(2, i);
  28.  
  29.         pow_of_two[i] = num;
  30.  
  31.         i++;
  32.     }
  33. }
  34.  
  35. ////////////////problem link: http://codeforces.com/problemset/problem/598/A //////////////////
  36.  
  37.  
  38. int main(){
  39.     #ifndef ONLINE_JUDGE
  40.         clock_t tStart = clock();
  41.         freopen("in.txt", "r", stdin);
  42.         freopen("out.txt", "w", stdout);
  43.     #endif
  44.  
  45.     create();
  46.  
  47.     int tc;
  48.     cin >> tc;
  49.  
  50.     for(int tr = 1; tr <= tc; tr++){
  51.         unsigned long long n;
  52.         cin >> n;
  53.         unsigned long long int totalSum = (n*(n+1))/2;
  54.        
  55.         unsigned long long int powerSum = 0;
  56.         for(int i = 0; pow_of_two[i] <= n; i++){
  57.             powerSum += pow_of_two[i];
  58.         }
  59.  
  60.         //please uncomment and check this line
  61.         //cout << totalSum - powerSum - powerSum << endl;
  62.  
  63.         long long int ans = totalSum - powerSum - powerSum;
  64.         cout << ans << endl;
  65.     }
  66.  
  67.  
  68.     #ifndef ONLINE_JUDGE
  69.         printf("\n>>Time taken: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
  70.     #endif
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement