QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#106774#3161. Another Coin Weighing Puzzlemarsxiang5902#WA 2ms3484kbC++17647b2023-05-19 06:35:542023-05-19 06:35:58

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-19 06:35:58]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 3484kb
  • [2023-05-19 06:35:54]
  • Submitted

answer

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

using ll = long long;
const int MN = 1e6+5, MOD = 1e9+7;

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]; vector<int> primes;

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 (!pfs[i])
      for (int j = i; j <= M; j += i)
        ++pfs[j];
    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);

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 1

output:

9

result:

ok single line: '9'

Test #2:

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

input:

2 2

output:

17

result:

ok single line: '17'

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 3484kb

input:

10000 10000

output:

589049894

result:

wrong answer 1st lines differ - expected: '689223145', found: '589049894'