`{"id":"62dfef2f-1825-446e-97ba-bc0c09f6782e","name":"Super Ugly Number","description":"1. You are given an array(arr) of size k which contains prime numbers in ascending order, and an integer N.\r\n2. You have to find Nth super ugly number.\r\n3. Super ugly number is defined as the number whose prime factors are elements of the given array.\r\n\r\nAssumption -> 1 is the first super ugly number.","inputFormat":"A number K\r\narr1\r\narr2.. K prime numbers in ascending order\r\nA number N","outputFormat":"A number representing Nth super ugly number.","constraints":"1 &lt;= K &lt;= 100\r\n1 &lt;= arr[i] &lt;= 1000\r\n1 &lt;= N &lt;= 10^6","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int solution(int[] primes, int n) {\r\n // write your code here\r\n\r\n }\r\n\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int k = scn.nextInt();\r\n int[] primes = new int[k];\r\n for (int i = 0 ; i < k; i++) {\r\n primes[i] = scn.nextInt();\r\n }\r\n int n = scn.nextInt();\r\n System.out.println(solution(primes, n));\r\n }\r\n\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"4\r\n3 5 7 11\r\n13","sampleOutput":"45\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"afb0eb13-c38b-450a-95db-aacb6c12329f","name":"Super Ugly Number","slug":"super-ugly-number","type":1}],"next":{"id":"351ded63-248f-4ca0-b6bd-1ef265a86635","name":"Find Water In Glass","type":1,"slug":"find-water-in-glass"},"prev":{"id":"6d4b494a-ee6a-4d62-a348-14712ed7fe2d","name":"Ugly Number","type":1,"slug":"ugly-number"}}}`

# Super Ugly Number

1. You are given an array(arr) of size k which contains prime numbers in ascending order, and an integer N. 2. You have to find Nth super ugly number. 3. Super ugly number is defined as the number whose prime factors are elements of the given array. Assumption -> 1 is the first super ugly number.

`{"id":"62dfef2f-1825-446e-97ba-bc0c09f6782e","name":"Super Ugly Number","description":"1. You are given an array(arr) of size k which contains prime numbers in ascending order, and an integer N.\r\n2. You have to find Nth super ugly number.\r\n3. Super ugly number is defined as the number whose prime factors are elements of the given array.\r\n\r\nAssumption -> 1 is the first super ugly number.","inputFormat":"A number K\r\narr1\r\narr2.. K prime numbers in ascending order\r\nA number N","outputFormat":"A number representing Nth super ugly number.","constraints":"1 &lt;= K &lt;= 100\r\n1 &lt;= arr[i] &lt;= 1000\r\n1 &lt;= N &lt;= 10^6","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int solution(int[] primes, int n) {\r\n // write your code here\r\n\r\n }\r\n\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int k = scn.nextInt();\r\n int[] primes = new int[k];\r\n for (int i = 0 ; i < k; i++) {\r\n primes[i] = scn.nextInt();\r\n }\r\n int n = scn.nextInt();\r\n System.out.println(solution(primes, n));\r\n }\r\n\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"4\r\n3 5 7 11\r\n13","sampleOutput":"45\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"afb0eb13-c38b-450a-95db-aacb6c12329f","name":"Super Ugly Number","slug":"super-ugly-number","type":1}],"next":{"id":"351ded63-248f-4ca0-b6bd-1ef265a86635","name":"Find Water In Glass","type":1,"slug":"find-water-in-glass"},"prev":{"id":"6d4b494a-ee6a-4d62-a348-14712ed7fe2d","name":"Ugly Number","type":1,"slug":"ugly-number"}}}` Editor

# Super Ugly Number

medium

1. You are given an array(arr) of size k which contains prime numbers in ascending order, and an integer N. 2. You have to find Nth super ugly number. 3. Super ugly number is defined as the number whose prime factors are elements of the given array. Assumption -> 1 is the first super ugly number.

## Constraints

1 <= K <= 100 1 <= arr[i] <= 1000 1 <= N <= 10^6

## Format

### Input

A number K arr1 arr2.. K prime numbers in ascending order A number N

### Output

A number representing Nth super ugly number.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}4 3 5 7 11 13```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}45 ```

Discussions

Show Discussion

Related Resources 