QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#108464#3161. Another Coin Weighing Puzzleandrew018gu#AC ✓160ms19156kbC++141.1kb2023-05-25 04:01:382023-05-25 04:01:42

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-25 04:01:42]
  • Judged
  • Verdict: AC
  • Time: 160ms
  • Memory: 19156kb
  • [2023-05-25 04:01:38]
  • Submitted

answer

#include <vector>
#include <iostream>
#define MOD 998244353
#define MAXN 1000000
using namespace std;

int m, k;

long long dp[1000001];

long long mpowers[1000001];

int main(){
    cin >> m >> k;
    long long power2[21];
    dp[0] = 0;
    for(int i = 1; i <= 2 * MAXN + 1; i += 2){
        power2[0] = i;
        for(int j = 1; j < 21; j++){
            power2[j] = (power2[j - 1] * power2[j - 1]) % MOD;
        }
        int t = m;
        long long ans = 1;
        for(int j = 0; j < 21; j++){
            if(t % 2 == 1){
                ans *= power2[j];
                ans %= MOD;
            }
            t/=2;
        }
        mpowers[i/2] = ans;
        if(i > 1){
            dp[i/2] = (MOD + mpowers[i/2] - mpowers[i/2 - 1]) % MOD;
        }
    }
    for(int i = 1; i <= MAXN; i++){
        int j = 2;
        while(i * j <= MAXN){
            dp[i * j] += (MOD - dp[i]);
            dp[i * j] %= MOD;
            j++;
        }
    }
    long long ans = 0;
    for(int i = 1; i <= k; i++){
        ans += dp[i];
        ans %= MOD;
    }
    cout << ans + 1 << endl;
}

详细

Test #1:

score: 100
Accepted
time: 145ms
memory: 18900kb

input:

2 1

output:

9

result:

ok single line: '9'

Test #2:

score: 0
Accepted
time: 136ms
memory: 19040kb

input:

2 2

output:

17

result:

ok single line: '17'

Test #3:

score: 0
Accepted
time: 143ms
memory: 18956kb

input:

10000 10000

output:

689223145

result:

ok single line: '689223145'

Test #4:

score: 0
Accepted
time: 140ms
memory: 18980kb

input:

9999 31

output:

986106162

result:

ok single line: '986106162'

Test #5:

score: 0
Accepted
time: 147ms
memory: 18984kb

input:

57 9817

output:

447253096

result:

ok single line: '447253096'

Test #6:

score: 0
Accepted
time: 135ms
memory: 19100kb

input:

501 499

output:

247755220

result:

ok single line: '247755220'

Test #7:

score: 0
Accepted
time: 160ms
memory: 19156kb

input:

97424 174829

output:

964884269

result:

ok single line: '964884269'

Test #8:

score: 0
Accepted
time: 141ms
memory: 18908kb

input:

11 13

output:

729153057

result:

ok single line: '729153057'

Test #9:

score: 0
Accepted
time: 149ms
memory: 18976kb

input:

200000 200000

output:

803771125

result:

ok single line: '803771125'

Test #10:

score: 0
Accepted
time: 152ms
memory: 18976kb

input:

199999 562

output:

865836540

result:

ok single line: '865836540'

Test #11:

score: 0
Accepted
time: 145ms
memory: 18908kb

input:

3539 189423

output:

530738158

result:

ok single line: '530738158'

Test #12:

score: 0
Accepted
time: 146ms
memory: 18984kb

input:

198324 173852

output:

963717515

result:

ok single line: '963717515'

Test #13:

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

input:

1 1

output:

3

result:

ok single line: '3'

Test #14:

score: 0
Accepted
time: 146ms
memory: 18984kb

input:

1000000 1000000

output:

800590912

result:

ok single line: '800590912'

Test #15:

score: 0
Accepted
time: 137ms
memory: 18924kb

input:

5034 999999

output:

946555033

result:

ok single line: '946555033'

Test #16:

score: 0
Accepted
time: 157ms
memory: 18968kb

input:

999998 2042

output:

713878368

result:

ok single line: '713878368'