import os,sys,random,threading #sys.exit() 退出程序 #sys.setrecursionlimit(10**6) #调整栈空间 from random import randint,choice,shuffle #randint(a,b)从[a,b]范围随机选择一个数 #choice(seq)seq可以是一个列表,元组或字符串,从seq中随机选取一个元素 #shuffle(x)将一个可变的序列x中的元素打乱 from copy import deepcopy from io import BytesIO,IOBase from types import GeneratorType from functools import lru_cache,reduce #reduce(op,迭代对象) from bisect import bisect_left,bisect_right #bisect_left(x) 大于等于x的第一个下标 #bisect_right(x) 大于x的第一个下标 from collections import Counter,defaultdict,deque from itertools import accumulate,combinations,permutations #accumulate(a)用a序列生成一个累积迭代器,一般list化前面放个[0]做前缀和用 #combinations(a,k)a序列选k个 组合迭代器 #permutations(a,k)a序列选k个 排列迭代器 from heapq import heapify,heappop,heappush #heapify将列表转为堆 from typing import Generic,Iterable,Iterator,TypeVar,Union,List from string import ascii_lowercase,ascii_uppercase,digits #小写字母,大写字母,十进制数字 from math import ceil,floor,sqrt,pi,factorial,gcd,log,log10,log2,inf #ceil向上取整,floor向下取整 ,sqrt开方 ,factorial阶乘 from decimal import Decimal,getcontext #Decimal(s) 实例化Decimal对象,一般使用字符串 #getcontext().prec=100 修改精度 from sys import stdin, stdout, setrecursionlimit input = lambda: sys.stdin.readline().rstrip("\r\n") MI = lambda :map(int,input().split()) li = lambda :list(MI()) ii = lambda :int(input()) mod = int(1e9 + 7) #998244353 inf = 1<<60 py = lambda :print("YES") pn = lambda :print("NO") DIRS = [(0, 1), (1, 0), (0, -1), (-1, 0)] # 右下左上 DIRS8 = [(0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0),(-1, 1)] # →↘↓↙←↖↑↗ class PrimeTable: def __init__(self, n=int((10**9)**0.5)+3) -> None: #值域1e9的话考虑质因子,只需小于等于(10**9)**0.5的质数即可 #任意一个正整数n最多只有一个质因子大于根号n self.n = n self.primes = [] #小于等于n的所有质数 self.min_div = [0] * (n+1) self.min_div[1] = 1 mu = [0] * (n+1) phi = [0] * (n+1) mu[1] = 1 phi[1] = 1 for i in range(2, n+1): if not self.min_div[i]: self.primes.append(i) self.min_div[i] = i mu[i] = -1 phi[i] = i-1 for p in self.primes: if i * p > n: break self.min_div[i*p] = p if i % p == 0: phi[i*p] = phi[i] * p break else: mu[i*p] = -mu[i] phi[i*p] = phi[i] * (p - 1) # x是否质数 def is_prime(self, x:int): if x < 2: return False if x <= self.n: return self.min_div[x] == x for p in self.primes: if p * p > x: break if x % p == 0: return False return True # x分解质因数:[p, cnt] 质因子p,个数cnt # 用的yield,当作一个可遍历的数据对象 #一个数一定可以分解为多个质数的连乘积 #n = x^a * y^b * z^c ... (x,y,z为质因数) n的约数个数=(a+1)(b+1)...(y+1) def prime_factorization(self, x:int): for p in self.primes: if p * p > x: break if x <= self.n: break if x % p == 0: cnt = 0 while x % p == 0: cnt += 1; x //= p yield p, cnt while (1 < x and x <= self.n): p, cnt = self.min_div[x], 0 while x % p == 0: cnt += 1; x //= p yield p, cnt if x >= self.n and x > 1: #小于等于(10**9)**0.5的质数除干净了,如果还大于1 # 那么余下的数一定是一个大于等于n的质数 yield x, 1 # x的所有因数 def get_factors(self, x:int): factors = [1] for p, b in self.prime_factorization(x): n = len(factors) for j in range(1, b+1): for d in factors[:n]: factors.append(d * (p ** j)) return factors def getMu(n): mu = [0] * (n + 1) flg = [0] * (n + 1) p = [0] * (n + 1) tot = 0 mu[1] = 1 for i in range(2, n + 1): if flg[i] == 0: tot = tot + 1; p[tot] = i; mu[i] = -1 j = 1 while j <= tot and i * p[j] <= n: flg[i * p[j]] = 1 if i % p[j] == 0: mu[i * p[j]] = 0 break mu[i * p[j]] = - mu[i] j = j + 1 return mu # f[n]表示恰好使用n个有标号的元素形成特定结构的方案数 # g[n]从n个中选出i个选出特定结构的总方案数 # 情况1:g[n]表示至多为n个 # g[n]=ΣC(n,i) * f[i] i∈[0,n] # 反演 # f[n]=Σ(-1)^(n-i) * C(n,i) * g[i] i∈[0,n] # 情况2:g[k]表示至少为k个 # g[k]=ΣC(i,k) * f[i] i∈[k,n] # 反演 # f[k]=Σ(-1)^(i-k) * C(i,k) * g[i] i∈[k,n] mod=998244353 pt=PrimeTable(10**6+1) mb=getMu(10**6+1) n=ii() arr=li() ans=0 cnt=[0]*(10**6+1) tot=0 for a in arr: val=[1] for p,_ in pt.prime_factorization(a): for i in range(len(val)): val.append(val[i]*p) dp=0 for v in val: dp+=cnt[v]*mb[v] dp%=mod #print(cnt[:10],val,mb[:10]) #print(a,dp,tot) dp=(tot-dp+1)%mod tot=(tot+dp)%mod for v in val: cnt[v]+=dp cnt[v]%=mod #print(a,dp,tot) print(tot)