QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#413762#3161. Another Coin Weighing PuzzlefrizzfrizzAC ✓144ms7768kbC++141.5kb2024-05-18 03:07:442024-05-18 03:07:45

Judging History

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

  • [2024-05-18 03:07:45]
  • 评测
  • 测评结果:AC
  • 用时:144ms
  • 内存:7768kb
  • [2024-05-18 03:07:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

#define A first
#define B second
#define SZ(x) (int)(x.size())

#define FR(i, a, b) for (int i = (a); i < (b); i++)
#define FOR(i, n) FR(i, 0, n)

int M, K, coeffs[1000005];
LL MOD = 998244353;
LL modPow(LL b, LL e)
{
    if (e == 0)
        return 1;
    LL haf = modPow(b, e / 2);
    if (e % 2)
        return (((haf * haf) % MOD) * b) % MOD;
    return (haf * haf) % MOD;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> M >> K;
    FR(i, 2, K + 1)
        coeffs[i] = 1; // coeffs[i] == 1 in first loop at start of iteration iff i is prime
    int fsq = (int)(pow(K, 0.5));
    FR(i, 2, fsq + 1)
    {
        if (coeffs[i] == 1)
        {
            for (int j = i; j <= K; j += i)
                coeffs[j] *= -i;
            for (int j = i * i; j <= K; j += i * i)
                coeffs[j] = 0; // stays 0 forever
        }
    }
    FR(i, 2, K + 1)
    {
        if (coeffs[i] == -i)
            coeffs[i] = 1;
        else if (coeffs[i] == i)
            coeffs[i] = -1;
        else if (coeffs[i] < 0)
            coeffs[i] = -1;
        else if (coeffs[i] > 0)
            coeffs[i] = 1;
    }
    LL ans = 0;
    FR(i, 2, K + 1)
    {
        LL co = (modPow((K / i) * 2 + 1, M) - 1 + MOD) % MOD;
        ans = (ans + co * coeffs[i]) % MOD;
    }
    ans = (modPow(2 * K + 1, M) - ans + MOD) % MOD;
    cout << ans;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 1

output:

9

result:

ok single line: '9'

Test #2:

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

input:

2 2

output:

17

result:

ok single line: '17'

Test #3:

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

input:

10000 10000

output:

689223145

result:

ok single line: '689223145'

Test #4:

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

input:

9999 31

output:

986106162

result:

ok single line: '986106162'

Test #5:

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

input:

57 9817

output:

447253096

result:

ok single line: '447253096'

Test #6:

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

input:

501 499

output:

247755220

result:

ok single line: '247755220'

Test #7:

score: 0
Accepted
time: 19ms
memory: 4564kb

input:

97424 174829

output:

964884269

result:

ok single line: '964884269'

Test #8:

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

input:

11 13

output:

729153057

result:

ok single line: '729153057'

Test #9:

score: 0
Accepted
time: 25ms
memory: 4712kb

input:

200000 200000

output:

803771125

result:

ok single line: '803771125'

Test #10:

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

input:

199999 562

output:

865836540

result:

ok single line: '865836540'

Test #11:

score: 0
Accepted
time: 18ms
memory: 6156kb

input:

3539 189423

output:

530738158

result:

ok single line: '530738158'

Test #12:

score: 0
Accepted
time: 24ms
memory: 5920kb

input:

198324 173852

output:

963717515

result:

ok single line: '963717515'

Test #13:

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

input:

1 1

output:

3

result:

ok single line: '3'

Test #14:

score: 0
Accepted
time: 144ms
memory: 7744kb

input:

1000000 1000000

output:

800590912

result:

ok single line: '800590912'

Test #15:

score: 0
Accepted
time: 97ms
memory: 7768kb

input:

5034 999999

output:

946555033

result:

ok single line: '946555033'

Test #16:

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

input:

999998 2042

output:

713878368

result:

ok single line: '713878368'