QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#132293#5661. Multi-Ladderswillow#AC ✓1ms3640kbC++141.2kb2023-07-29 13:49:012023-07-29 13:49:03

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-29 13:49:03]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3640kb
  • [2023-07-29 13:49:01]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const int MOD = 1e9 + 7;

inline void Inc(int &x, int y) {
	x += y; if (x >= MOD) x -= MOD;
}
inline void Dec(int &x, int y) {
	x -= y; if (x < 0) x += MOD;
}
inline int Mul(int x, int y) {
	return 1LL * x * y % MOD;
}
inline int Ksm(int x, int y) {
	int ret = 1;
	for (; y; y >>= 1) {
		if (y & 1) ret = Mul(ret, x);
		x = Mul(x, x);
	}
	return ret;
}
inline int Inv(int x) {
	return Ksm(x, MOD - 2);
}

void solve() {
	int n, k, c;
	scanf("%d %d %d", &n, &k, &c);
	if (c <= 1) {
		puts("0");
		return;
	}
	if ((k & 1) && c == 2) {
		puts("0");
		return;
	}
	int ans = 1;
	if (k & 1) {
		Inc(ans, Ksm(c - 1, k));
	} else {
		Dec(ans, Ksm(c - 1, k));
	}
	ans = Mul(ans, Inv(c));
	Dec(ans, 1);
	if (!(k & 1)) {
		ans = (MOD - ans) % MOD;
	}
	ans = Mul(ans, c);
	cerr << ans << endl;
	int d = 1;
	if (c >= 3) {
		Inc(d, Mul(2, c - 2));
	}
	if (c >= 4) {
		Inc(d, Mul(c - 2, c - 3));
	}
	ans = Mul(ans, Ksm(d, 1LL * k * (n - 1) % (MOD - 1)));
	printf("%d\n", ans);
}

int main() {
	int T; scanf("%d", &T);
	while (T--) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3640kb

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3568kb

input:

20
2 3 3
1 3 3
10 3 0
10 3 2
1 21 2
1 22 0
2000 15000 2000
12000 30000 200000
1000000000 3 3
2 1000000000 3
2 3 100000000
1000000000 1000000000 10
1000000000 3 100000000
2 1000000000 100000000
1 1000000000 10
1 1000000000 100000000
1 1000 100000000
1000000000 1000000000 0
1000000000 1000000000 1
100...

output:

162
6
0
0
0
0
349400141
243010659
52489881
53690844
176686901
218103365
558243892
991895211
693053429
883715672
80402569
0
0
311752813

result:

ok 20 lines