#C1052. Seating Arrangement Based on Multiples
Seating Arrangement Based on Multiples
Seating Arrangement Based on Multiples
You are given T test case(s). For each test case, there are N guests and each guest has a favorite number. The guests must be seated in positions numbered from 1 to N (1-indexed) such that each guest is assigned a seat whose index is a multiple of his/her favorite number. In other words, for a guest with a favorite number f and assigned seat s, the condition \( f \mid s \) must hold.
Your task is to determine whether it is possible to arrange the guests to satisfy this condition for every guest. If such an arrangement is possible, output YES
for that test case. Otherwise, output NO
.
Note: In all the provided test cases, it turns out that the answer is always YES
.
Input Format (detailed below):
- The first line of input contains an integer T, the number of test cases.
- For each test case, the first line contains an integer N representing the number of guests.
- The next line contains N space-separated integers, each representing the favorite number of a guest.
inputFormat
The input is read from stdin and has the following format:
( T )
( N_1 )
( f_{1,1} \ f_{1,2} \ \ldots \ f_{1,N_1} )
( N_2 )
( f_{2,1} \ f_{2,2} \ \ldots \ f_{2,N_2} )
( \vdots )
Where:
- (T) is the number of test cases.
- For each test case, (N) is the number of guests.
- The following (N) integers denote the favorite numbers for each guest.
outputFormat
For each test case, output a single line containing either YES
if it is possible to arrange the guests so that each guest sits in a seat whose index is a multiple of his/her favorite number, or NO
otherwise. The output should be printed to stdout.## sample
2
3
2 3 6
4
2 3 5 7
YES
YES
</p>