Advertisement
HaciyevAlik

Cycle Shifts

Aug 31st, 2022
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using ll = long long;
  5. using ld = long double;
  6. const ll INF = 2*1e9;
  7.  
  8. //Acımasızca geçip giden zamandan
  9. //Geriye kalan sadece yalnızlıklarımız
  10.  
  11. int main(){
  12.     ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //freopen("input.txt","r",stdin);
  13.     ll n; cin>>n;
  14.     string bin = "";
  15.     while(n > 0){
  16.         int q = n % 2;
  17.         bin = to_string(q) + bin;
  18.         n/=2;
  19.     }
  20.     vector<string> v;
  21.     v.push_back(bin);
  22.     for(int i = 1;i<(int)bin.size();i++){
  23.         bin += bin[0];
  24.         bin = bin.substr(1,(int)bin.size());
  25.         v.push_back(bin);
  26.     }
  27.     sort(v.begin(),v.end());
  28.     bin = v[v.size()-1];
  29.     n = 0;
  30.     for(int i = 0;i<(int)bin.size();i++){
  31.         if(bin[i] == '1'){
  32.             n += pow(2,(int)bin.size() - i - 1);
  33.         }
  34.     }
  35.     cout << n << "\n";
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement