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