Worker

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)

Problem Description

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

思路:

因为最后的数目要相等,所以这就一定要是这些的公倍数,因为我们不知道是哪一个公倍数,所以我们就先求出最小公倍数,这个需要求的公倍数肯定是倍数的关系了,然后就判断工人数是否符合条件,因为公倍数与最小公倍数是倍数的关系,所以工人数也是倍数的关系,只要能够整除,那么工人一定符合条件,然后算出倍数在乘以每个位置工人数就出来。

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
int main() {
    int n;
    ll m;
    while (scanf("%d %lld", &n, &m) != EOF) {
        ll a[1010] = {0}, b[1010] = {0};
        ll lc = 1;
        for (int i = 0; i < n; i++) {
            scanf("%lld", &a[i]);
            lc = lcm(a[i], lc);
        }
        ll sum = 0;
        for (int i = 0; i < n; i++) {
            b[i] = lc / a[i];
            sum += b[i];
        }
        if (m % sum != 0) {
            printf("No\n");
            continue;
        }
        printf("Yes\n");
        ll x = m / sum;
        for (int i = 0; i < n; i++) {
            if (i != 0) printf(" ");
            printf("%lld", b[i] * x);
        }
        printf("\n");
    }
    return 0;
}