QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#269932#5661. Multi-LaddersSTnofarjo#AC ✓1ms3344kbC++20773b2023-11-30 11:43:122023-11-30 11:43:12

Judging History

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

  • [2023-11-30 11:43:12]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3344kb
  • [2023-11-30 11:43:12]
  • 提交

answer

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

using ll = long long;

const ll MOD = 1e9 + 7;

ll fpow(ll a, ll b) {
	ll ret = 1;
	while (b) {
		if (b & 1) ret = (ret * a) % MOD;
		a = (a * a) % MOD;
		b >>= 1;
	}
	return ret;
}

void solve() {
	ll n, k, v;
	cin >> n >> k >> v;
	if (v <= 1) {
		cout << 0 << '\n';
		return;
	}
	ll cyc = fpow(v - 1, k);
	ll tmp = ((k & 1) ? -1 : 1);
	cyc = (cyc + (v - 1) * tmp) % MOD;
	ll sides = ((v - 1) * (v - 1) - (v - 2)) % MOD;
	sides = fpow(sides, (n - 1) * k) % MOD;
	ll ans = (sides * cyc) % MOD;
	if (ans < 0) ans += MOD;
	cout << ans << '\n';
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

	int tc;
	cin >> tc;
	for (int i = 0; i < tc; i++) {
		solve();
	}

	return 0;
}

详细

Test #1:

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

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3328kb

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