File tree Expand file tree Collapse file tree 1 file changed +71
-0
lines changed
Expand file tree Collapse file tree 1 file changed +71
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < algorithm>
2+ #include < iostream>
3+ #include < sstream>
4+ #include < string>
5+ #include < vector>
6+ #include < queue>
7+ #include < set>
8+ #include < map>
9+ #include < cstdio>
10+ #include < cstdlib>
11+ #include < cctype>
12+ #include < cmath>
13+ #include < string>
14+ #include < cstring>
15+ using namespace std ;
16+
17+ #define REP (i,n ) for (int i=0 ;i<(n);++i)
18+ #define FOR (i,a,b ) for (int i=(a);i<=(b);++i)
19+ #define RFOR (i,a,b ) for (int i=(a);i>=(b);--i)
20+ typedef long long LL;
21+ typedef vector<long long > VI;
22+
23+ LL gcd (LL a,LL b){
24+ return b?gcd (b,a%b):a;
25+ }
26+
27+ LL ext_gcd (LL a,LL b,LL& x,LL& y){
28+ LL t,ret;
29+ if (!b){
30+ x=1 ,y=0 ;
31+ return a;
32+ }
33+ ret=ext_gcd (b,a%b,x,y);
34+ t=x,x=y,y=t-a/b*y;
35+ return ret;
36+ }
37+
38+ int main () {
39+ int n, p, b;
40+ cin >> n >> p >> b;
41+ VI a (n);
42+ LL g = p;
43+ REP (i,n) {
44+ cin >> a[i];
45+ g = gcd (g, a[i]);
46+ }
47+
48+ if (b % g != 0 ) {
49+ cout << " NO" << endl;
50+ } else {
51+ cout << " YES" << endl;
52+ VI mod (n), x (n);
53+ mod[0 ] = p;
54+ FOR (i,1 ,n-1 ) mod[i] = gcd (mod[i - 1 ], a[i - 1 ]);
55+
56+ LL tmp;
57+ RFOR (i,n-1 ,0 ) {
58+ LL ret = ext_gcd (a[i], mod[i], x[i], tmp);
59+ x[i] *= b / ret;
60+ x[i] = (x[i] % p + p) % p;
61+ b = ((b - a[i] * x[i]) % p + p) % p;
62+ }
63+
64+ REP (i,n) {
65+ if (i) cout << " " ;
66+ cout << x[i];
67+ }
68+ cout << endl;
69+ }
70+ return 0 ;
71+ }
You can’t perform that action at this time.
0 commit comments