codeforces-scrape

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

566F.md (1747B)


      1 Source: https://codeforces.com/problemset/problem/566/F
      2 
      3 F. Clique in the Divisibility Graph
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 As you must know, the maximum clique problem in an arbitrary graph is *NP*-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
     22 
     23 Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.
     24 
     25 Let's define a divisibility graph for a set of positive integers *A* = {*a*1, *a*2, ..., *a**n*} as follows. The vertices of the given graph are numbers from set *A*, and two numbers *a**i* and *a**j* (*i* ≠ *j*) are connected by an edge if and only if either *a**i* is divisible by *a**j*, or *a**j* is divisible by *a**i*.
     26 
     27 You are given a set of non-negative integers *A*. Determine the size of a maximum clique in a divisibility graph for set *A*.
     28 
     29 Input
     30 
     31 The first line contains integer *n* (1 ≤ *n* ≤ 106), that sets the size of set *A*.
     32 
     33 The second line contains *n* distinct positive integers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 106) — elements of subset *A*. The numbers in the line follow in the ascending order.
     34 
     35 Output
     36 
     37 Print a single number — the maximum size of a clique in a divisibility graph for set *A*.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 8  
     45 3 4 6 8 10 18 21 24
     46 ```
     47 
     48 Output
     49 
     50 ```
     51 3
     52 ```
     53 
     54 Note
     55 
     56 In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph.