| Task: | Jubilee |
| Sender: | freefoodfreepoints |
| Submission time: | 2025-11-08 16:12:56 +0200 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.00 s | details |
| #3 | ACCEPTED | 0.00 s | details |
| #4 | ACCEPTED | 0.00 s | details |
| #5 | ACCEPTED | 0.00 s | details |
| #6 | ACCEPTED | 0.02 s | details |
| #7 | ACCEPTED | 0.00 s | details |
| #8 | ACCEPTED | 0.02 s | details |
| #9 | ACCEPTED | 0.00 s | details |
| #10 | ACCEPTED | 0.02 s | details |
| #11 | ACCEPTED | 0.02 s | details |
| #12 | ACCEPTED | 0.00 s | details |
| #13 | ACCEPTED | 0.00 s | details |
| #14 | ACCEPTED | 0.01 s | details |
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define til(n) for(ll i = 0; i < n; i++)
constexpr ll mod = 1e9+7;
ll euclid(ll a, ll b, ll& x, ll& y){
if (!b) return x=1,y=0,a;
ll d = euclid(b,a%b,y,x);
return y-=a/b * x, d;
}
struct Mod {
ll x;
Mod(ll xx) : x(xx) {}
Mod operator* (Mod b) { return Mod((x * b.x) % mod); }
Mod operator/ (Mod b) { return *this * invert(b); }
Mod operator- (Mod b) { return Mod((x-b.x+mod) % mod); }
Mod operator+ (Mod b) { return Mod((x+b.x) % mod); }
Mod invert(Mod a) {
ll x,y,g = euclid(a.x,mod,x,y);
assert (g==1);
return Mod((x+mod) % mod);
}
};
int main() {
cin.tie(0)->sync_with_stdio(false);
cout.tie(0)->sync_with_stdio(false);
ll n2, m2;
cin >> n2 >> m2;
Mod n(n2);
Mod m(m2);
Mod total = 1;
// first two seats at the end of the table
total = total * m;
total = total * (m - 1);
til(n2-1) {
auto same = total;
auto diff = total * (m - 2);
total = (same * (m-1)) + (diff * (m-2));
}
cout << total.x << '\n';
}Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 3 2 |
| correct output |
|---|
| 2 |
| user output |
|---|
| 2 |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 1 1 |
| correct output |
|---|
| 0 |
| user output |
|---|
| 0 |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 1 1000000000 |
| correct output |
|---|
| 56 |
| user output |
|---|
| 56 |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 2 1000000000 |
| correct output |
|---|
| 4088 |
| user output |
|---|
| 4088 |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 3 1000000000 |
| correct output |
|---|
| 298424 |
| user output |
|---|
| 298424 |
Test 6
Verdict: ACCEPTED
| input |
|---|
| 1000000 1000000000 |
| correct output |
|---|
| 859388820 |
| user output |
|---|
| 859388820 |
Test 7
Verdict: ACCEPTED
| input |
|---|
| 2 1 |
| correct output |
|---|
| 0 |
| user output |
|---|
| 0 |
Test 8
Verdict: ACCEPTED
| input |
|---|
| 1000000 1 |
| correct output |
|---|
| 0 |
| user output |
|---|
| 0 |
Test 9
Verdict: ACCEPTED
| input |
|---|
| 1 2 |
| correct output |
|---|
| 2 |
| user output |
|---|
| 2 |
Test 10
Verdict: ACCEPTED
| input |
|---|
| 1000000 2 |
| correct output |
|---|
| 2 |
| user output |
|---|
| 2 |
Test 11
Verdict: ACCEPTED
| input |
|---|
| 1000000 3 |
| correct output |
|---|
| 129870828 |
| user output |
|---|
| 129870828 |
Test 12
Verdict: ACCEPTED
| input |
|---|
| 1 3 |
| correct output |
|---|
| 6 |
| user output |
|---|
| 6 |
Test 13
Verdict: ACCEPTED
| input |
|---|
| 21355 1239478 |
| correct output |
|---|
| 74219157 |
| user output |
|---|
| 74219157 |
Test 14
Verdict: ACCEPTED
| input |
|---|
| 531578 913517291 |
| correct output |
|---|
| 105420893 |
| user output |
|---|
| 105420893 |
