fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. vector<int> ans(1000006, 0), temp(1000006, 0);
  4. void preprocess(){
  5. ans[1] = temp[1] = 1;
  6. ans[2] = 2, temp[2] = 1;
  7. for(int i=3; i<1000006; ++i){
  8. if(i&1){
  9. ans[i] = temp[i/2] * 2;
  10. temp[i] = ans[i/2 + 1] * 2 - 1;
  11. }
  12. else{
  13. ans[i] = ans[i/2] * 2;
  14. temp[i] = temp[i/2] * 2 - 1;
  15. }
  16. }
  17. }
  18. int main(){
  19. #ifndef ONLINE_JUDGE
  20. freopen("inp6.txt", "r", stdin);
  21. freopen("out6.txt", "w", stdout);
  22. #endif // ONLINE_JUDGE
  23. preprocess();
  24. int test;
  25. scanf("%d", &test);
  26. while(test--){
  27. int n;
  28. scanf("%d", &n);
  29. printf("%d\n", ans[n]);
  30. }
  31. }
  32.  
Runtime error #stdin #stdout 0s 11272KB
stdin
Standard input is empty
stdout
Standard output is empty