fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int t;
  6. cin >> t;
  7. while(t--) {
  8. long long n;
  9. cin >> n;
  10.  
  11. long long sum = n*(n+1)/2;
  12. long long f = 1;
  13. while(f <= n) {
  14. sum -= 2*f; // نجعل كل قوة 2 بالسالب
  15. f *= 2;
  16. }
  17. cout << sum << endl;
  18. }
  19. return 0;
  20. }
Success #stdin #stdout 0.01s 5292KB
stdin
2
stdout
4390284870744727442
4390284870744727442