#pragma GCC optimize("Ofast") #include using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using i128 = __int128_t; using P = pair; using LP = pair; using LT = tuple; using LT4 = tuple; typedef vector vi; typedef vector vvi; typedef vector vl; typedef vector vvl; typedef vector v3l; typedef vector v4l; typedef vector v5l; typedef vector vlp; typedef vector vvlp; typedef vector vlt; typedef vector vvlt; typedef vector vlt4; typedef vector vs; typedef vector vvs; typedef vector vd; typedef vector vvd; typedef vector vb; typedef vector vvb; template using pq = priority_queue; template using mpq = priority_queue, greater>; template class infinity{ public: static constexpr T MAX=numeric_limits::max(); static constexpr T MIN=numeric_limits::min(); static constexpr T val=numeric_limits::max()/2-1e6; static constexpr T mval=numeric_limits::min()/2+1e6; }; const int INF = infinity::val; const ll LINF = infinity::val; const ld DINF = infinity::val; #define _overload5(a, b, c, d, e, name, ...) name #define _overload4(a, b, c, d, name, ...) name #define _overload3(a, b, c, name, ...) name #define _rep0(n) for(ll i = 0; (ll)(i) < n; ++i) #define _rep1(i, n) for(ll i = 0; i < (ll)(n); ++i) #define _rep2(i, a, b) for(ll i = (ll)(a); i < (ll)(b); ++i) #define _rep3(i, a, b, c) for(ll i = (ll)(a); i < (ll)(b); i += (ll)(c)) #define rep(...) _overload4(__VA_ARGS__, _rep3, _rep2, _rep1, _rep0)(__VA_ARGS__) #define _per0(n) for(ll i = 0; i < (ll)(n); ++i) #define _per1(i, n) for(ll i = (ll)(n)-1; i >= 0; --i) #define _per2(i, a, b) for(ll i = (ll)(a)-1; i >= (ll)(b); --i) #define _per3(i, a, b, c) for(ll i = (ll)(a)-1; i >= (ll)(b); i -= (ll)(c)) #define rep_r(...) _overload4(__VA_ARGS__, _per3, _per2, _per1, _per0)(__VA_ARGS__) #define _fore0(a) rep(a.size()) #define _fore1(i, a) for(auto &&i : a) #define _fore2(a, b, v) for(auto &&[a, b] : v) #define _fore3(a, b, c, v) for(auto &&[a, b, c] : v) #define _fore4(a, b, c, d, v) for(auto &&[a, b, c, d] : v) #define fore(...) _overload5(__VA_ARGS__, _fore4, _fore3, _fore2, _fore1, _fore0)(__VA_ARGS__) #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define rng(v, l, r) (v).begin() + l, (v).begin() + r #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define vv(type, name, h, ...) vector> name(h, vector(__VA_ARGS__)) #define v3(type, name, h, w, ...) vector>> name(h, vector>(w, vector(__VA_ARGS__))) #define v4(type, name, a, b, c, ...) vector>>> name(a, vector>>(b, vector>(c, vector(__VA_ARGS__)))) struct RandGen { using ud = uniform_int_distribution; mt19937 mt; RandGen() : mt(chrono::steady_clock::now().time_since_epoch().count()) {} ll l(ll a, ll b) { ud d(a, b - 1); return d(mt); } LP lp(ll a, ll b, bool rng = true) { ll x = l(a, b - 1), y = l(rng ? x + 1 : a, b - 1); return {x, y}; } vl vecl(ll n, ll a, ll b) { ud d(a, b - 1); vl ret(n); rep(i, n) ret[i] = d(mt); return ret; } vl vecperm(ll n, ll from = 0) { vl perm(n); iota(all(perm), from); shuffle(perm); return perm; } string str(ll n, string op) { vl fig = vecl(n, 0, op.size()); string s; rep(i, n) s.pb(op[fig[i]]); return s; } string straz(ll n, ll a = 0, ll z = 26) { vl az = vecl(n, a, z); string s; rep(i, n) s.pb('a' + az[i]); return s; } string strnum(ll n, ll zero = 0, ll ten = 10) { vl zt = vecl(n, zero, ten); string s; rep(i, n) s.pb('0' + zt[i]); return s; } template void shuffle(vector &a) { std::shuffle(all(a), mt); } }; // デバッグ系 #define dout cout template struct is_specialize:false_type{}; template struct is_specialize::type>:true_type{}; template struct is_specialize::type>:true_type{}; template struct is_specialize::value, void>>:true_type{}; void dump(const char &t) { dout<::value, nullptr_t> =nullptr> void dump(const T&t) { dout << t; } template void dump(const T&t, enable_if_t::value>* =nullptr) { string tmp;if(t==infinity::val||t==infinity::MAX)tmp="inf";if(is_signed::value&&(t==infinity::mval||t==infinity::MIN))tmp="-inf";if(tmp.empty())tmp=to_string(t);dout< void dump(const tuple&t) { dout<<"("; dump(get<0>(t)); dout<<" "; dump(get<1>(t)); dout << " "; dump(get<2>(t)); dout << ")"; } template void dump(const pair&); template void dump(const T&t, enable_if_t::value>* =nullptr) { dout << "{ "; for(auto it=t.begin();it!=t.end();){ dump(*it); dout << (++it==t.end() ? "" : " "); } dout<<" }"; } template void dump(const pair&t) { dout<<"("; dump(t.first); dout<<" "; dump(t.second); dout << ")"; } void trace() { dout << "\n"; } template void trace(Head&&head, Tail&&... tail) { dump(head); if(sizeof...(tail)) dout<<", "; trace(forward(tail)...); } #ifdef ONLINE_JUDGE #define debug(...) (void(0)) #else #define debug(...) do {dout<<#__VA_ARGS__<<" = ";trace(__VA_ARGS__); } while(0) #endif // 入出力系 #define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__) #define STR(...) string __VA_ARGS__; IN(__VA_ARGS__) #define LD(...) ld __VA_ARGS__; IN(__VA_ARGS__) #define _vl(name, size) vl name(size); IN(name) #define _vl2(name, size, off) vl name(size); IN(name); rep(i, size) name[i]-=off #define VL(...) _overload3(__VA_ARGS__, _vl2, _vl)(__VA_ARGS__) #define VEC(type, name, size) vector name(size); IN(name) #define VEC2(type, name1, name2, size) vector name1(size), name2(size); for(int i = 0; i < size; i++) IN(name1[i], name2[i]) #define VEC3(type, name1, name2, name3, size) vector name1(size), name2(size), name3(size); for(int i = 0; i < size; i++) IN(name1[i], name2[i], name3[i]) #define VEC4(type, name1, name2, name3, name4, size) vector name1(size), name2(size), name3(size), name4(size); for(int i = 0; i < size; i++) IN(name1[i], name2[i], name3[i], name4[i]); #define VV(type, name, h, w) vector> name(h, vector(w)); IN(name) void scan(int &a) { cin >> a; } void scan(long long &a) { cin >> a; } void scan(char &a) { cin >> a; } void scan(double &a) { cin >> a; } void scan(string &a) { cin >> a; } template void scan(pair &p) { scan(p.first), scan(p.second); } template void scan(vector &a) { for(auto &i : a) scan(i); } template void scan(T &a) { cin >> a; } void IN() {} template void IN(Head &head, Tail &...tail) { scan(head); IN(tail...); } #define OUTRET(...) { { OUT(__VA_ARGS__); return; } } template ostream &operator<<(ostream &os, const pair &p) { return os << p.first << " " << p.second; } void OUT() { cout << '\n'; } template void OUT(const Head &head, const Tail &...tail) { cout << head; if(sizeof...(tail)) cout << ' '; OUT(tail...); } template void OUTARRAY(vector& v, int offset = 0, string sep = " ") { rep(i, v.size()) { if (i > 0) cout << sep; if (offset) cout << v[i] + offset; else cout << v[i]; } cout << "\n"; } template void OUTMAT(vector>& v, int offset = 0) { rep(i, v.size()) { coutarray(v[i], offset); } } template void OUTBIN(T &a, int d) { for (int i = d - 1; i >= 0; i--) cout << ((a >> i) & (T)1); cout << "\n"; } template void IQUERY(initializer_list q, A &a, string str = "? ") { cout << str; vector v(q); coutarray(v); cout.flush(); cin >> a; } // template void IQUERY(initializer_list q, A &a, string str = "? ") { vector query(q); RandGen rg; // a = query[0] ? A() : A(); // } template void IANSWER(A a, string str = "! ") { cout << str << a << "\n"; cout.flush(); } // 数値系 int ceil_pow2(ll n) { int x = 0; while ((1ULL << x) < (ull)(n)) x++; return x; } int floor_pow2(ll n) { int x = 0; while ((1ULL << (x + 1)) <= (ull)(n)) x++; return x; } ll POW(__uint128_t x, int n) { assert(n >= 0); ll res = 1; for(; n; n >>= 1, x *= x) if(n & 1) res *= x; return res; } ll sqrt_ceil(ll x) { ll l = -1, r = x; while (r - l > 1) { ll m = (l + r) / 2; if (m * m >= x) r = m; else l = m; } return r; } vl divisor(ll n) { vl ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.pb(i); if (i * i != n) ret.pb(n / i); } } sort(all(ret)); return ret; } template vl digits(T n) { assert(n >= 0); vl ret; while(n > 0) { ret.pb(n % 10); n /= 10; } return ret; } template T ceil(T x, S y) { assert(y); return (y < 0 ? ceil(-x, -y) : (x > 0 ? (x + y - 1) / y : x / y)); } template T floor(T x, S y) { assert(y); return (y < 0 ? floor(-x, -y) : (x > 0 ? x / y : (x - y + 1) / y)); } template T sum_of(const vector &v, int l = 0, int r = INF) { return accumulate(rng(v, l, min(r, (int)v.size())), T(0)); } ll max(int x, ll y) { return max((ll)x, y); } ll max(ll x, int y) { return max(x, (ll)y); } ll min(int x, ll y) { return min((ll)x, y); } ll min(ll x, int y) { return min(x, (ll)y); } ll mex(vl& v) { ll n = v.size(); vb S(n + 1); for (auto a: v) if (a <= n) S[a] = 1; ll ret = 0; while (S[ret]) ret++; return ret; } // 操作系 template void uniq(vector&a) { sort(all(a)); a.erase(unique(all(a)), a.end()); } template void comp(vector&a) { vector b = a; uniq(b); rep(i, a.size()) a[i] = lower_bound(all(b), a[i]) - b.begin(); } template bool chmin(T &a, const U &b) { if (b < a) { a = b; return 1;} return 0; } template bool chmax(T &a, const U &b) { if (b > a) { a = b; return 1;} return 0; } template int lbs(vector &a, const T &b) { return lower_bound(all(a), b) - a.begin(); }; template int ubs(vector &a, const T &b) { return upper_bound(all(a), b) - a.begin(); }; ll binary_search(function check, ll ok, ll ng) { assert(check(ok)); while (abs(ok - ng) > 1) { auto x = (ng + ok) / 2; if (check(x)) ok = x; else ng = x; } return ok; } template vector csum(vector &a) { vl ret(a.size() + 1, 0); rep(i, a.size()) ret[i + 1] = ret[i] + a[i]; return ret; } template vector> RLE(const vector &v) { vector> res; for(auto &e : v) if(res.empty() or res.back().first != e) res.emplace_back(e, 1); else res.back().second++; return res; } vector> RLE(const string &v) { vector> res; for(auto &e : v) if(res.empty() or res.back().first != e) res.emplace_back(e, 1); else res.back().second++; return res; } template bool incl(const T &x, const S &l, const S &r) { return l <= x and x < r; } bool is_palindrome(string s) { rep(i, (s.size() + 1) / 2) if (s[i] != s[s.size() - 1 - i]) { return false; } return true; } const string drul = "DRUL"; vl dx = {1, 0, -1, 0}; vl dy = {0, 1, 0, -1}; ll solve(ll n, vl a) { ll ans = n - a[0]; return ans; } ll naive(ll n, vl a) { ll ans = n + a[0]; return ans; } void compare(bool check = true) { RandGen rg; ll c = 0, loop = 10; while (++c) { if (c % loop == 0) cout << "reached " << c / loop << "loop" << "\n", cout.flush(); ll n = 10; vl a = rg.vecl(n, 1, 1e2); auto so = solve(n, a); auto na = naive(n, a); if (!check || na != so) { cout << c << "times tried" << "\n"; debug(n, a); debug(so); debug(na); if (check || (!check && c > loop)) break; } } } vector primes_below(const ll N) { vector is_prime(N + 1, true); for(ll i = 2; i * i <= N; i++) { if ((i > 2 && i % 2 == 0) || !is_prime[i]) continue; for(ll j = i * i; j <= N; j += i) is_prime[j] = false; } vector ret; for(ll i = 2; i <= N; i++) if (is_prime[i]) ret.emplace_back(i); return ret; } const ll mod = 998244353; //------------------------------------------------------------------------------ template< int mod > struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int) (1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inv(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inv() const { int a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); } static int get_mod() { return mod; } }; using mint = ModInt< mod >; using vmi = vector; using vvmi = vector; using v3mi = vector; using v4mi = vector; //------------------------------------------------------------------------------ const int max_n = 1 << 20; mint fact[max_n], factinv[max_n]; void init_f() { fact[0] = 1; for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * (i + 1); } factinv[max_n - 1] = mint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * (i + 1); } } mint comb(int a, int b) { assert(fact[0] != 0); if (a < 0 || b < 0 || a < b) return 0; return fact[a] * factinv[b] * factinv[a - b]; } mint combP(int a, int b) { assert(fact[0] != 0); if (a < 0 || b < 0 || a < b) return 0; return fact[a] * factinv[a - b]; } //------------------------------------------------------------------------------ ll mod_pow(ll x, ll n, const ll &p = mod) { ll ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; } ll mod_inv(ll x, ll m) { ll a = x, b = m, u = 1, v = 0, t; while(b) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } if (u < 0) u += m; return u % m; } //------------------------------------------------------------------------------ //------------------------------------------------------- // https://atcoder.jp/contests/abc238/submissions/29086825 // https://cp-algorithms.com/algebra/prime-sieve-linear.html struct PrimeSieve { int n; vector is_prime; vector pr, mu, pf; // pr := primes, mu := moebius, pf[i] := smallest prime p s.t. p | i PrimeSieve(int _n){ n = ++_n; is_prime.assign(n, true); mu.assign(n, 0); pf.assign(n, 0); is_prime[0] = is_prime[1] = false; mu[1] = 1; for (int i = 2; i < n; i++) { if (is_prime[i]) { pr.emplace_back(i); pf[i] = i; mu[i] = -1; } for (int p : pr) { if (ll(i) * p >= n) break; is_prime[i * p] = false; mu[i * p] = -mu[i]; pf[i * p] = p; if (i % p == 0) { mu[i * p] = 0; break; } } } } vector> factorize(int x) { assert(x < n); vector> res; while (pf[x] > 1) { int d = pf[x], c = 0; while (x % d == 0) { x /= d; c++; } res.emplace_back(d, c); } if (x != 1) res.emplace_back(x, 1); return res; } // not sorted [1..x] vector divisors(int x) { assert(x < n); auto f = factorize(x); vector res = { 1 }; for (auto [p, c] : f) { vector powp; powp.emplace_back(p); rep(i, c - 1) powp.emplace_back(powp.back() * p); for (int i = res.size() - 1; i >= 0; --i) for (int j = 0; j < c; ++j) res.emplace_back(res[i] * powp[j]); } // res.erase(res.begin()); [2..x] return res; } }; void solve() { LL(n); VL(a, n); ll MA = *max_element(all(a)); PrimeSieve ps(MA); vmi dp(MA + 1, 0); mint ans = 0; rep(i, n) { auto f = ps.factorize(a[i]); ll sz = f.size(); mint cnt = 1; vlp combi; rep(S, 1 << sz) { ll div = 1; rep(j, sz) if (S & 1 << j) div *= f[j].fi; combi.pb({div, __builtin_popcount(S)}); if (S == 0) continue; cnt += dp[div]; } fore(d, c, combi) { if (c == 0) continue; dp[d] += (c & 1 ? cnt : -cnt); } // debug(dp); ans += cnt; } OUT(ans); } signed main() { cin.tie(0)->sync_with_stdio(0); cout.tie(0); cout << fixed << setprecision(20); int t = 1; // cin >> t; while (t--) solve(); // while (t--) compare(); }