QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#129228#273. 类欧几里得算法Scintilla#100 ✓181ms4472kbC++142.4kb2023-07-22 08:32:172023-07-22 08:32:20

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-22 08:32:20]
  • 评测
  • 测评结果:100
  • 用时:181ms
  • 内存:4472kb
  • [2023-07-22 08:32:17]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define drep(i, s, e) for (int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define pv(a) cout << #a << " = " << a << endl
#define pa(a, l, r) cout << #a " : "; rep(_, l, r) cout << a[_] << ' '; cout << endl

const int P = 1e9 + 7;

const int N = 10 + 5;

int read() {
  int x = 0, f = 1; char c = getchar();
  for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
  return x * f;
}

int inc(int a, int b) { return (a += b) >= P ? a - P : a; }
int dec(int a, int b) { return (a -= b) < 0 ? a + P : a; }
int mul(int a, int b) { return 1ll * a * b % P; }
int qpow(int a, int b) { int res = 1; for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a); return res; }

int a, b, c, n, k1, k2, C[N][N];

void init(int w) {
  rep(i, 0, w) C[i][0] = 1;
  rep(i, 1, w) rep(j, 1, i) C[i][j] = inc(C[i - 1][j], C[i - 1][j - 1]);
}

struct node {
  int u, r, f[N][N];
  node(int _u = 0, int _r = 0) { u = _u, r = _r; rep(i, 0, k1) rep(j, 0, k2) f[i][j] = 0; }
  int* operator [] (int i) { return f[i]; }
  friend node operator * (node a, node b) {
    node res(inc(a.u, b.u), inc(a.r, b.r));
    rep(u, 0, k1) rep(v, 0, k2) {
      // if (u == 0 && v == 1) cout << "!!!\n";
      res[u][v] = a[u][v];
      rep(i, 0, u) rep(j, 0, v) {
        int t = mul(b[i][j], mul(C[u][i], C[v][j]));
        t = mul(t, mul(qpow(a.r, u - i), qpow(a.u, v - j)));
        res[u][v] = inc(res[u][v], t);
      }
    }
    return res;
  }
} fu(1, 0), fr(0, 1);

node qpow(node a, int b) {
  node res;
  for (; b; b >>= 1, a = a * a) if (b & 1) res = res * a;
  return res;
}

node calc(int a, int b, int c, int n, node fu, node fr) {
  b %= c;
  if (a >= c) return calc(a % c, b, c, n, fu, qpow(fu, a / c) * fr);
  else {
    int m = (a * n + b) / c;
    if (!m) return qpow(fr, n);
    else return qpow(fr, (c - b - 1) / a) * fu * calc(c, c - b - 1, a, m - 1, fr, fu) * qpow(fr, n - (c * m - b - 1) / a);
  }  
}

signed main() {
  fr[0][0] = 1, init(10);
  for (int tc = read(); tc; -- tc) {
    n = read(), a = read(), b = read(), c = read(), k1 = read(), k2 = read();
    node res = qpow(fu, b / c) * fr * calc(a, b, c, n, fu, fr);
    printf("%lld\n", res[k1][k2]);
  }
  return 0;
}

详细

Test #1:

score: 10
Accepted
time: 21ms
memory: 4300kb

input:

1000
846930887 681692778 714636916 89384 0 1
424238336 719885387 649760493 47794 0 1
189641422 25202363 350490028 16650 0 1
102520060 44897764 967513927 68691 0 1
540383427 304089173 303455737 80541 0 1
521595369 294702568 726956430 5212 0 1
861021531 278722863 233665124 65783 0 1
468703136 10151393...

output:

787440837
603410377
723035859
327613252
213481743
197744321
183595532
306097937
945612263
462240557
878873337
913033603
276973800
137776104
471637127
36869524
59950373
599468074
662996688
39221965
159523453
603757410
863747292
125209174
321695224
581226543
502962761
546511215
492741651
881346590
834...

result:

ok 1000 numbers

Test #2:

score: 10
Accepted
time: 17ms
memory: 4340kb

input:

1000
846930887 681692778 714636916 89384 0 1
424238336 719885387 649760493 47794 0 1
189641422 25202363 350490028 16650 0 1
102520060 44897764 967513927 68691 0 1
540383427 304089173 303455737 80541 0 1
521595369 294702568 726956430 5212 0 1
861021531 278722863 233665124 65783 0 1
468703136 10151393...

output:

787440837
603410377
723035859
327613252
213481743
197744321
183595532
306097937
945612263
462240557
878873337
913033603
276973800
137776104
471637127
36869524
59950373
599468074
662996688
39221965
159523453
603757410
863747292
125209174
321695224
581226543
502962761
546511215
492741651
881346590
834...

result:

ok 1000 numbers

Test #3:

score: 10
Accepted
time: 21ms
memory: 4340kb

input:

1000
846930887 681692778 714636916 89384 1 0
649760493 596516650 189641422 85387 0 1
102520060 44897764 967513927 68691 0 0
303455737 35005212 521595369 89173 1 0
861021531 278722863 233665124 65783 1 0
801979803 315634023 635723059 13930 1 0
89018457 628175012 656478043 61394 1 0
914544920 60841378...

output:

590247101
607294734
102520061
988535616
258549494
359848706
860104659
914544921
806512744
219134560
36869524
54386320
1100547
760313752
603757410
510232691
82579690
843146721
36876088
935671592
290199337
365292116
534011850
126900199
669344073
690573152
719144156
644864030
602224207
100895714
452066...

result:

ok 1000 numbers

Test #4:

