fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. long long int flooring(int);
  4. long long int a[3000000]={0};
  5. int main() {
  6. // your code goes here
  7. int t;
  8. cin>>t;
  9. while(t--)
  10. {
  11. int n;
  12. cin>>n;
  13. cout<<flooring(n)<<"\n";
  14. }
  15. return 0;
  16. }
  17. long long int flooring(int x)
  18. {
  19. if(x==0)
  20. {
  21. return 0;
  22. }
  23. if(a[x]!=0)
  24. return a[x];
  25. else
  26. a[x]=floor((double)(x/2))+flooring(x-1);
  27. return a[x];
  28. }
Success #stdin #stdout 0s 26536KB
stdin
5
1
2
3
4
5
stdout
0
1
2
4
6