Submission details
Task:Jubilee
Sender:freefoodfreepoints
Submission time:2025-11-08 16:12:56 +0200
Language:C++ (C++20)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.02 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.02 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.02 sdetails
#11ACCEPTED0.02 sdetails
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.00 sdetails
#14ACCEPTED0.01 sdetails

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