Cryptographically Strong Keys
Time limit2sMemory limit256 MB
Given numbers a_i, the closure under gcd and lcm defines a set S; decide whether a query value v lies in S.
- Level
Hard8 of 10
- Topics
- Number theory, Math, Greedy, Hash map
- Solved
- No attempts yet
Problem
Pasha has created his own data encryption protocol. In this protocol, the key used for encryption must belong to the set of cryptographically strong keys, which is built from a set of numbers .
The set is the inclusion-minimal set with the following two properties:
- Every number belongs to .
- If and belong to , then their greatest common divisor and their least common multiple also belong to .
Pasha wants to use the number as the key. Determine whether belongs to the set of cryptographically strong keys.
Input
The first line contains a positive integer , the number of test cases in the input. does not exceed 5. The descriptions of the test cases follow.
Each test case consists of three lines. The first line contains a positive integer (). The second line contains numbers (). The third line contains the number () whose membership in the set of cryptographically strong keys must be checked.
Output
For each of the test cases, output YES on a separate line if belongs to the set of cryptographically strong keys, and NO otherwise.