1. 程式人生 > >Codeforces Round #523 (Div. 2) C. Multiplicity

Codeforces Round #523 (Div. 2) C. Multiplicity

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

i">ii (1ik1≤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

a">aa has exactly 2n12n−1 different subsequences (excluding an empty subsequence).

Input

The first line contains an integer nn (1n1000001≤n≤100000 ) — the length of the array aa .

The next line contains integers

,an">a1,a2,,ana1,a2,…,an (1ai1061≤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,求a的good子序列b,good的定義為:對於bi可以整除i。求一共多少種good子序列。

分析

  考慮dp,dp[i][j]表示在a1 a2 a3 a4......ai中長度為j的good序列的個數。所以結果就是ni=1dp[n][i],

      dp[i1][j]+dp[i1][j1]              if a[i] is a multiple of j

  dp[i][j]=

      dp[i1][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\n",ans);
    return 0;
}
View Code

 

相關推薦

Codeforces Round #523 (Div. 2) C. Multiplicity

C. Multiplicity time limit per test 3 seconds memory limit per test 256 megabytes

Codeforces Round #523 (Div. 2) C Multiplicity

傳送門 https://www.cnblogs.com/violet-acmer/p/10005351.html   題意:   給定一陣列a[],從a[ ]中除去任意個元素得到b[ ],求能形成多少“好序列”;   好序列的定義是:對於任意的 i 有 b[i]%i == 0(1 

Codeforces Round #523 (Div. 2) C. Multiplicity DP

題意: 給n個整數的數列,你可以從中去掉一些數得到一個新的數列,新的數列是好數列當對於每一個i,a[i] %i == 0。 問你有多少個好數列 解題思路: dp求解,二維的dp很好想,dp[i][j]表示前i個數中 因數為j  的好數列的個數, 最後的答案就是sum(i

Codeforces Round #523 (Div. 2)C. Multiplicity

C. Multiplicity 題目連線 You are given an integer array a1,a2,…,an . The array b is called to be a subsequence of a if it is possible to remove

Codeforces Round #523(Div. 2)】Multiplicity(dp)

題目連結 C. Multiplicity time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output

Codeforces Round #415 (Div. 2) C. Do you want a date?

for 題目 point system pro only const man test C. Do you want a date? 2 seconds 256 megabytes Leha decided to move to a

【動態規劃】 Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip

and main spa def esp 動態 return 價值 can 劃分那個序列,沒必要完全覆蓋原序列。對於劃分出來的每個序列,對於某個值v,要麽全都在該序列,要麽全都不在該序列。 一個序列的價值是所有不同的值的異或和。整個的價值是所有劃分出來的序列的價值之和。

【動態規劃】Codeforces Round #406 (Div. 2) C.Berzerk

[1] space node sca 一個 for 隊列 ber 動態規劃 有向圖博弈問題。 能轉移到一個必敗態的就是必勝態。 能轉移到的全是必勝態的就是必敗態。 轉移的時候可以用隊列維護。 可以看這個 http://www.cnblogs.com/quintessence

Codeforces Round #260 (Div. 2)C. Boredom

color 題意 spa 等於 pre scanf 記得 logs ++ 題意:N個數,我們可以選擇某個數A,然後去掉A,和等於A+1,A-1的所有數字,得到A價值,問最後價值最大 思路:我們可以得到去掉A,得到的價值為A*A的個數,那麽dp[i]=max(dp[i]+dp

Codeforces Round #360 (Div. 2)C. NP-Hard Problem

並且 pri baidu code int str 兩個 printf 染色 題意:給出一個無向圖,問是否可以是二分圖, 思路:染色就行了,二分圖又稱作二部圖,是圖論中的一種特殊模型。 設G=(V,E)是一個無向圖,如果頂點V可分割為兩個互不相交的子集(A,B),並且圖中的

Codeforces Round #423 Div. 2 C-String Reconstruction(思維)

images memset clu 技術 ret .cn har ges round 題目大意:告訴你n個字符串以及這些字符串在字符串s中出現的位置(x1,x2.....xn),要求在滿足上述條件的情況下,求出字典序最小的字符串s。 解題思路:主要問題是,如果直接模擬是會超

Codeforces Round #423 (Div. 2) C 思維,並查集 或 線段樹 D 樹構造,水

closed alt pda memset sed () back ref cup Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) C. String Reconstruction 思維,並查

Codeforces Round #316 (Div. 2) C. Replacement

ont 復雜 problem tar ret ng- include return 題目 題意:給定一個字符串,裏面有各種小寫字母和’ . ‘ ,無論是什麽字母,都是一樣的,假設遇到‘ . . ‘ ,就要合並成一個‘ .‘,有m個詢問,每次都在字符串某個位置上將原來

Codeforces Round #181 (Div. 2)C

none 單獨 space stream cassert lib bool closed splay 用lucas定理, p必須是素數 對於單獨的C(n, m) mod p,已知C(n, m) mod p = n!/(m!(n - m)!) mod p。顯然除法取模,這裏

Codeforces Round #380 (Div. 2,) C C. Road to Cinema

容量 int pri 分鐘 cnblogs 思路 pre scan end 題意:n,k,s,t,n種車,k個加油站,s距離,t時間,問你是否能選一個最便宜的車,從0到s在t時間內,2種速度,1km/1L油/2分鐘和1km/2L油/1分鐘,路過加油站可加滿油並且不耗時間,給

Codeforces Round #431 (Div. 2) C

次數 reat bits bar solution sage das ces eno From beginning till end, this message has been waiting to be conveyed. For a given

Codeforces Round #435 (Div. 2) c+d

pan define ons eve vector class bits ace mod C:給n和k要求,找出n個不同的數,使得亦或起來等於k 可以先預處理從1到1e5,找亦或起來等於(11111111111111111)(二進制)的所有對數,然後四個一起亦或就是0了,

Codeforces Round #448 (Div. 2)C. Square Subsets

cos 什麽 using click clu pla std pri *** 可以用狀壓dp,也可以用線型基,但是狀壓dp沒看臺懂。。。 線型基的重要性質 性質一:最高位1的位置互不相同 性質二:任意一個可以用這些向量組合出的向量x,組合方式唯一 性質三:線性基的任

Codeforces Round #451 Div. 2 C D E

eve == ont span har else const 實用 iterator C。Phone Numbers 之前沒有做過字典樹……感覺這個題字典樹也能做……就拿來練一練字典樹……板子好多地方寫的都不夠好,還需要繼續改…… emmm這個……卡了好久啊……不過好在還

Codeforces Round #455 (Div. 2) C. Python Indentation dp遞推

air 方式 gpo pac sin -s font its 多少 Codeforces Round #455 (Div. 2) C. Python Indentation 題意:python 裏面,給出 n 個 for 循環或陳述語句,‘f‘ 裏面必須要有語句。按 p