QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#129328#273. 类欧几里得算法exxqfu#100 ✓163ms3392kbC++143.0kb2023-07-22 15:22:092023-07-22 15:22:12

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 15:22:12]
  • 评测
  • 测评结果:100
  • 用时:163ms
  • 内存:3392kb
  • [2023-07-22 15:22:09]
  • 提交

answer

#include <cstdio>
#define rep(i, d, u) for(int i = d; i <= u; ++i)
#define cep(n) while(n--)
int ured() {
	int re = 0;
	char ch;
	do {
		ch = getchar();
	} while('9' < ch || ch < '0');
	do {
		re = re * 10 + (ch ^ '0');
	} while('0' <= (ch = getchar()) && ch <= '9');
	return re;
}
void uwit(int da) {
	int ch[21], cn = 0;
	do {
		ch[++cn] = da - da / 10 * 10;
	} while(da /= 10);
	do {
		putchar('0' ^ ch[cn]);
	} while(--cn);
}
const int _mods = 1000000007, _maxs = 37, _maxa = 11;
int incd(int le, int ri) {
	return le + ri >= _mods ? le + ri - _mods : le + ri;
}
int dcnt;
struct matr {
	int da[_maxs][_maxs];
} adat, bdat;
matr operator+(matr le, matr ri) {
	matr re;
	rep(i, 0, dcnt - 1) {
		rep(j, i, dcnt - 1) {
			re . da[i][j] = 0;
		}
	}
	rep(i, 0, dcnt - 1) {
		rep(j, i, dcnt - 1) {
			if(le . da[i][j]) {
				rep(k, j, dcnt - 1) {
					if(ri . da[j][k]) {
						re . da[i][k] = (1ll * le . da[i][j] * ri . da[j][k] + re . da[i][k]) % _mods;
					}
				}
			}
		}
	}
	return re;
}
matr operator*(matr le, int ri) {
	matr re;
	if(ri) {
		re = le, --ri;
		while(ri) {
			if(ri & 1) {
				re = re + le;
			}
			le = le + le, ri >>= 1;
		}
		return re;
	} else {
		rep(i, 0, dcnt - 1) {
			rep(j, i, dcnt - 1) {
				re . da[i][j] = i == j;
			}
		}
		return re;
	}
}
int max(int le, int ri) {
	return le > ri ? le : ri;
}
int t, n, a, b, c, f, s, comb[_maxa][_maxa];
matr solv(int dp, int dr, int dq, int dn, matr da, matr db) {
	if(1ll * dp * dn + dr < dq) {
		return db * dn;
	} else if(dp >= dq) {
		return solv(dp % dq, dr, dq, dn, da, da * (dp / dq) + db);
	} else {
		int ya = (1ll * dp * dn + dr) / dq, xa = (1ll * dq * ya - dr - 1) / dp;
		return db * ((dq - dr - 1) / dp) + da + solv(dq, (dq - dr - 1) % dp, dp, ya - 1, db, da) + db * (dn - xa);
	}
}
int qpow(int da, int up) {
	int re = 1;
	while(up) {
		if(up & 1) {
			re = 1ll * re * da % _mods;
		}
		da = 1ll * da * da % _mods, up >>= 1;
	}
	return re;
}
int main() {
	t = ured();
	cep(t) {
		n = ured(), a = ured(), b = ured(), c = ured(), f = ured(), s = ured(), dcnt = (f + 1) * (s + 1) + 1, comb[0][0] = 1;
		rep(i, 1, max(f, s)) {
			comb[i][0] = 1;
			rep(j, 1, i) {
				comb[i][j] = incd(comb[i - 1][j - 1], comb[i - 1][j]);
			}
		}
		rep(i, 0, (f + 1) * (s + 1)) {
			rep(j, i, (f + 1) * (s + 1)) {
				adat . da[i][j] = bdat . da[i][j] = 0;
			}
		}
		rep(i, 0, (f + 1) * (s + 1) - 1) {
			rep(j, 0, i % (s + 1)) {
				adat . da[i / (s + 1) * (s + 1) + j][i] = comb[i % (s + 1)][j];
			}
			rep(j, 0, i / (s + 1)) {
				bdat . da[j * (s + 1) + i % (s + 1)][i] = comb[i / (s + 1)][j];
			}
		}
		rep(i, 0, f) {
			bdat . da[i * (s + 1) + s][(f + 1) * (s + 1)] = comb[f][i];
		}
		adat . da[(f + 1) * (s + 1)][(f + 1) * (s + 1)] = bdat . da[(f + 1) * (s + 1)][(f + 1) * (s + 1)] = 1;
		uwit(incd((adat * (b / c) + solv(a, b % c, c, n, adat, bdat)) . da[0][(f + 1) * (s + 1)], f ? 0 : qpow(b / c, s))), putchar('\n');
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 37ms
memory: 3360kb

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: 38ms
memory: 3352kb

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: 37ms
memory: 3352kb

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: 38ms
memory: 3372kb

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: 159ms
memory: 3392kb

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: 162ms
memory: 3356kb

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: 163ms
memory: 3352kb

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: 158ms
memory: 3308kb

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: 163ms
memory: 3388kb

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: 158ms
memory: 3388kb

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