fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int countEvenSetBits(int n)
  5. {
  6. unsigned int count = 0;
  7. while (n)
  8. {
  9. n &= (n-1) ;
  10. count++;
  11. }
  12. if(count==2){
  13. return count;
  14. }
  15. else{
  16. return 0;
  17. }
  18. }
  19.  
  20.  
  21. int calculate_sum(int n){
  22. int sum = 0;
  23. int number = 0;
  24. while(n){
  25. if(countEvenSetBits(number)!=0){
  26. sum = sum + number;
  27.  
  28. n--;
  29. }
  30. number++;
  31. }
  32.  
  33. return sum;
  34.  
  35. }
  36.  
  37.  
  38.  
  39. int main() {
  40. int t,n;
  41. // your code goes here
  42. cin >> t;
  43.  
  44.  
  45. while(t--){
  46. cin >> n;
  47. cout << calculate_sum(n)<<endl;
  48. }
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0s 2688KB
stdin
2
15
25
stdout
315
1289