J - Worker
Avin meets a rich customer today. He will earn 1 million dollars if he can solve a hard problem. There are n warehouses and m workers. Any worker in the i-th warehouse can handle ai orders per day. The customer wonders whether there exists one worker assignment method satisfying that every warehouse handles the same number of orders every day. Note that each worker should be assigned to exactly one warehouse and no worker is lazy when working.
Input
The first line contains two integers n (1 ≤ n ≤ 1, 000), m (1 ≤ m ≤ 1018). The second line contains n integers. The i-th integer ai (1 ≤ ai ≤ 10) represents one worker in the i-th warehouse can handle ai orders per day.
Output
If there is a feasible assignment method, print “Yes” in the first line. Then, in the second line, print n integers with the i-th integer representing the number of workers assigned to the i-th warehouse.
Otherwise, print “No” in one line. If there are multiple solutions, any solution is accepted.
Sample Input
2 6
1 2
2 5
1 2
Sample Output
Yes
4 2
No
题目大意:这道题题意是给n个车间,m个工人,然后第i个车间每天每人能处理ai件订单,如果可以让每个车间每天处理的订单数相同并且没有人闲着,那么输出"Yes"并且把其中的一种方案输出出来,如果不存在这样的情况,那么就输出"No".
解题思路:这道题可以直接求出所有车间每人能处理订单数的lcm,然后用求出的lcm除以每一个车间单人可以处理的订单数保存在数组中,并且将这个数组中的所有成员相加。如果m模上这个sum为0,那么就说明有适合的方案,然后就输出,如果不为0,那么就说明没有适合的方案,就输出"No".
#include<iostream>