QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#106777#3161. Another Coin Weighing Puzzlemarsxiang5902#TL 2ms3492kbC++171.1kb2023-05-19 06:49:052023-05-19 06:49:07

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:49:07]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:3492kb
  • [2023-05-19 06:49:05]
  • 提交

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]; 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;
}

详细

Test #1:

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

input:

2 1

output:

9

result:

ok single line: '9'

Test #2:

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

input:

2 2

output:

17

result:

ok single line: '17'

Test #3:

score: -100
Time Limit Exceeded

input:

10000 10000

output:


result: