def factorize(n): factors = {} while n % 2 == 0: factors[2] = factors.get(2, 0) + 1 n = n // 2 i = 3 while i * i <= n: while n % i == 0: factors[i] = factors.get(i, 0) + 1 n = n // i i += 2 if n > 2: factors[n] = 1 return factors def generate_divisors_with_mu(factors): primes = list(factors.keys()) divisors = [(1, {}, False)] # (value, exponents dict, has_squared) result = [] for p in primes: max_e = factors[p] temp = [] for d in divisors: current_value, current_exponents, current_has_squared = d # Append e=0 (same as current divisor) temp.append((current_value, current_exponents.copy(), current_has_squared)) for e in range(1, max_e + 1): new_value = current_value * (p ** e) new_exponents = current_exponents.copy() new_exponents[p] = e new_has_squared = current_has_squared or (e >= 2) temp.append((new_value, new_exponents, new_has_squared)) divisors = temp for d in divisors: value, exponents, has_squared = d if has_squared: mu = 0 else: k = len(exponents) mu = (-1) ** k result.append((value, mu)) # Remove duplicate divisors, keeping the first occurrence (mu should be consistent) unique = {} for val, mu in result: if val not in unique: unique[val] = mu return list(unique.items()) def main(): import sys input = sys.stdin.read().split() N = int(input[0]) A = list(map(int, input[1:N+1])) D = {} for a in A: if a == 0: continue # handle zero if needed, but problem says 1 <= A_i factors = factorize(a) if not factors and a == 1: factors = {} # 1's factors are none div_mu = generate_divisors_with_mu(factors) for d, mu in div_mu: if d not in D: D[d] = mu sum_total = 0 for d, mu in D.items(): count = 0 for x in A: if d == 0: continue if x % d == 0: count += 1 if count > 0: sum_total += mu * ((1 << count) - 1) print(sum_total) if __name__ == '__main__': main()