C. Multiplicity(dp,欧拉)

C. Multiplicity

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.

题意:

       给出一个数组a,然后可以移除一些元素变成数组b,这个数组b有个规定是:如果第i个元素可以整除i,那么这个数组b就是好的,现在问数组a可以构造出多少个数组b.

解析:

dp[i][j]代表前i个数构成长度为j的b数组的方案数目

dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1] 

用滚动数组优化空间

dp[j] = dp[j] + dp[j - 1]     

如果当前数字能整除x,她一定可以放在所有长度为x-1的子序列的后面,但是这样会有本层状态影响,所以因子从大到小dp,之后统计所有长度的合法子序列之和就可以了

ac:

#include<bits/stdc++.h>
#define ll long long
#define MAXN 100005
using namespace std;

const int mod =1e9+7;

int a[MAXN];
ll dp[MAXN];
vector<int> p[MAXN*10];

void init()//预先处理因子
{
    for(int i=1;i<=MAXN*10;i++)
    {
        for(int j=i;j<=MAXN*10;j+=i)
        {
            p[j].push_back(i);
        }
    }
}

int main()
{
    int n;
    init();
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
    {
        int m=p[a[i]].size();
        for(int j=m-1;j>=0;j--)
        {
            int t=p[a[i]][j];
            if(t>i) continue;
            if(t==1)
                dp[1]=(dp[1]+1)%mod;
            else
                dp[t]=(dp[t]+dp[t-1])%mod;
        }
    }
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        ans=(ans+dp[i])%mod;
    }
    printf("%I64d\n",ans);
    return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值