Created
October 22, 2017 22:38
-
-
Save MukulLatiyan/be89922b6d8e1cac80f26cce60819090 to your computer and use it in GitHub Desktop.
Equal to product(GeeksForGeeks)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Java code for eual to product problem given on geeksforgeeks array school section. | |
import java.util.*; | |
import java.lang.*; | |
import java.io.*; | |
class GFG { | |
public static void main (String[] args) { | |
Scanner scan = new Scanner(System.in); | |
int ntest = scan.nextInt(); | |
outer: | |
while (ntest-- > 0){ | |
int size = scan.nextInt(), mult = scan.nextInt(); | |
int arr[] = new int[size]; | |
for (int i = 0; i < size; i++){ | |
arr[i] = scan.nextInt(); | |
} | |
Arrays.sort(arr); | |
for (int i = 0; i < size; i++){ | |
if (arr[i] > mult){ | |
break; | |
} | |
if (arr[i] == 0 || mult % arr[i] != 0){ | |
continue; | |
} | |
if (Arrays.binarySearch(arr, mult / arr[i]) >= 0){ | |
System.out.println("Yes"); | |
continue outer; | |
} | |
} | |
System.out.println("No"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment