fork download
  1. #include <iostream>
  2. #include <bitset>
  3. using namespace std;
  4. int nextPermutation(int x){
  5. x++;
  6. int y = x&(x-1);
  7. x = (y&-y)/(x&-x)/2;
  8. return y-x;
  9. }
  10. int main() {
  11. int n,t;
  12. cin>>n>>t;
  13. cout<<n<<"\t\t"<<bitset<32>(n)<<endl;
  14. while(t--){
  15. n = nextPermutation(n);
  16. cout<<n<<"\t\t"<<bitset<32>(n)<<endl;
  17. }
  18. return 0;
  19. }
Success #stdin #stdout 0s 4620KB
stdin
60 16
stdout
60		00000000000000000000000000111100
58		00000000000000000000000000111010
57		00000000000000000000000000111001
54		00000000000000000000000000110110
53		00000000000000000000000000110101
51		00000000000000000000000000110011
46		00000000000000000000000000101110
45		00000000000000000000000000101101
43		00000000000000000000000000101011
39		00000000000000000000000000100111
30		00000000000000000000000000011110
29		00000000000000000000000000011101
27		00000000000000000000000000011011
23		00000000000000000000000000010111
15		00000000000000000000000000001111
0		00000000000000000000000000000000
0		00000000000000000000000000000000