Advertisement
erfanul007

LOJ 1042

Dec 8th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. long long t,i=0;
  7. cin>>t;
  8. while(t--){
  9. i++;
  10. long long n,x,j=0,total=0,l;
  11. cin>>n;
  12. vector<int>bin;
  13. while(n){
  14. x=n%2;
  15. bin.push_back(x);
  16. n/=2;
  17. j++;
  18. }
  19. x=0;
  20. bin.push_back(x);
  21. reverse(bin.begin(),bin.end());
  22. next_permutation(bin.begin(),bin.end());
  23. cout<<"Case "<<i<<": ";
  24. l=0;
  25. for(int k=j;k>=0;k--){
  26. total+=(bin[k]*pow(2,l));
  27. l++;
  28. }
  29. cout<<total<<endl;
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement