C++  solution!!!!
//  Just trace the index of any one varible until its index is equal to the required index.\n// Multiplying by 2 bcz if we observe the movement of any variable 
//  Just trace the index of any one varible until its index is equal to the required index.\n// Multiplying by 2 bcz if we observe the movement of any variable its equivalent to some multiple of 2 \n// modulus is to keep the value of index valid(<n).\n//Asymptotic behavior : I believe its not more than n. \n\n\n\nclass Solution {\npublic:\n    int reinitializePermutation(int n) \n    {\n        int ind=1;\n        int ct=0;\n        \n        if(n==2)\n            return 1;\n        \n        while(1)\n        {\n            ind=ind*2;\n            ct++;\n            \n            \n            if(ind>=(n-1))\n                ind=ind%(n-1);\n            \n            if(ind==1)\n                return ct;\n                \n            \n        }\n        \n            \n        \n    }\n};
[]