fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7.  
  8. long long sum = n*(n+1)/2;
  9. long long f = 1;
  10. while(f <= n) {
  11. sum -= 2*f;
  12. f *= 2;
  13. }
  14.  
  15. cout << sum << endl;
  16. }
Success #stdin #stdout 0.01s 5316KB
stdin
15
stdout
90