QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#74178#3161. Another Coin Weighing PuzzleUCSC_RavioliAC ✓85ms10020kbC++201.4kb2023-01-31 02:03:482023-01-31 02:03:49

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-31 02:03:49]
  • 评测
  • 测评结果:AC
  • 用时:85ms
  • 内存:10020kb
  • [2023-01-31 02:03:48]
  • 提交

answer

// qdd on Jan 30, 2023

#ifdef qdd
#include <ringo>
#else
#include <bits/stdc++.h>
#define dbg(...)
#define dbgr(x, y)
#endif

using namespace std;

using ll = long long;

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v) is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  bool f = 0;
  for (const T& x : v) (f ? os << ' ' : os) << x, f = 1;
  return os;
}

const int N = 1e6 + 7;

bool vis[N];
int mu[N], prime[N];

const ll P = 998244353;

constexpr ll qk(ll a, ll b, ll p) {
  ll ans = 1 % p;
  for (a %= p; b; b >>= 1, a = a * a % p)
    if (b & 1) ans = ans * a % p;
  return ans;
}

void get_mu() {
  int tot = 0;
  mu[1] = 1;
  for (int i = 2; i < N; i++) {
    if (!vis[i]) {
      prime[tot++] = i;
      mu[i] = -1;
    }
    for (int j = 0; j < tot; j++) {
      int d = i * prime[j];
      if (d >= N) break;
      vis[d] = true;
      if (i % prime[j] == 0) {
        mu[d] = 0;
        break;
      } else
        mu[d] = -mu[i];
    }
  }
}

void sol() {
  int n, k;
  cin >> n >> k;
  ll ans = 1;
  for (int i = 1; i <= k; i++) {
    ans += mu[i] * (qk(1 + 2 * (k / i), n, P) - 1);
    ans = (ans % P + P) % P;
  }
  cout << ans << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  get_mu();
  sol();
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 9884kb

input:

2 1

output:

9

result:

ok single line: '9'

Test #2:

score: 0
Accepted
time: 5ms
memory: 10020kb

input:

2 2

output:

17

result:

ok single line: '17'

Test #3:

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

input:

10000 10000

output:

689223145

result:

ok single line: '689223145'

Test #4:

score: 0
Accepted
time: 5ms
memory: 9376kb

input:

9999 31

output:

986106162

result:

ok single line: '986106162'

Test #5:

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

input:

57 9817

output:

447253096

result:

ok single line: '447253096'

Test #6:

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

input:

501 499

output:

247755220

result:

ok single line: '247755220'

Test #7:

score: 0
Accepted
time: 16ms
memory: 8624kb

input:

97424 174829

output:

964884269

result:

ok single line: '964884269'

Test #8:

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

input:

11 13

output:

729153057

result:

ok single line: '729153057'

Test #9:

score: 0
Accepted
time: 16ms
memory: 8536kb

input:

200000 200000

output:

803771125

result:

ok single line: '803771125'

Test #10:

score: 0
Accepted
time: 4ms
memory: 8536kb

input:

199999 562

output:

865836540

result:

ok single line: '865836540'

Test #11:

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

input:

3539 189423

output:

530738158

result:

ok single line: '530738158'

Test #12:

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

input:

198324 173852

output:

963717515

result:

ok single line: '963717515'

Test #13:

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

input:

1 1

output:

3

result:

ok single line: '3'

Test #14:

score: 0
Accepted
time: 85ms
memory: 8536kb

input:

1000000 1000000

output:

800590912

result:

ok single line: '800590912'

Test #15:

score: 0
Accepted
time: 60ms
memory: 8480kb

input:

5034 999999

output:

946555033

result:

ok single line: '946555033'

Test #16:

score: 0
Accepted
time: 9ms
memory: 8552kb

input:

999998 2042

output:

713878368

result:

ok single line: '713878368'