C. Multiplicity
time limit per test : 3 seconds
memory limit per test : 256 megabytes
You are given an integer array
.
The array
is called to be a subsequence of a if it is possible to remove some elements from a to get
.Array
is called to be good if it is not empty and for every
is divisible by
. Find the number of good subsequences in amodulo
.
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 has exactly different subsequences (excluding an empty subsequence).
Input
The first line contains an integer
— the length of the array
.
The next line contains integers
.
Output
Print exactly one integer — the number of good subsequences taken modulo
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: {
} , {
}, {
}.
In the second example, the possible good subsequences are: {
} , {
}, {
}, {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.
题意:
给定一个数组{
},问这个数组的所有子序列{
}中,有多少子序列满足:对于所有的
满足
是
的倍数,答案对
取模
题解:
先处理出
的所有因数。
接着就是DP
表示从
~
前面所有序列中,长度为
的方案数
所以
%
可以通过枚举
的因数得到
然后我们发现可以把
这个维度压掉…
#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;
}