QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#106779#3161. Another Coin Weighing Puzzlemarsxiang5902#AC ✓54ms8344kbC++171.1kb2023-05-19 06:52:072023-05-19 06:52:08

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-19 06:52:08]
  • 评测
  • 测评结果:AC
  • 用时:54ms
  • 内存:8344kb
  • [2023-05-19 06:52:07]
  • 提交

answer

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

using ll = long long;
const int MN = 1e6+5, MOD = 119<<23|1;

ll fpow(ll b, int e=MOD-2) {
  ll ret = 1;
  for (; e; e>>=1) {
    if (e&1) ret = ret*b %MOD;
    b = b*b %MOD;
  } return ret;
}

int N, M, pfs[MN]; bool hasSq[MN];

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);

  cin >> N >> M;
  ll ans = 0;
  for (int i = 2; i <= M; i++) {
    if (hasSq[i]) continue;
    if (!pfs[i]) {
      for (int j = i; j <= M; j += i)
        ++pfs[j];
      for (ll j = ll(i)*i; j <= M; j += ll(i)*i)
        hasSq[j] = 1;
    }
    ans += (pfs[i]&1 ? 1 : -1) * (fpow((M/i)*2+1, N) - 1);
  }
  ans = fpow(M*2+1, N) - ans;
  printf("%lld\n", (ans%MOD+MOD)%MOD);

  /*int ans0 = 0, ar[N]; fill(ar, ar+N, -M);
  while (1) {
    int g = 0;
    for (int i = 0; i < N; i++)
      g = __gcd(g, abs(ar[i]));
    ans0 += g == 1 || g == 0;
    if (accumulate(ar, ar+N, 0) == N*M) break;
    for (int i = 0; i < N; i++)
      if (ar[i] == M) ar[i] = -M;
      else { ++ar[i]; break; }
  }
  printf("%d\n", ans0);*/

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3480kb

input:

2 1

output:

9

result:

ok single line: '9'

Test #2:

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

input:

2 2

output:

17

result:

ok single line: '17'

Test #3:

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

input:

10000 10000

output:

689223145

result:

ok single line: '689223145'

Test #4:

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

input:

9999 31

output:

986106162

result:

ok single line: '986106162'

Test #5:

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

input:

57 9817

output:

447253096

result:

ok single line: '447253096'

Test #6:

score: 0
Accepted
time: 2ms
memory: 3456kb

input:

501 499

output:

247755220

result:

ok single line: '247755220'

Test #7:

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

input:

97424 174829

output:

964884269

result:

ok single line: '964884269'

Test #8:

score: 0
Accepted
time: 2ms
memory: 3472kb

input:

11 13

output:

729153057

result:

ok single line: '729153057'

Test #9:

score: 0
Accepted
time: 8ms
memory: 4532kb

input:

200000 200000

output:

803771125

result:

ok single line: '803771125'

Test #10:

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

input:

199999 562

output:

865836540

result:

ok single line: '865836540'

Test #11:

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

input:

3539 189423

output:

530738158

result:

ok single line: '530738158'

Test #12:

score: 0
Accepted
time: 12ms
memory: 4464kb

input:

198324 173852

output:

963717515

result:

ok single line: '963717515'

Test #13:

score: 0
Accepted
time: 2ms
memory: 3732kb

input:

1 1

output:

3

result:

ok single line: '3'

Test #14:

score: 0
Accepted
time: 54ms
memory: 8344kb

input:

1000000 1000000

output:

800590912

result:

ok single line: '800590912'

Test #15:

score: 0
Accepted
time: 34ms
memory: 8316kb

input:

5034 999999

output:

946555033

result:

ok single line: '946555033'

Test #16:

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

input:

999998 2042

output:

713878368

result:

ok single line: '713878368'