QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#106777 | #3161. Another Coin Weighing Puzzle | marsxiang5902# | TL | 2ms | 3492kb | C++17 | 1.1kb | 2023-05-19 06:49:05 | 2023-05-19 06:49:07 |
Judging History
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