C. Multiplicity
http://codeforces.com/problemset/problem/1061/C
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
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
Copy
2
1 2
output
Copy
3
input
Copy
5
2 2 1 22 14
output
Copy
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.
题意:输入一个由n个数组构成的数列,现在从其中删除一些元素(但不能删完),要求删除后形成的新数列,满足每个位置的数值都能被整除下标。问有多少种删法能够得到满足条件的数列?(删法不同,即使最终结果相同也记为两种方法)
/*
先预处理出来每个a【i】能放的位置,即a【i】的约数。
定义dp【i】表示长度为 i 的b序列有多少种。
那么转移方程如下:dp【i】= dp【i】+ dp【i-1】
为什么?
因为,假如我们想有一个长度为3的序列,
那么我们必须得有至少一条长度为2的序列。
注意:
这里我们需要枚举各个a【i】的约数,
然后判断他能放在哪里的位置。
如果这个能放在这个位置j,那么长度为j的数列数量dp[j]+=dp[j-1] 这里要好好想想
所以我们需要把他的约数从小到大排序,
然后倒着枚举,原理同01背包倒着枚举一样。
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10,M=1e6+10;
const ll mod=1e9+7;
ll a[N],dp[M];
int cnt;
void cal(int x)
{
cnt=0;
for(int i=1;i*i<=x;++i)
{
if(i*i==x)
{
a[++cnt]=i;
continue;
}
if(x%i==0)
{
a[++cnt]=i;
a[++cnt]=x/i;
}
}
}
int main()
{
dp[0]=1;
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
cal(x);
sort(a+1,a+1+cnt);
for(int j=cnt;j>=1;--j)
{
dp[a[j]]=dp[a[j]]+dp[a[j]-1];
dp[a[j]]%=mod;
}
}
ll sum=0;
for(int i=1;i<=1e6+5;i++)
{
sum=(sum+dp[i])%mod;
}
printf("%lld\n",sum%mod);
}