C++ 0ms solution (cache the result array)
\nclass Solution {\npublic:\n    std::vector<int> f()\n    {\n        std::vector<int> v { 1 };\n        int i2 = 0;\n        int i3 = 0;\n        int i5 = 0;\n
```\nclass Solution {\npublic:\n    std::vector<int> f()\n    {\n        std::vector<int> v { 1 };\n        int i2 = 0;\n        int i3 = 0;\n        int i5 = 0;\n        while (v.size() < 1691)\n        {\n            int a = std::min(v[i2] * 2, std::min(v[i3] * 3, v[i5] * 5));\n            v.push_back(a);\n            if (a == v[i2] * 2)\n                ++i2;\n            if (a == v[i3] * 3)\n                ++i3;\n            if (a == v[i5] * 5)\n                ++i5;\n        }\n        \n        return v;\n    }\n    int nthUglyNumber(int n) {\n        static auto vv = f();\n        return vv[n - 1];                \n    }\n};\n```
[]