output
standard output
You are given an integer array a1,a2,…,ana1,a2,…,an.
The array bb is called to be a subsequence of aa if it is possible to remove some elements from aa to get bb.
Array b1,b2,…,bkb1,b2,…,bk is called to be good if it is not empty and for every ii (1≤i≤k1≤i≤k) bibi is divisible by ii.
Find the number of good subsequences in aa modulo 109+7109+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 aa has exactly 2n−12n−1 different subsequences (excluding an empty subsequence).
Input
The first line contains an integer nn (1≤n≤1000001≤n≤100000) — the length of the array aa.
The next line contains integers a1,a2,…,ana1,a2,…,an (1≤ai≤1061≤ai≤106).
Output
Print exactly one integer — the number of good subsequences taken modulo 109+7109+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,2}{1,2}, {2}{2}
In the second example, the possible good subsequences are: {2}{2}, {2,2}{2,2}, {2,22}{2,22}, {2,14}{2,14}, {2}{2}, {2,22}{2,22}, {2,14}{2,14}, {1}{1}, {1,22}{1,22}, {1,14}{1,14}, {22}{22}, {22,14}{22,14}, {14}{14}.
Note, that some subsequences are listed more than once, since they occur in the original array multiple times.
思路:这道题一眼看去无从下手,看了大佬的博客知道了这是一道类似01背包的题(个人觉得).
这道题有三点要注意
1.定义状态 dp[i][j]表示序列前i个长度为j的子序列有多少个.
2.状态转移我们考虑第i个长度为j那么它只能从dp[i-1][j-1]转移过来(这就好比01背包选了第i个物品).
3.因为序列是删除得来的所以子序列的编号一定比原来小(博主刚开始觉得要加判断条件,后来想了一下状态的转移已经保证了得到子序列一定比原来小因为如果你j是3那么她一定有2转移过来这就保证前面有两个数时j=3才会贡献答案)
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#define LL long long
using namespace std;
const int maxn=1e5+100;
const int maxm=1e6+100;
const LL mod=1e9+7;
int a[maxn];
vector<int>st;
LL dp[maxm];
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
dp[0]=1;
for(int i=1;i<=n;i++)
{
st.clear();
for(int j=1;j*j<=a[i];j++)
{
if(a[i]%j==0)
{
if(j!=a[i]/j)
{
st.push_back(j);
st.push_back(a[i]/j);
}
else
{
st.push_back(j);
}
}
}
sort(st.begin(),st.end());
reverse(st.begin(),st.end());
for(auto &i:st)
{
dp[i]+=dp[i-1];
dp[i]%=mod;
}
}
LL ans=0;
for(int i=1;i<=n;i++)
{
ans+=dp[i];
ans%=mod;
}
printf("%lld\n",ans);
return 0;
}