QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232527#3161. Another Coin Weighing Puzzle8BQube#AC ✓79ms11368kbC++201.2kb2023-10-30 16:04:402023-10-30 16:04:40

Judging History

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

  • [2023-10-30 16:04:40]
  • 评测
  • 测评结果:AC
  • 用时:79ms
  • 内存:11368kb
  • [2023-10-30 16:04:40]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define pb push_back
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()

const int MAXC = 1000000;
const int MOD = 998244353;

void add(int &x, int val) {
    x += val;
    if (x >= MOD) x -= MOD;
}

int pw(int a, int n) {
    int res = 1;
    for (; n; n >>= 1, a = (ll)a * a % MOD)
        if (n & 1)
            res = (ll)res * a % MOD;
    return res;
}

int mu[MAXC + 1], prime[MAXC + 1];

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    mu[1] = 1;
    for (int i = 2; i <= MAXC; ++i) {
        if (!prime[i]) { 
            prime[i] = i;
            for (int j = i + i; j <= MAXC; j += i)
                prime[j] = i;
        }
        if (i / prime[i] % prime[i] != 0) 
            mu[i] = -mu[i / prime[i]]; 
    }
    int m, k;
    cin >> m >> k;
    int ans = 0;
    for (int d = 1; d <= k; ++d) {
        int num = pw(2 * (k / d) + 1, m);
        add(num, MOD - 1);
        if (mu[d] == 1) add(ans, num);
        else if (mu[d] == -1) add(ans, MOD - num);
    }
    add(ans, 1);
    cout << ans << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 10ms
memory: 11172kb

input:

2 1

output:

9

result:

ok single line: '9'

Test #2:

score: 0
Accepted
time: 11ms
memory: 11200kb

input:

2 2

output:

17

result:

ok single line: '17'

Test #3:

score: 0
Accepted
time: 11ms
memory: 11136kb

input:

10000 10000

output:

689223145

result:

ok single line: '689223145'

Test #4:

score: 0
Accepted
time: 3ms
memory: 11200kb

input:

9999 31

output:

986106162

result:

ok single line: '986106162'

Test #5:

score: 0
Accepted
time: 7ms
memory: 11200kb

input:

57 9817

output:

447253096

result:

ok single line: '447253096'

Test #6:

score: 0
Accepted
time: 7ms
memory: 11312kb

input:

501 499

output:

247755220

result:

ok single line: '247755220'

Test #7:

score: 0
Accepted
time: 21ms
memory: 11200kb

input:

97424 174829

output:

964884269

result:

ok single line: '964884269'

Test #8:

score: 0
Accepted
time: 7ms
memory: 11200kb

input:

11 13

output:

729153057

result:

ok single line: '729153057'

Test #9:

score: 0
Accepted
time: 17ms
memory: 11312kb

input:

200000 200000

output:

803771125

result:

ok single line: '803771125'

Test #10:

score: 0
Accepted
time: 11ms
memory: 11328kb

input:

199999 562

output:

865836540

result:

ok single line: '865836540'

Test #11:

score: 0
Accepted
time: 14ms
memory: 11204kb

input:

3539 189423

output:

530738158

result:

ok single line: '530738158'

Test #12:

score: 0
Accepted
time: 22ms
memory: 11360kb

input:

198324 173852

output:

963717515

result:

ok single line: '963717515'

Test #13:

score: 0
Accepted
time: 11ms
memory: 11368kb

input:

1 1

output:

3

result:

ok single line: '3'

Test #14:

score: 0
Accepted
time: 79ms
memory: 11196kb

input:

1000000 1000000

output:

800590912

result:

ok single line: '800590912'

Test #15:

score: 0
Accepted
time: 43ms
memory: 11200kb

input:

5034 999999

output:

946555033

result:

ok single line: '946555033'

Test #16:

score: 0
Accepted
time: 11ms
memory: 11200kb

input:

999998 2042

output:

713878368

result:

ok single line: '713878368'