QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#206529#7562. Except Oneucup-team1264#AC ✓1ms3608kbC++203.7kb2023-10-07 21:00:132023-10-07 21:00:13

Judging History

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

  • [2023-10-07 21:00:13]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3608kb
  • [2023-10-07 21:00:13]
  • 提交

answer

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

namespace modint {

using i64 = int64_t;

template <int P> struct mint {
  private:
    constexpr mint power(mint x, int p) const {
        mint res = 1;
        while (p > 0) {
            if (p & 1) { res *= x; }
            x *= x;
            p >>= 1;
        }
        return res;
    }

  public:
    int x;
    constexpr mint() : x{} {}
    constexpr mint(i64 x) : x{norm(x % getMod())} {}
    static int Mod;
    constexpr static int getMod() {
        if (P > 0) {
            return P;
        } else {
            return Mod;
        }
    }
    constexpr static void setMod(int Mod_) { Mod = Mod_; }
    constexpr int norm(int x) const {
        if (x < 0) { x += getMod(); }
        if (x >= getMod()) { x -= getMod(); }
        return x;
    }
    constexpr int val() const { return x; }
    explicit constexpr operator int() const { return x; }
    constexpr mint operator-() const {
        mint res;
        res.x = norm(getMod() - x);
        return res;
    }
    constexpr mint inv() const {
        assert(x != 0);
        return power(*this, getMod() - 2);
    }
    constexpr mint pow(int r) const { return power(*this, r); }
    constexpr mint &operator*=(mint rhs) & {
        x = 1LL * x * rhs.x % getMod();
        return *this;
    }
    constexpr mint &operator+=(mint rhs) & {
        x = norm(x + rhs.x);
        return *this;
    }
    constexpr mint &operator-=(mint rhs) & {
        x = norm(x - rhs.x);
        return *this;
    }
    constexpr mint &operator/=(mint rhs) & { return *this *= rhs.inv(); }
    friend constexpr mint operator*(mint lhs, mint rhs) {
        mint res = lhs;
        res *= rhs;
        return res;
    }
    friend constexpr mint operator+(mint lhs, mint rhs) {
        mint res = lhs;
        res += rhs;
        return res;
    }
    friend constexpr mint operator-(mint lhs, mint rhs) {
        mint res = lhs;
        res -= rhs;
        return res;
    }
    friend constexpr mint operator/(mint lhs, mint rhs) {
        mint res = lhs;
        res /= rhs;
        return res;
    }
    friend constexpr std::istream &operator>>(std::istream &is, mint &a) {
        i64 v;
        is >> v;
        a = mint(v);
        return is;
    }
    friend constexpr std::ostream &operator<<(std::ostream &os, const mint &a) {
        return os << a.val();
    }
    friend constexpr bool operator==(mint lhs, mint rhs) {
        return lhs.val() == rhs.val();
    }
    friend constexpr bool operator!=(mint lhs, mint rhs) {
        return lhs.val() != rhs.val();
    }
};

template <int P> int mint<P>::Mod{0};

template <typename Z> struct comb {
    std::vector<Z> fact, inv_fact;
    comb(int n) {
        fact.resize(n + 1, Z(1));
        inv_fact.resize(n + 1, Z(1));
        for (int i = 1; i <= n; i++) {
            fact[i] = fact[i - 1] * i;
        }
        inv_fact[n] = Z{1} / fact[n];
        for (int i = n - 1; i >= 0; i--) {
            inv_fact[i] = inv_fact[i + 1] * (i + 1);
        }
    }
    Z get(int n, int m) {
        if (n < m || m < 0) return 0;
        return fact[n] * inv_fact[m] * inv_fact[n - m];
    }
};
} // namespace modint

using Z = modint::mint<0>;
using C = modint::comb<Z>;

void solve() {
    i64 sign = 1;
    int k, t, p;
    cin >> p >> k >> t;
    if (t % 2 == 0) sign = -1;
    Z::setMod(p);
    Z ans = sign * ((i64)p * (p - 1) / 2 - k) % p;
    ans *= Z{k}.pow(t - 1);
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3428kb

input:

7 5 3

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

11 6 7

output:

3

result:

ok 1 number(s): "3"

Test #3:

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

input:

3 2 1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

596620183 516846890 38276329

output:

135352707

result:

ok 1 number(s): "135352707"

Test #5:

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

input:

382744931 85302262 235496559

output:

14577469

result:

ok 1 number(s): "14577469"

Test #6:

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

input:

659446013 641119314 378275666

output:

290624162

result:

ok 1 number(s): "290624162"

Test #7:

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

input:

227 163 124

output:

189

result:

ok 1 number(s): "189"

Test #8:

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

input:

197 187 19

output:

62

result:

ok 1 number(s): "62"

Test #9:

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

input:

5 3 3

output:

3

result:

ok 1 number(s): "3"

Test #10:

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

input:

7 6 4

output:

1

result:

ok 1 number(s): "1"

Test #11:

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

input:

7 1 1

output:

6

result:

ok 1 number(s): "6"

Test #12:

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

input:

782371 586755 418517

output:

298550

result:

ok 1 number(s): "298550"

Test #13:

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

input:

181081 178315 76002

output:

125177

result:

ok 1 number(s): "125177"

Test #14:

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

input:

715019 492103 446729

output:

221541

result:

ok 1 number(s): "221541"

Test #15:

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

input:

238985261 199832612 162675695

output:

65826267

result:

ok 1 number(s): "65826267"

Test #16:

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

input:

129716453 10994076 62963738

output:

5186275

result:

ok 1 number(s): "5186275"

Test #17:

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

input:

962360593 652577122 345596237

output:

814039152

result:

ok 1 number(s): "814039152"

Test #18:

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

input:

871606937 839183139 754188014

output:

466391387

result:

ok 1 number(s): "466391387"

Test #19:

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

input:

275568091 270750503 241146839

output:

252569968

result:

ok 1 number(s): "252569968"

Test #20:

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

input:

562028473 111749710 450258818

output:

63116256

result:

ok 1 number(s): "63116256"