C. Multiplicity
time limit per test : 3 seconds
memory limit per test : 256 megabytes
You are given an integer array
a
1
,
a
2
,
…
,
a
n
a_1,a_2,…,a_n
a1,a2,…,an.
The array
b
b
b is called to be a subsequence of a if it is possible to remove some elements from a to get
b
b
b.Array
b
1
,
b
2
,
…
,
b
k
b_1,b_2,…,b_k
b1,b2,…,bk is called to be good if it is not empty and for every
i
(
1
≤
i
≤
k
)
b
i
i (1≤i≤k) b_i
i(1≤i≤k)bi is divisible by
i
i
i. Find the number of good subsequences in amodulo
1
0
9
+
7
10^9+7
109+7.
Two subsequences are considered different if index sets of numbers included in them are different. That is, the values of the elements do not matter in the comparison of subsequences. In particular, the array a a a has exactly 2 n − 1 2^n−1 2n−1 different subsequences (excluding an empty subsequence).
Input
The first line contains an integer
n
(
1
≤
n
≤
100000
)
n(1≤n≤100000)
n(1≤n≤100000) — the length of the array
a
a
a.
The next line contains integers
a
1
,
a
2
,
…
,
a
n
(
1
≤
a
i
≤
1
0
6
)
a_1,a_2,…,a_n(1≤a_i≤10^6)
a1,a2,…,an(1≤ai≤106).
Output
Print exactly one integer — the number of good subsequences taken modulo
1
0
9
+
7
10^9+7
109+7
Examples
Input
2
1 2
Output
3
Input
5
2 2 1 22 14
Output
13
Note
In the first example, all three non-empty possible subsequences are good: {
1
1
1} , {
1
,
2
1,2
1,2}, {
2
2
2}.
In the second example, the possible good subsequences are: {
2
2
2} , {
2
,
2
2,2
2,2}, {
2
,
22
2,22
2,22}, {2,14}, {2}, {2,22}, {2,14}, {1}, {1,22}, {1,14}, {22}, {22,14}, {14}.
Note, that some subsequences are listed more than once, since they occur in the original array multiple times.
题意:
给定一个数组{
a
k
a_k
ak},问这个数组的所有子序列{
b
k
b_k
bk}中,有多少子序列满足:对于所有的
i
(
1
<
=
i
<
=
k
)
i(1<=i<=k)
i(1<=i<=k)满足
b
i
b_i
bi 是
i
i
i 的倍数,答案对
1
0
9
+
7
10^9+7
109+7取模
题解:
先处理出
a
[
i
]
a[i]
a[i]的所有因数。
接着就是DP
f
[
i
]
[
j
]
f[i][j]
f[i][j]表示从
1
1
1~
i
i
i前面所有序列中,长度为
j
j
j的方案数
所以
f
[
i
]
[
j
]
=
(
f
[
i
]
[
j
]
+
f
[
i
]
[
j
−
1
]
)
f[i][j]=(f[i][j]+f[i][j-1])
f[i][j]=(f[i][j]+f[i][j−1])%
M
O
D
MOD
MOD
j
j
j可以通过枚举
a
[
i
]
a[i]
a[i]的因数得到
然后我们发现可以把
i
i
i这个维度压掉…
#include<bits/stdc++.h>
#define LiangJiaJun main
#define ll long long
#define MOD 1000000007
using namespace std;
vector<int>v[100004];
int n,f[1000004];
int w33ha(){
memset(f,0,sizeof(f));
for(int i=1;i<=n;i++){
int x;
scanf("%d",&x);
v[i].clear();
for(int j=1;j<=sqrt(x);j++){
if(x%j==0){
v[i].push_back(j);
if(x!=j*j)v[i].push_back(x/j);
}
}
sort(v[i].begin(),v[i].end());
}
ll ans=0;
f[0]=1;
for(int i=1;i<=n;i++){
for(int j=v[i].size()-1;j>=0;j--){
f[v[i][j]]=(f[v[i][j]]+f[v[i][j]-1])%MOD;
ans=(ans+f[v[i][j]-1])%MOD;
}
}
printf("%d\n",ans);
return 0;
}
int LiangJiaJun(){
while(scanf("%d",&n)!=EOF)w33ha();
return 0;
}