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).
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 ).
Print exactly one integer — the number of good subsequences taken modulo 109+7109+7 .
2
1 2
3
5
2 2 1 22 14
13
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.
题意
给一个序列a,求a的good子序列b,good的定义为:对于bi可以整除i。求一共多少种good子序列。
分析
考虑dp,dp[i][j]表示在a1 a2 a3 a4......ai中长度为j的good序列的个数。所以结果就是∑ni=1dp[n][i],
dp[i−1][j]+dp[i−1][j−1] if a[i] is a multiple of j
dp[i][j]=
dp[i−1][j] otherwise
二维会超内存,所以用第一维都是dp[i-1],所以用一维数组存就可以了。

/// author:Kissheart /// #include<stdio.h> #include<algorithm> #include<iostream> #include<string.h> #include<vector> #include<stdlib.h> #include<math.h> #include<queue> #include<deque> #include<ctype.h> #include<map> #include<set> #include<stack> #include<string> #define INF 0x3f3f3f3f #define FAST_IO ios::sync_with_stdio(false) const double PI = acos(-1.0); const double eps = 1e-6; const int MAX=1e6+10; const int mod=1e9+7; typedef long long ll; using namespace std; #define gcd(a,b) __gcd(a,b) inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;} inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;} inline ll inv1(ll b){return qpow(b,mod-2);} inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;} inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;} //freopen( "in.txt" , "r" , stdin ); //freopen( "data.txt" , "w" , stdout ); ll n,ans; ll a[MAX]; ll dp[MAX]; int main() { scanf("%lld",&n); for(int i=1;i<=n;i++) scanf("%lld",&a[i]); dp[0]=1; for(int i=1;i<=n;i++) { vector<ll>v; for(int j=1;j*j<=a[i];j++) { if(a[i]%j==0) { v.push_back(j); if(j*j!=a[i]) v.push_back(a[i]/j); } } sort(v.begin(),v.end()); reverse(v.begin(),v.end()); for(auto &it: v) { dp[it]+=dp[it-1]; dp[it]%=mod; } } for(int i=1;i<=n;i++) ans+=dp[i]; ans%=mod; printf("%lld ",ans); return 0; }