codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

264B.md (1614B)


      1 Source: https://codeforces.com/problemset/problem/264/B
      2 
      3 B. Good Sequences
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks *n* integers *a*1, *a*2, ..., *a**n* are good.
     22 
     23 Now she is interested in good sequences. A sequence *x*1, *x*2, ..., *x**k* is called good if it satisfies the following three conditions:
     24 
     25 * The sequence is strictly increasing, i.e. *x**i* < *x**i* + 1 for each *i* (1 ≤ *i* ≤ *k* - 1).
     26 * No two adjacent elements are coprime, i.e. *gcd*(*x**i*, *x**i* + 1) > 1 for each *i* (1 ≤ *i* ≤ *k* - 1) (where *gcd*(*p*, *q*) denotes the greatest common divisor of the integers *p* and *q*).
     27 * All elements of the sequence are good integers.
     28 
     29 Find the length of the longest good sequence.
     30 
     31 Input
     32 
     33 The input consists of two lines. The first line contains a single integer *n* (1 ≤ *n* ≤ 105) — the number of good integers. The second line contains a single-space separated list of good integers *a*1, *a*2, ..., *a**n* in strictly increasing order (1 ≤ *a**i* ≤ 105; *a**i* < *a**i* + 1).
     34 
     35 Output
     36 
     37 Print a single integer — the length of the longest good sequence.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 5  
     45 2 3 4 6 9
     46 ```
     47 
     48 Output
     49 
     50 ```
     51 4
     52 ```
     53 
     54 Input
     55 
     56 ```
     57 9  
     58 1 2 3 5 6 7 8 9 10
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 4
     65 ```
     66 
     67 Note
     68 
     69 In the first example, the following sequences are examples of good sequences: [2; 4; 6; 9], [2; 4; 6], [3; 9], [6]. The length of the longest good sequence is 4.