Hacker Decrypting Messages
Practice
3.9 (58 votes)
Approved
Easy
Math
Number theory
Problem
62% Success 22188 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code

Alex has started hacking websites, and also started learning encryption and decryption of messages. Once he faced an interesting issue, where he needs to decrypt the message in a different way.
Initially, he will be given an array A of N integers, and has to decrypt Q messages. In each message he will get an integer X, and if X can be converted into product of two different or same prime numbers, then the real message is "YES" (without quotes), otherwise the message is "NO" (without quotes).

To convert X, he can choose one element from array say Y (X should be divisible Y), and can divide X by Y any number of times (till X is divisible by Y). Help Alex in decrypting the messages.

Input Format:

First line will contain an integer N and Q,, denoting the number of elements in the array and number of encrypted messages respectively.

Next line will contain N space-separated integers representing the elements of the array.

In next Q lines, each line will contain an integer X , representing an encrypted message.

Output Format:

For each encrypted message, output the decrypted message in new line.

Constraints:
\(1 \le N \le 10^5 \)
\( 0 \le A_i \le 10^6\)
\( 1 \le Q \le 10^6 \)
\( 0 \le X \le 10^6 \)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
59 votes
Tags:
ApprovedEasyMathNumber TheoryOpen
Points:30
23 votes
Tags:
EasyNumber Theory
Points:30
19 votes
Tags:
AlgorithmsEuler's totient functionGreatest common divisorMathNumber TheorySieve