Using Mersenne Numbers
\n\n\n# Code\ncpp []\nclass Solution {\npublic:\n    int smallestNumber(int n) {\n        int z = 1;\n        for (int i = 0; i <= n; i++) {\n            z = (1
![image.png](https://assets.leetcode.com/users/images/d614775c-47e0-49da-89ab-1c222a41891d_1733027782.9739358.png)\n\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int smallestNumber(int n) {\n        int z = 1;\n        for (int i = 0; i <= n; i++) {\n            z = (1 << i);\n            if (z > n)\n                return z - 1;\n        }\n        return 0;\n    }\n};\n\n```
['C++']