Submission #35024990
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define TIME 1e3 * clock() / CLOCKS_PER_SEC
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ull = unsigned long long;
inline ll read() {
ll x = 0, sgn = 0;
char s = getchar();
while(!isdigit(s)) sgn |= s == '-', s = getchar();
while(isdigit(s)) x = x * 10 + s - '0', s = getchar();
return sgn ? -x : x;
}
inline void print(int x) {
if(x < 0) return putchar('-'), print(-x);
if(x >= 10) print(x / 10);
putchar(x % 10 + '0');
}
bool Mbe;
constexpr int V = 1e6;
constexpr int mod = 998244353;
void add(int &x, int y) {x += y, x >= mod && (x -= mod);}
bool vis[V + 5];
int n, c[V + 5], f[V + 5], s, ans;
int cnt, pr[V + 5], mu[V + 5];
bool Med;
int main() {
fprintf(stderr, "%.3lf MB\n", (&Mbe - &Med) / 1048576.0);
#ifdef ALEX_WEI
FILE* IN = freopen("1.in", "r", stdin);
FILE* OUT = freopen("1.out", "w", stdout);
#endif
cin >> n;
for(int i = 1, a; i <= n; i++) add(s, a = read()), c[a]++;
mu[1] = 1;
for(int i = 2; i <= V; i++) {
if(!vis[i]) pr[++cnt] = i, mu[i] = -1;
for(int j = 1; j <= cnt && i * pr[j] <= V; j++) {
vis[i * pr[j]] = 1;
if(i % pr[j] == 0) break;
mu[i * pr[j]] = -mu[i];
}
}
for(int i = 1; i <= V; i++) if(mu[i])
for(int j = i; j <= V; j += i)
add(f[j], mu[i] > 0 ? i : mod - i);
for(int T = 1; T <= V; T++) {
int g = 0;
for(int i = 1; i <= V / T; i++) add(g, 1ll * i * c[i * T] % mod);
add(ans, 1ll * T * f[T] % mod * g % mod * g % mod);
}
cout << 1ll * (ans + mod - s) * (mod + 1 >> 1) % mod << "\n";
cerr << TIME << " ms\n";
return 0;
}
/*
2022/9/21
author: Alex_Wei
start coding at 11:24
finish debugging at 12:27
*/
Submission Info
| Submission Time |
|
| Task |
C - LCMs |
| User |
Alex_Wei |
| Language |
C++ (GCC 9.2.1) |
| Score |
700 |
| Code Size |
1755 Byte |
| Status |
AC |
| Exec Time |
108 ms |
| Memory |
16768 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:55:40: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
55 | cout << 1ll * (ans + mod - s) * (mod + 1 >> 1) % mod << "\n";
| ~~~~^~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
700 / 700 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample-01.txt, sample-02.txt, sample-03.txt |
| All |
01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, sample-01.txt, sample-02.txt, sample-03.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 01-01.txt |
AC |
73 ms |
12644 KiB |
| 01-02.txt |
AC |
105 ms |
16720 KiB |
| 01-03.txt |
AC |
107 ms |
16636 KiB |
| 01-04.txt |
AC |
86 ms |
14800 KiB |
| 01-05.txt |
AC |
104 ms |
16744 KiB |
| 01-06.txt |
AC |
103 ms |
16756 KiB |
| 01-07.txt |
AC |
99 ms |
16656 KiB |
| 01-08.txt |
AC |
105 ms |
16648 KiB |
| 01-09.txt |
AC |
105 ms |
16664 KiB |
| 01-10.txt |
AC |
104 ms |
16676 KiB |
| 01-11.txt |
AC |
106 ms |
16660 KiB |
| 01-12.txt |
AC |
108 ms |
16636 KiB |
| 01-13.txt |
AC |
104 ms |
16676 KiB |
| 01-14.txt |
AC |
104 ms |
16748 KiB |
| 01-15.txt |
AC |
107 ms |
16632 KiB |
| 01-16.txt |
AC |
106 ms |
16768 KiB |
| 01-17.txt |
AC |
103 ms |
16664 KiB |
| 01-18.txt |
AC |
75 ms |
12768 KiB |
| sample-01.txt |
AC |
73 ms |
12752 KiB |
| sample-02.txt |
AC |
71 ms |
12748 KiB |
| sample-03.txt |
AC |
73 ms |
12856 KiB |