PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000128. Chia và cân bằng (Divide and Equalize)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chia và cân bằng (Divide and Equalize)
Divide and Equalize
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given positive integers, an operation chooses distinct indices and a positive divisor of , then replaces with and with . Any number of operations, including zero, is allowed. Decide whether all elements can become equal.
Input
The first line contains ; the second contains integers .
Output
Print YES if all values can be made equal, and NO otherwise.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
5
100 2 50 10 1
Output
YES
Explanation
Transfer factor 5 from 50 to 2, obtaining [100,10,10,10,1]. Then transfer factor 10 from 100 to 1 to obtain five copies of 10.