C++ 100 % fast and 100% less memory solution
\nclass Solution {\npublic:\n    int reinitializePermutation(int n) {\n        if(n<=2)\n            return 1;\n        int ans =1;\n        int num = 2;\n     
```\nclass Solution {\npublic:\n    int reinitializePermutation(int n) {\n        if(n<=2)\n            return 1;\n        int ans =1;\n        int num = 2;\n        \n        while(num!=1)\n        {\n            ans++;\n            num = (num*2)%(n-1);\n        }\n        return ans;\n    }\n};\n```
[]