Submission #9703431
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()
template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
return std::vector<T>(n, std::forward<T>(val));
}
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
template<i64 M>
struct modint {
i64 a;
constexpr modint(const i64 x = 0) noexcept: a(x) {}
constexpr i64 value() const noexcept { return a; }
constexpr modint pow(i64 r) const noexcept {
modint ans(1);
modint aa = *this;
while(r) {
if(r & 1) {
ans *= aa;
} aa *= aa;
r >>= 1;
}
return ans;
}
constexpr modint& operator+=(const modint r) noexcept {
a += r.a;
if(a >= M) a -= M;
return *this;
}
constexpr modint& operator=(const i64 r) {
a = (r % M + M) % M;
return *this;
}
constexpr modint& operator-=(const modint r) noexcept {
a -= r.a;
if(a < 0) a += M;
return *this;
}
constexpr modint& operator*=(const modint r) noexcept {
a = a * r.a % M;
return *this;
}
constexpr modint& operator/=(modint r) noexcept {
i64 ex = M - 2;
while(ex) {
if(ex & 1) {
*this *= r;
}
r *= r;
ex >>= 1;
}
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 modint r) const {
return modint(*this) *= r;
}
constexpr modint operator/(const modint r) const {
return modint(*this) /= r;
}
};
template<const i64 M>
std::ostream& operator<<(std::ostream& os, const modint<M>& m) {
os << m.value();
return os;
}
const i64 MOD = 998244353;
using fp = modint<MOD>;
i64 gcd(i64 a, i64 b) {
while(b != 0) {
a %= b;
swap(a, b);
}
return a;
}
#include <cstdio>
namespace niu {
char cur;
struct FIN {
static inline bool is_blank(char c) { return c <= ' '; }
inline char next() { return cur = getc_unlocked(stdin); }
inline char peek() { return cur; }
inline void skip() { while(is_blank(next())){} }
#define intin(inttype) \
FIN& operator>>(inttype& n) { \
bool sign = 0; \
n = 0; \
skip(); \
while(!is_blank(peek())) { \
if(peek() == '-') sign = 1; \
else n = (n << 1) + (n << 3) + (peek() & 0b1111); \
next(); \
} \
if(sign) n = -n; \
return *this; \
}
intin(int)
intin(long long)
} fin;
char tmp[128];
struct FOUT {
static inline bool is_blank(char c) { return c <= ' '; }
inline void push(char c) { putc_unlocked(c, stdout); }
FOUT& operator<<(char c) { push(c); return *this; }
FOUT& operator<<(const char* s) { while(*s) push(*s++); return *this; }
#define intout(inttype) \
FOUT& operator<<(inttype n) { \
if(n) { \
char* p = tmp + 127; bool neg = 0; \
if(n < 0) neg = 1, n = -n; \
while(n) *--p = (n % 10) | 0b00110000, n /= 10; \
if(neg) *--p = '-'; \
return (*this) << p; \
} \
else { \
push('0'); \
return *this; \
} \
}
intout(int)
intout(long long)
} fout;
}
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
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];
}
}
}
}
constexpr i64 A = 1e6 + 1;
int main() {
std::vector<fp> f(A);
rep(d,1,A) {
f[d] = fp(d).pow(MOD - 2);
}
inverse_divisor_transform(f);
i64 N;
niu::fin >> N;
vector<fp> sum(A);
fp ans = 0;
rep(i,0,N) {
int x;
niu::fin >> x;
fp res = 0;
for(int d = 1; d * d <= x; d++) {
if(x % d == 0) {
res += f[d] * sum[d];
sum[d] += fp(x);
if(x / d != d) {
res += f[x / d] * sum[x / d];
sum[x / d] += fp(x);
}
}
}
ans += res * fp(x);
}
niu::fout << ans.value() << "\n";
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - LCMs |
| User | niuez |
| Language | C++14 (GCC 5.4.1) |
| Score | 700 |
| Code Size | 4761 Byte |
| Status | AC |
| Exec Time | 946 ms |
| Memory | 16128 KiB |
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 | 178 ms | 16000 KiB |
| 01-02.txt | AC | 467 ms | 16000 KiB |
| 01-03.txt | AC | 650 ms | 16000 KiB |
| 01-04.txt | AC | 179 ms | 16128 KiB |
| 01-05.txt | AC | 588 ms | 16000 KiB |
| 01-06.txt | AC | 411 ms | 16000 KiB |
| 01-07.txt | AC | 321 ms | 16000 KiB |
| 01-08.txt | AC | 529 ms | 16000 KiB |
| 01-09.txt | AC | 359 ms | 16000 KiB |
| 01-10.txt | AC | 688 ms | 16000 KiB |
| 01-11.txt | AC | 748 ms | 16000 KiB |
| 01-12.txt | AC | 689 ms | 16000 KiB |
| 01-13.txt | AC | 748 ms | 16000 KiB |
| 01-14.txt | AC | 688 ms | 16000 KiB |
| 01-15.txt | AC | 757 ms | 16000 KiB |
| 01-16.txt | AC | 688 ms | 16000 KiB |
| 01-17.txt | AC | 750 ms | 16000 KiB |
| 01-18.txt | AC | 946 ms | 16000 KiB |
| sample-01.txt | AC | 178 ms | 16128 KiB |
| sample-02.txt | AC | 178 ms | 16000 KiB |
| sample-03.txt | AC | 178 ms | 16000 KiB |