题目分析:
蛮简单的一道题,对于每个数拆质因子,对于每个质因子找出最长链,在每个地方枚举一下拼接
代码:
1 #include2 using namespace std; 3 4 const int maxn = 205000; 5 6 int n,a[maxn],prime[maxn],flag[maxn],minn[maxn],num,ans; 7 vector g[maxn]; 8 vector > mp[maxn]; 9 10 vector cl[maxn];11 12 void getprime(int N){13 for(int i=2;i<=N;i++){14 if(!flag[i]){prime[++num] = i,minn[i] = i;}15 for(int j=1;j<=num&&i*prime[j]<=N;j++){16 flag[i*prime[j]] = 1;17 minn[i*prime[j]] = prime[j];18 if(i%prime[j] == 0) break;19 }20 }21 }22 23 void read(){24 scanf("%d",&n);25 for(int i=1;i<=n;i++) scanf("%d",&a[i]);26 for(int i=1;i = maxx) sec = maxx,maxx = cl[z][i];53 else if(cl[z][i] > sec) sec = cl[z][i];54 }55 mp[now].push_back(make_pair(z,maxx+1));56 ans = max(ans,maxx+sec+1);57 }58 }59 60 void work(){61 getprime(200000);62 dp(1,0);63 printf("%d\n",ans);64 }65 66 int main(){67 read();68 work();69 return 0;70 }