Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <functional>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <cstring>
  5. #include <cstdlib>
  6. #include <cassert>
  7. #include <sstream>
  8. #include <numeric>
  9. #include <string>
  10. #include <vector>
  11. #include <cstdio>
  12. #include <bitset>
  13. #include <cmath>
  14. #include <ctime>
  15. #include <queue>
  16. #include <stack>
  17. #include <map>
  18. #include <set>
  19.  
  20. using namespace std;
  21.  
  22. #define sz(a) (int)a.size()
  23. #define vi vector <int>
  24. #define pb push_back
  25. #define mp make_pair
  26. #define ll long long
  27. #define f first
  28. #define s second
  29.  
  30. const int inf = (int)1e9;
  31. const int mod = inf + 7;
  32. const double eps = 1e-9;
  33. const double pi = acos(-1.0);
  34.  
  35. ll n;
  36. string s;
  37. string f(ll n){
  38. string res = "";
  39. while(n != 0){
  40. res += char('0' + n % 2);
  41. n /= 2;
  42. }
  43. reverse(res.begin(), res.end());
  44. return res;
  45. }
  46. string next(string s){
  47. string d = "";
  48. for(int i = 1; i < s.size(); ++i)
  49. d += s[i];
  50. d += s[0];
  51. return d;
  52. }
  53. ll bpow(ll a, ll n){
  54.  
  55. if(n == 0)
  56. return 1;
  57. if(n == 1)
  58. return a;
  59. else {
  60.  
  61. ll k = bpow(a, n / 2);
  62.  
  63. if(n % 2 == 0)
  64. return k * k;
  65. else
  66. return k * k * a;
  67. }
  68. }
  69.  
  70. ll u(string s){
  71. ll res = 0;
  72. for(ll i = s.size() - 1; i >= 0; --i)
  73. res += bpow(2, s.size() - i - 1) * (s[i] - '0');
  74. return res;
  75. }
  76. int main(){
  77. cin >> n;
  78. if(n == 0){
  79. cout << 0 << endl;
  80. return 0;
  81. }
  82. string p = f(n);
  83. string maxi = "";
  84. for(int i = 0; i < p.size() + 2; ++i){
  85. if(maxi < p)
  86. maxi = p;
  87. p = next(p);
  88. }
  89. cout << u(maxi) << endl;
  90. return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement