fork download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main(){
  6. unsigned long in_val, tmp_val;
  7. cin >> in_val;
  8. tmp_val = in_val;
  9. unsigned long power;
  10. power = pow(2, floor(log2(in_val)) + 1);
  11. tmp_val = in_val;
  12. unsigned long max_val = in_val;
  13. do{
  14. in_val = in_val << 1;
  15. in_val = in_val % power + (in_val >= power ? 1 : 0);
  16. if(max_val < in_val){
  17. max_val = in_val;
  18. }
  19. }while(tmp_val != in_val);
  20. cout << max_val << endl;
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 4308KB
stdin
11
stdout
14