F. Coprime Subsequences

Codeforces
IDCF803F
Time2000ms
Memory256MB
Difficulty
bitmaskscombinatoricsnumber theory
English · Original
Chinese · Translation
Formal · Original
Let's call a non-empty sequence of positive integers _a_1, _a_2... _a__k_ _coprime_ if the greatest common divisor of all elements of this sequence is equal to 1. Given an array _a_ consisting of _n_ positive integers, find the number of its _coprime_ subsequences. Since the answer may be very large, print it modulo 109 + 7. Note that two subsequences are considered different if chosen indices are different. For example, in the array \[1, 1\] there are 3 different subsequences: \[1\], \[1\] and \[1, 1\]. ## Input The first line contains one integer number _n_ (1 ≤ _n_ ≤ 100000). The second line contains _n_ integer numbers _a_1, _a_2... _a__n_ (1 ≤ _a__i_ ≤ 100000). ## Output Print the number of _coprime_ subsequences of _a_ modulo 109 + 7. [samples] ## Note In the first example _coprime_ subsequences are: 1. 1 2. 1, 2 3. 1, 3 4. 1, 2, 3 5. 2, 3 In the second example all subsequences are _coprime_.
我们称一个非空正整数序列 #cf_span[a1, a2... ak] 为 _互质_ 的,当且仅当该序列所有元素的最大公约数等于 #cf_span[1]。 给定一个包含 #cf_span[n] 个正整数的数组 #cf_span[a],求其 _互质_ 子序列的数量。由于答案可能很大,请对 #cf_span[109 + 7] 取模输出。 注意,如果所选下标不同,则两个子序列被视为不同。例如,在数组 #cf_span[[1, 1]] 中,有 #cf_span[3] 个不同的子序列:#cf_span[[1]]、#cf_span[[1]] 和 #cf_span[[1, 1]]。 第一行包含一个整数 #cf_span[n](#cf_span[1 ≤ n ≤ 100000])。 第二行包含 #cf_span[n] 个整数 #cf_span[a1, a2... an](#cf_span[1 ≤ ai ≤ 100000])。 请输出数组 #cf_span[a] 的 _互质_ 子序列数量对 #cf_span[109 + 7] 取模的结果。 在第一个例子中,_互质_ 子序列为: 在第二个例子中,所有子序列都是 _互质_ 的。 ## Input 第一行包含一个整数 #cf_span[n](#cf_span[1 ≤ n ≤ 100000])。第二行包含 #cf_span[n] 个整数 #cf_span[a1, a2... an](#cf_span[1 ≤ ai ≤ 100000])。 ## Output 请输出数组 #cf_span[a] 的 _互质_ 子序列数量对 #cf_span[109 + 7] 取模的结果。 [samples] ## Note 在第一个例子中,_互质_ 子序列为: #cf_span[1] #cf_span[1, 2] #cf_span[1, 3] #cf_span[1, 2, 3] #cf_span[2, 3] 在第二个例子中,所有子序列都是 _互质_ 的。
**Definitions** Let $ n \in \mathbb{Z}^+ $ be the length of the array. Let $ A = (a_1, a_2, \dots, a_n) $ be a sequence of positive integers with $ 1 \leq a_i \leq 10^5 $. A subsequence $ S \subseteq A $ is *coprime* if $ \gcd(S) = 1 $. Let $ \mathcal{S} $ denote the set of all non-empty subsequences of $ A $. **Constraints** 1. $ 1 \leq n \leq 10^5 $ 2. $ 1 \leq a_i \leq 10^5 $ for all $ i \in \{1, \dots, n\} $ **Objective** Compute the number of coprime non-empty subsequences: $$ \left| \left\{ S \subseteq A \mid S \neq \emptyset,\ \gcd(S) = 1 \right\} \right| \mod (10^9 + 7) $$
Samples
Input #1
3
1 2 3
Output #1
5
Input #2
4
1 1 1 1
Output #2
15
Input #3
7
1 3 5 15 3 105 35
Output #3
100
API Response (JSON)
{
  "problem": {
    "name": "F. Coprime Subsequences",
    "description": {
      "content": "Let's call a non-empty sequence of positive integers _a_1, _a_2... _a__k_ _coprime_ if the greatest common divisor of all elements of this sequence is equal to 1. Given an array _a_ consisting of _n_",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF803F"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Let's call a non-empty sequence of positive integers _a_1, _a_2... _a__k_ _coprime_ if the greatest common divisor of all elements of this sequence is equal to 1.\n\nGiven an array _a_ consisting of _n_...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "我们称一个非空正整数序列 #cf_span[a1, a2... ak] 为 _互质_ 的,当且仅当该序列所有元素的最大公约数等于 #cf_span[1]。\n\n给定一个包含 #cf_span[n] 个正整数的数组 #cf_span[a],求其 _互质_ 子序列的数量。由于答案可能很大,请对 #cf_span[109 + 7] 取模输出。\n\n注意,如果所选下标不同,则两个子序列被视为不同。例如,在数组...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the length of the array.  \nLet $ A = (a_1, a_2, \\dots, a_n) $ be a sequence of positive integers with $ 1 \\leq a_i \\leq 10^5 $.  \nA subsequence $ S \\sub...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments