I have studied about finding LIS (longest increasing subsequence) How do I extend that knowledge to find LIS where gcd(xi, xi+1) > 1? Please help me here is the link to the question https://codeforces.me/problemset/problem/264/B
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
I have studied about finding LIS (longest increasing subsequence) How do I extend that knowledge to find LIS where gcd(xi, xi+1) > 1? Please help me here is the link to the question https://codeforces.me/problemset/problem/264/B
Название |
---|
Hint : The problem is related to prime factors. # of prime factors of $$$a_i$$$ is small.
Find prime factors by doing like "Sieve of Eratosthenes".
Hold largest length of sequence ever whose last element has the particular prime factor.
you mean this dp would work dp[i] = dp[i] + 1. where i is one of the primefactors of ith number. right? if yes then the maximum value of this array will be our answer?
No, (1) all dp[i] must be replaced with (2) (max of all dp[i])+1 where i is one of the primefactors. For example, when a=6, replace dp[2] and dp[3] with max(dp[2],dp[3])+1. This is because (1)[6 is a multiple of 2 and a multiple of 3], and (2)[we can put 6 after a multiple of 2 or a multiple of 3]. However, "max of dp array will be our answer" is right.
/* If you need, see my submission. */ Sorry my submission isn't fit the explanation.