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