Please help me. The statement is: Give an array A with n integers(n <= 10^5). Your task is to find the longest increasing subsequence that gcd of 2 consecutive elements is > 1.
Example:
input
5
2 3 4 6 9
output
4
# | User | Rating |
---|---|---|
1 | tourist | 3690 |
2 | jiangly | 3647 |
3 | Benq | 3581 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | Radewoosh | 3509 |
8 | ecnerwala | 3486 |
9 | jqdai0815 | 3474 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 164 |
3 | adamant | 162 |
4 | TheScrasse | 160 |
5 | nor | 158 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 152 |
8 | orz | 146 |
9 | pajenegod | 145 |
9 | SecondThread | 145 |
Please help me. The statement is: Give an array A with n integers(n <= 10^5). Your task is to find the longest increasing subsequence that gcd of 2 consecutive elements is > 1.
Example:
input
5
2 3 4 6 9
output
4
Name |
---|
I think this is solvable in n.sqrt(max(Ai)).logn.
I think sqrt(maxAi) part can be even reduced to <= 30 since each number can have at most <= 20 unique prime factors if Ai <= 10^9
Heyy man, the general idea is shown below:
I also added brute force validator to verify my algorithm.
200% confidence this algorithm is right since I tested with many random inputs from https://planetcalc.com/5843/. random sequence generated online
Try $$$[3, 3, 3]$$$.