-
Notifications
You must be signed in to change notification settings - Fork 0
/
B.cpp
47 lines (45 loc) · 950 Bytes
/
B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//Looked editorial
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
int dp[100005],d[100005],ara[100005],mx;
int main()
{
fastio;
int n,i,j;
cin>>n;
for(i=0;i<n;i++)
cin>>ara[i];
if(n==1)
{
cout<<1<<"\n";
return 0;
}
for(i=0;i<n;i++)
{
for(j=2;j*j<=ara[i];j++)
{
if(ara[i]%j==0)
{
dp[ara[i]]=max(dp[ara[i]],d[j]+1);
dp[ara[i]]=max(dp[ara[i]],d[ara[i]/j]+1);
}
}
dp[ara[i]]=max(1,dp[ara[i]]);
for(j=2;j*j<=ara[i];j++)
{
if(ara[i]%j==0)
{
d[j]=dp[ara[i]];
d[ara[i]/j]=dp[ara[i]];
}
}
d[ara[i]]=dp[ara[i]];
}
for(i=0;i<n;i++)
{
//cout<<dp[ara[i]]<<"\n";
mx=max(mx,dp[ara[i]]);
}
cout<<mx<<"\n";
}