Submission #31088850
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
std::cout << PREFIX << #x << " = " << x << std::endl; \
}
std::ostream& output_indent(std::ostream& os, int ind) {
for(int i = 0; i < ind; i++) os << " ";
return os;
}
template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);
template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
os << "[";
for(int i = 0;i < v.size();i++) os << v[i] << ", ";
return (os << "]");
}
template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
#include <iostream>
using i64 = long long;
template<i64 M> struct modint { i64 a;
constexpr modint(const i64 x = 0): a((x%M+M)%M){}
constexpr i64 value() const { return a; }
constexpr modint inv() const { return this->pow(M-2); }
constexpr modint pow(i64 r) const {
modint ans(1); modint aa = *this;
while(r) { if(r & 1) ans *= aa; aa *= aa; r >>= 1; }
return ans;
}
constexpr bool operator==(const modint& r) const { return a == r.a; }
constexpr bool operator!=(const modint& r) const { return a != r.a; }
constexpr modint& operator=(const i64 r) { a = (r % M + M) % M; return *this; }
constexpr modint& operator+=(const modint r) { a += r.a; if(a >= M) a -= M; return *this; }
constexpr modint& operator-=(const modint r) { a -= r.a; if(a < 0) a += M; return *this; }
constexpr modint& operator*=(const modint r) { a = a * r.a % M; return *this; }
constexpr modint& operator/=(const modint r) { (*this) *= r.inv(); return *this; }
constexpr modint operator+(const modint r) const { return modint(*this) += r; }
constexpr modint operator-(const modint r) const { return modint(*this) -= r; }
constexpr modint operator-() const { return modint(0) - modint(*this); }
constexpr modint operator*(const modint r) const { return modint(*this) *= r; }
constexpr modint operator/(const modint r) const { return modint(*this) /= r; }
constexpr bool operator!=(const modint r) const { return this->value() != r.value(); }
};
template<const i64 M> std::ostream& operator<<(std::ostream& os, const modint<M>& m) { os << m.value(); return os; }
using fp = modint<998244353>;
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
template <class T>
void divisor_transform(vector<T> &a) {
int n = a.size();
vector<bool> sieve(n, true);
for (int p = 2; p < n; ++p) {
if (sieve[p]) {
for (int k = 1; k * p < n; ++k) {
sieve[k * p] = false;
a[k * p] += a[k];
}
}
}
for (int i = 0; ++i != n;) {
a[i] += a[0];
}
}
template <class T>
void inverse_divisor_transform(vector<T> &a) {
int n = a.size();
vector<bool> sieve(n, true);
for (int i = 0; ++i != n;) {
a[i] -= a[0];
}
for (int p = 2; p < n; ++p) {
if (sieve[p]) {
for (int k = (n - 1) / p; k != 0; --k) {
sieve[k * p] = false;
a[k * p] -= a[k];
}
}
}
}
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
template <class T>
void multiple_transform(vector<T> &a) {
int n = a.size();
vector<bool> sieve(n, true);
for (int p = 2; p < n; ++p) {
if (sieve[p]) {
for (int k = (n - 1) / p; k != 0; --k) {
sieve[k * p] = false;
a[k] += a[k * p];
}
}
}
for (int i = 0; ++i != n;) {
a[i] += a[0];
}
}
template <class T>
void inverse_multiple_transform(vector<T> &a) {
int n = a.size();
vector<bool> sieve(n, true);
for (int i = 0; ++i != n;) {
a[i] -= a[0];
}
for (int p = 2; p < n; ++p) {
if (sieve[p]) {
for (int k = 1; k * p < n; ++k) {
sieve[k * p] = false;
a[k] -= a[k * p];
}
}
}
}
constexpr i64 MAX = 1e6 + 1;
int main() {
i64 N;
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
cin >> N;
vector<i64> A(N);
rep(i,0,N) cin >> A[i];
vector<fp> S(MAX);
rep(i,0,N) {
S[A[i]] += A[i];
}
multiple_transform(S);
rep(g,1,MAX) {
S[g] = S[g] * S[g];
}
inverse_multiple_transform(S);
fp res;
rep(g,1,MAX) {
res += fp(g).inv() * S[g];
}
rep(i,0,N) {
res -= A[i];
}
cout << res / fp(2) << endl;
}
Submission Info
Submission Time |
|
Task |
C - LCMs |
User |
niuez |
Language |
C++ (GCC 9.2.1) |
Score |
700 |
Code Size |
5246 Byte |
Status |
AC |
Exec Time |
173 ms |
Memory |
12880 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:4:28: warning: unnecessary parentheses in declaration of ‘i’ [-Wparentheses]
4 | #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
| ^
./Main.cpp:150:3: note: in expansion of macro ‘rep’
150 | rep(i,0,N) cin >> A[i];
| ^~~
./Main.cpp:4:28: warning: unnecessary parentheses in declaration of ‘i’ [-Wparentheses]
4 | #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
| ^
./Main.cpp:153:3: note: in expansion of macro ‘rep’
153 | rep(i,0,N) {
| ^~~
./Main.cpp:4:28: warning: unnecessary parentheses in declaration of ‘g’ [-Wparentheses]
4 | #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
| ^
./Main.cpp:158:3: note: in expansion of macro ‘rep’
158 | rep(g,1,MAX) {
| ^~~
./Main.cpp:4:28: warning: unnecessary parentheses in declaration of ‘g’ [-Wparentheses]
4 | #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
| ^
./Main.cpp:165:3: note: in expansion of macro ‘rep’
165 | rep(g,1,MAX) {
| ^~~
./Main.cpp:4:28: warning: unnecessary parentheses in declaration of ‘i’ [-Wparentheses]
4 | #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
| ^
./Main.cpp:168:3: note: in expansion of macro ‘rep’
168 | rep(i,0,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 |
158 ms |
11176 KiB |
01-02.txt |
AC |
164 ms |
12100 KiB |
01-03.txt |
AC |
168 ms |
12428 KiB |
01-04.txt |
AC |
156 ms |
11212 KiB |
01-05.txt |
AC |
165 ms |
12360 KiB |
01-06.txt |
AC |
164 ms |
11948 KiB |
01-07.txt |
AC |
158 ms |
11600 KiB |
01-08.txt |
AC |
165 ms |
12284 KiB |
01-09.txt |
AC |
160 ms |
11728 KiB |
01-10.txt |
AC |
170 ms |
12880 KiB |
01-11.txt |
AC |
169 ms |
12820 KiB |
01-12.txt |
AC |
173 ms |
12772 KiB |
01-13.txt |
AC |
169 ms |
12712 KiB |
01-14.txt |
AC |
171 ms |
12836 KiB |
01-15.txt |
AC |
170 ms |
12696 KiB |
01-16.txt |
AC |
169 ms |
12840 KiB |
01-17.txt |
AC |
168 ms |
12876 KiB |
01-18.txt |
AC |
171 ms |
12816 KiB |
sample-01.txt |
AC |
155 ms |
11244 KiB |
sample-02.txt |
AC |
155 ms |
11284 KiB |
sample-03.txt |
AC |
155 ms |
11220 KiB |