#P6570. [NOI Online #3 提高组] 优秀子序列

[NOI Online #3 提高组] 优秀子序列

Problem Description

Given a non-negative integer sequence A={a1,a2,,an}A=\{a_1,a_2,\cdots,a_n\} of length nn. For a subsequence of AA, B={ab1,ab2,,abm}B=\{a_{b_1},a_{b_2},\cdots,a_{b_m}\} (0mn0\le m\le n, 1b1<b2<<bmn1\le b_1<b_2<\cdots<b_m\le n, same below), we call BB an excellent subsequence of AA if and only if the bitwise AND of any two different elements is 00, that is: for all 1i<jm1\le i<j\le m, it holds that abi and abj=0a_{b_i}~\mathrm{and}~a_{b_j}=0, where  and ~\mathrm{and}~ is the bitwise AND operation.

For the subsequence B={ab1,ab2,,abm}B=\{a_{b_1},a_{b_2},\cdots,a_{b_m}\}, we define its value as φ(1+i=1mabi)\varphi(1+\sum_{i=1}^m a_{b_i}), where φ(x)\varphi(x) denotes the number of positive integers not greater than xx that are coprime to xx.

Now please compute the sum of values of all excellent subsequences of AA. Output the answer modulo 109+710^9+7.

Input Format

The first line contains a positive integer nn, denoting the length of the sequence.

The second line contains nn non-negative integers separated by spaces, denoting a1,a2,,ana_1,a_2,\cdots,a_n.

Output Format

Only one line with one integer, denoting the result of the answer modulo 109+710^9+7.

4
1 2 2 3
12

Hint

Explanation for Sample 1

The valid subsequences are: \emptyset, {1}\{1\}, {2}\{2\}, {2}\{2\}, {3}\{3\}, {1,2}\{1,2\}, {1,2}\{1,2\}. Their values are 11, 11, 22, 22, 22, 22, 22, respectively, and the total sum is 1212.

Constraints

  • For 10%10\% of the testdata, it is guaranteed that ai1a_i\le 1.
  • For 30%30\% of the testdata, it is guaranteed that ai1000a_i\le 1000.
  • For 60%60\% of the testdata, it is guaranteed that ai30000a_i\le 30000.
  • There is another 10%10\% of the testdata where it is guaranteed that n20n\le 20.
  • For 100%100\% of the testdata, it is guaranteed that 1n1061\le n\le 10^6 and 0ai2×1050\le a_i\le 2\times 10^5.

Translated by ChatGPT 5