O(nk) C Solution with Detailed Explanation
In this problem we have to make a series such that number have factors belonging only to give Prime array. Lets take an example of [2,5,11].\n    In this case o
    In this problem we have to make a series such that number have factors belonging only to give Prime array. Lets take an example of [2,5,11].\n    In this case our ugly series will be: 1, 2, 4, 5, 8, 10, 11, 16, 20 & so on.\n    In general this series can be denoted as:\n    0)1 as universal ugly number\n    1)2 = 2x1 = 2 x ugly[0]\n    2)4 = 2x2 = 2 x ugly[1]\n    3)5 = 5x1 = 5 x ugly[0]\n    4)8 = 2x4 = 2 x ugly[2]\n    5)10= 5x2 = 5 x ugly[1] = 2 x ugly[3]\n    6)11= 11x1= 11x ugly[0]\n    7)16= 2x8 = 2 x ugly[4]\n    8)20= 5x4 = 5 x ugly[2] = 2x10 = 2 x ugly[5]\n    9)22= 11x2= 11x ugly[1] = 2 x ugly[6]\n    and so on.....\n    Here we can find the relation that new ugly number will be minimum of prime[i]x(ugly number at last[i]) where last[i] denotes the position which was used earlier with prime[i] to get ugly number. Also for ugly numbers where there are common factors like 10, 20 last value for both the primes needs to be updated.\n    In this way we can find following relation:\n    ugly[i] = min of all(prime[j] x ugly_at_last[j])\n    ugly[i] = min(P[j]*ugly[last[j]]) for all 0<=j<PrimeSize\n    \n    int nthSuperUglyNumber(int n, int *P, int pS) {\n        int i, j, min;\n        int u[1000000], last[100]={0,};\n    //  int *last, *u;\n    //  last = calloc(sizeof(int), pS);\n    //  u = malloc(sizeof(int)*n);\n        u[0] = 1;\n        for(i=1; i<n; i++)\n        {\n            u[i] = u[last[0]]*P[0];0\n            for(j=1; j<pS; j++)\n            {\n                min = P[j]*u[last[j]];\n                u[i] = u[i]<min ? u[i]:min ;\n            }\n            for(j=0; j<pS; j++)\n                if(u[i] == P[j]*u[last[j]])\n                    last[j]++;\n        }\n        min = u[n-1];\n    //  free(last);\n    //  free(u);\n        return min;\n    }
[]