score: 10
Accepted
time: 21ms
memory: 4360kb

input:

1000
846930887 681692778 714636916 89384 1 0
649760493 596516650 189641422 85387 0 1
102520060 44897764 967513927 68691 0 0
303455737 35005212 521595369 89173 1 0
861021531 278722863 233665124 65783 1 0
801979803 315634023 635723059 13930 1 0
89018457 628175012 656478043 61394 1 0
914544920 60841378...

output:

590247101
607294734
102520061
988535616
258549494
359848706
860104659
914544921
806512744
219134560
36869524
54386320
1100547
760313752
603757410
510232691
82579690
843146721
36876088
935671592
290199337
365292116
534011850
126900199
669344073
690573152
719144156
644864030
602224207
100895714
452066...

result:

ok 1000 numbers

Test #5:

score: 10
Accepted
time: 174ms
memory: 4264kb

input:

1000
846930887 681692778 714636916 89384 3 3
649760493 596516650 189641422 85387 2 3
102520060 44897764 967513927 68691 0 6
303455737 35005212 521595369 89173 7 0
861021531 278722863 233665124 65783 7 1
801979803 315634023 635723059 13930 9 0
89018457 628175012 656478043 61394 9 0
914544920 60841378...

output:

269986411
687117872
337796106
649269006
273534477
925890819
789776059
781917067
471414212
683680813
655243026
766680733
110386800
920667633
42177293
33248798
268698025
97602241
455950431
787378605
628127823
884695308
910301084
481441390
301149571
40678494
744524425
997602040
853435603
942399367
4371...

result:

ok 1000 numbers

Test #6:

score: 10
Accepted
time: 180ms
memory: 4336kb

input:

1000
846930887 681692778 714636916 89384 3 3
649760493 596516650 189641422 85387 2 3
102520060 44897764 967513927 68691 0 6
303455737 35005212 521595369 89173 7 0
861021531 278722863 233665124 65783 7 1
801979803 315634023 635723059 13930 9 0
89018457 628175012 656478043 61394 9 0
914544920 60841378...

output:

269986411
687117872
337796106
649269006
273534477
925890819
789776059
781917067
471414212
683680813
655243026
766680733
110386800
920667633
42177293
33248798
268698025
97602241
455950431
787378605
628127823
884695308
910301084
481441390
301149571
40678494
744524425
997602040
853435603
942399367
4371...

result:

ok 1000 numbers

Test #7:

score: 10
Accepted
time: 181ms
memory: 4300kb

input:

1000
846930887 681692778 714636916 89384 3 3
649760493 596516650 189641422 85387 2 3
102520060 44897764 967513927 68691 0 6
303455737 35005212 521595369 89173 7 0
861021531 278722863 233665124 65783 7 1
801979803 315634023 635723059 13930 9 0
89018457 628175012 656478043 61394 9 0
914544920 60841378...

output:

269986411
687117872
337796106
649269006
273534477
925890819
789776059
781917067
471414212
683680813
655243026
766680733
110386800
920667633
42177293
33248798
268698025
97602241
455950431
787378605
628127823
884695308
910301084
481441390
301149571
40678494
744524425
997602040
853435603
942399367
4371...

result:

ok 1000 numbers

Test #8:

score: 10
Accepted
time: 181ms
memory: 4472kb

input:

1000
846930887 681692778 714636916 89384 3 3
649760493 596516650 189641422 85387 2 3
102520060 44897764 967513927 68691 0 6
303455737 35005212 521595369 89173 7 0
861021531 278722863 233665124 65783 7 1
801979803 315634023 635723059 13930 9 0
89018457 628175012 656478043 61394 9 0
914544920 60841378...

output:

269986411
687117872
337796106
649269006
273534477
925890819
789776059
781917067
471414212
683680813
655243026
766680733
110386800
920667633
42177293
33248798
268698025
97602241
455950431
787378605
628127823
884695308
910301084
481441390
301149571
40678494
744524425
997602040
853435603
942399367
4371...

result:

ok 1000 numbers

Test #9:

score: 10
Accepted
time: 177ms
memory: 4340kb

input:

1000
846930887 681692778 714636916 89384 3 3
649760493 596516650 189641422 85387 2 3
102520060 44897764 967513927 68691 0 6
303455737 35005212 521595369 89173 7 0
861021531 278722863 233665124 65783 7 1
801979803 315634023 635723059 13930 9 0
89018457 628175012 656478043 61394 9 0
914544920 60841378...

output:

269986411
687117872
337796106
649269006
273534477
925890819
789776059
781917067
471414212
683680813
655243026
766680733
110386800
920667633
42177293
33248798
268698025
97602241
455950431
787378605
628127823
884695308
910301084
481441390
301149571
40678494
744524425
997602040
853435603
942399367
4371...

result:

ok 1000 numbers

Test #10:

score: 10
Accepted
time: 177ms
memory: 4340kb

input:

1000
846930887 681692778 714636916 89384 3 3
649760493 596516650 189641422 85387 2 3
102520060 44897764 967513927 68691 0 6
303455737 35005212 521595369 89173 7 0
861021531 278722863 233665124 65783 7 1
801979803 315634023 635723059 13930 9 0
89018457 628175012 656478043 61394 9 0
914544920 60841378...

output:

269986411
687117872
337796106
649269006
273534477
925890819
789776059
781917067
471414212
683680813
655243026
766680733
110386800
920667633
42177293
33248798
268698025
97602241
455950431
787378605
628127823
884695308
910301084
481441390
301149571
40678494
744524425
997602040
853435603
942399367
4371...

result:

ok 1000 numbers