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://mirror.codeforces.com/problemset/problem/264/B
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
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://mirror.codeforces.com/problemset/problem/264/B
Name |
---|
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.