QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#820470 | #4499. Find different | SGColin | AC ✓ | 664ms | 4676kb | C++20 | 1.6kb | 2024-12-18 21:33:16 | 2024-12-18 21:33:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
inline int rd() {
int x = 0;
bool f = 0;
char c = getchar();
for (; !isdigit(c); c = getchar()) f |= (c == '-');
for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
return f ? -x : x;
}
#define N 100007
#define mod 998244353
inline int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}
inline int fpow(int x, int t = mod - 2) {
int res = 1;
for (; t; t >>= 1, x = 1ll * x * x % mod)
if (t & 1) res = 1ll * res * x % mod;
return res;
}
bool vis[N];
int phi[N] = {0, 1}, prm[N], ans[N];
inline void work() {
int n = rd(), m = rd();
for (int i = 1; i <= n; ++i) ans[i] = 0;
for (int i = 1; i <= n; ++i)
for (int j = i; j <= n; j += i)
ans[j] = (ans[j] + 1ll * gcd(j / i, m) * fpow(m, i - 1) % mod * phi[j / i]) % mod;
printf("%d", ans[1]);
for (int i = 2; i <= n; ++i) printf(" %lld", 1ll * ans[i] * fpow(i) % mod);
puts("");
}
int main() {
for (int i = 2; i < N; ++i) {
if (!vis[i]) {phi[i] = i - 1; prm[++prm[0]] = i;}
for (int j = 1; j <= prm[0]; ++j) {
if (1ll * i * prm[j] > N) break;
vis[i * prm[j]] = 1;
if (i % prm[j] == 0) {
phi[i * prm[j]] = phi[i] * prm[j];
break;
}
phi[i * prm[j]] = phi[i] * (prm[j] - 1);
}
}
for (int t = rd(); t; --t) work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 664ms
memory: 4676kb
input:
100 100000 100000 100000 10007 100000 99991 99999 65536 100000 39366 100000 1 100000 2 100000 3 100000 4 91 14575 92 79445 92 90081 92 90629 96 47202 95 94325 93 4784 97 2156 92 35902 94 78537 91 30739 90 29211 100 38506 98 86568 100 60016 90 96263 100 1449 95 90310 94 77068 99 8580 95 49218 96 9432...
output:
1 50001 338600275 682529035 345997022 799071125 767573961 525777344 672451750 695859947 80705839 973419437 270876600 831711420 936750132 722158139 215082649 400813551 495979547 702209089 368345940 35630556 251536020 273337876 775086485 990484575 711464282 66329938 116620838 856606896 74334807 781842...
result:
ok 100 lines