forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path140.cpp
More file actions
71 lines (64 loc) · 1.39 KB
/
140.cpp
File metadata and controls
71 lines (64 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <string>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long LL;
typedef vector<long long> VI;
LL gcd(LL a,LL b){
return b?gcd(b,a%b):a;
}
LL ext_gcd(LL a,LL b,LL& x,LL& y){
LL t,ret;
if (!b){
x=1,y=0;
return a;
}
ret=ext_gcd(b,a%b,x,y);
t=x,x=y,y=t-a/b*y;
return ret;
}
int main() {
int n, p, b;
cin >> n >> p >> b;
VI a(n);
LL g = p;
REP(i,n) {
cin >> a[i];
g = gcd(g, a[i]);
}
if (b % g != 0) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
VI mod(n), x(n);
mod[0] = p;
FOR(i,1,n-1) mod[i] = gcd(mod[i - 1], a[i - 1]);
LL tmp;
RFOR(i,n-1,0) {
LL ret = ext_gcd(a[i], mod[i], x[i], tmp);
x[i] *= b / ret;
x[i] = (x[i] % p + p) % p;
b = ((b - a[i] * x[i]) % p + p) % p;
}
REP(i,n) {
if (i) cout << " ";
cout << x[i];
}
cout << endl;
}
return 0;
}