Friend numbers

Let x₁, …, x_(n) be a non-empty sequence of natural numbers, all of them
strictly larger than 1, and let gcd(x, y) stand as usual for the
greatest common divisor of x and y. We say that x_(i) is a friend of
x_(j) if and only if at least one of these conditions hold:

- gcd(x_(i), x_(j)) > 1;

- x_(i) is a friend of some x_(k), and x_(j) is also a friend of x_(k).

Write a program such that, given a sequence of numbers, computes the
size of the largest set of friends in it.

Input

Input consists of several cases. Every case begins with a number n ≥ 1,
followed by n different integer numbers, all them between 2 and 100000.

Output

For every case, print the size of the largest set of friends.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T10:16:09.897Z

© Jutge.org, 2006–2026.
https://jutge.org
