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
| #include <bits/stdc++.h> #define int long long
using namespace std;
int N, A, B; int Ans[1000000 + 100];
inline int ex_gcd (int a, int b, int &x, int &y) { if (!b) { x = 1; y = 0; return a; } int gcd = ex_gcd (b, a % b, x, y); int tmp = x; x = y; y = tmp - a / b * y; return gcd; }
main() { #ifdef hk_cnyali freopen("C.in", "r", stdin); freopen("C.out", "w", stdout); #endif scanf("%lld%lld%lld", &N, &A, &B); int x, y; int g = ex_gcd(A, B, x, y); if (N % g) { cout<<-1<<endl; return 0; } B /= g; int t1 = ((N / g) * x % B + B) % B; B *= g; int p1 = (N - A * t1) / B; A /= g; int p2 = ((N / g) * y % A + A) % A; A *= g; int t2 = (N - B * p2) / A; if ((p1 < 0) || (t2 < 0)) { cout<<-1<<endl; return 0; } if (p2 >= 0 && t2 >= 0) p1 = p2, t1 = t2; swap(p1, t1); for (int i = 0; i < p1; ++i) { Ans[i * A + 1] = i * A + A; for (int j = 2; j <= A; ++j) Ans[i * A + j] = i * A + j - 1; } for (int i = 0; i < t1; ++i) { Ans[A * p1 + i * B + 1] = A * p1 + i * B + B; for (int j = 2; j <= B; ++j) Ans[A * p1 + i * B + j] = A * p1 + i * B + j - 1; } for (int i = 1; i <= N; ++i) cout<<Ans[i]<<" "; cout<<endl; return 0; }
|