QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#250544#7562. Except OneKKT89AC ✓1ms3552kbC++171.8kb2023-11-13 12:21:452023-11-13 12:21:45

Judging History

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

  • [2023-11-13 12:21:45]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3552kb
  • [2023-11-13 12:21:45]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    vector<int> primes = {2, 3, 5, 7, 11};
//    for (int p : primes) {
//        for (int k = 1; k <= p-1; ++k) {
//            for (int t = 1; t <= p-2; ++t) {
//                ll sum = 0;
//                auto dfs = [&](auto dfs, int i, int cn, ll pro) -> void {
//                    if (i == p) {
//                        if (cn == t) {
//                            sum += pro;
//                            sum %= p;
//                        }
//                        return;
//                    }
//                    dfs(dfs, i+1, cn, pro);
//                    if (i != k) dfs(dfs, i+1, cn+1, pro*i%p);
//                };
//                dfs(dfs, 1, 0, 1);
//                cout << p << " " << k << " " << t << " " << sum << endl;
//            }
//        }
//    }
    ll p,k,t; cin >> p >> k >> t;
    ll res = 0;
    if (t == p-1) res = p-1;
    ll x = (res-k)%p;
    if (t == 1) {
        res = x;
    }
    else {
        if (t%2 == 0) res -= modpow(k, t-1, p)*x;
        else res += modpow(k, t-1, p)*x;
    }
    res %= p;
    if (res < 0) res += p;
    cout << res << endl;
}

详细

Test #1:

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

input:

7 5 3

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

11 6 7

output:

3

result:

ok 1 number(s): "3"

Test #3:

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

input:

3 2 1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

596620183 516846890 38276329

output:

135352707

result:

ok 1 number(s): "135352707"

Test #5:

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

input:

382744931 85302262 235496559

output:

14577469

result:

ok 1 number(s): "14577469"

Test #6:

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

input:

659446013 641119314 378275666

output:

290624162

result:

ok 1 number(s): "290624162"

Test #7:

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

input:

227 163 124

output:

189

result:

ok 1 number(s): "189"

Test #8:

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

input:

197 187 19

output:

62

result:

ok 1 number(s): "62"

Test #9:

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

input:

5 3 3

output:

3

result:

ok 1 number(s): "3"

Test #10:

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

input:

7 6 4

output:

1

result:

ok 1 number(s): "1"

Test #11:

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

input:

7 1 1

output:

6

result:

ok 1 number(s): "6"

Test #12:

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

input:

782371 586755 418517

output:

298550

result:

ok 1 number(s): "298550"

Test #13:

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

input:

181081 178315 76002

output:

125177

result:

ok 1 number(s): "125177"

Test #14:

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

input:

715019 492103 446729

output:

221541

result:

ok 1 number(s): "221541"

Test #15:

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

input:

238985261 199832612 162675695

output:

65826267

result:

ok 1 number(s): "65826267"

Test #16:

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

input:

129716453 10994076 62963738

output:

5186275

result:

ok 1 number(s): "5186275"

Test #17:

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

input:

962360593 652577122 345596237

output:

814039152

result:

ok 1 number(s): "814039152"

Test #18:

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

input:

871606937 839183139 754188014

output:

466391387

result:

ok 1 number(s): "466391387"

Test #19:

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

input:

275568091 270750503 241146839

output:

252569968

result:

ok 1 number(s): "252569968"

Test #20:

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

input:

562028473 111749710 450258818

output:

63116256

result:

ok 1 number(s): "63116256"