Logo
(追記) (追記ここまで)

21032번 - Odd GCD Matching 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB78605384.127%

문제

Supposed there are N integers A1..N. Ai can be paired with Aj if GCD(Ai, Aj) is an odd number. GCD(a, b) is the greatest common divisor of a and b. For example, 6 can be paired with 9 because GCD(6, 9) = 3 is an odd number; however, 12 cannot be paired with 8 because GCD(12, 8) = 4 is an even number.

An odd GCD matching of A1..N is a set of pairs which satisfies the following.

  • Each pair contains two integers (i, j) where 1 ≤ i < j ≤ N.
  • Each integer i only appears at most once in the set.
  • If (i, j) is in the set, then Ai must be able to be paired with Aj.

Given A1..N, your task is to find the size of a maximum odd GCD matching of A1..N. An odd GCD matching is maximum if and only if there are no other odd GCD matching which has more pairs than it.

For example, let A1..5 = {6, 8, 9, 12, 13}. The size of a maximum odd GCD matching in this example is 2; one such example is {(1, 3),(2, 5)} which corresponds to the pairs (A1 = 6 with A3 = 9) and (A2 = 8 with A5 = 13). Note that {(1, 3)} with the size of 1 is also a valid odd GCD matching, but it is not a maximum one. On the other hand, {(2, 4)} is not a valid odd GCD matching as A2 = 8 cannot be paired with A4 = 12 in this example.

입력

Input begins with a line containing an integer: N (1 ≤ N ≤ 20 000) representing the size of A. The next line contains N integers: Ai (1 ≤ Ai ≤ 106) representing the array A.

출력

Output in a line an integer representing the size of a maximum odd GCD matching of A1..N.

제한

예제 입력 1

5
6 8 9 12 13

예제 출력 1

2

This is the example from the problem description.

예제 입력 2

3
10 10 10

예제 출력 2

0

With 3 elements, the candidate pairs are only (1, 2), (1, 3), and (2, 3). However, none of these candidates are valid as all GCD(Ai , Aj ) are not an odd number, thus, the maximum odd GCD matching for this case is an empty set {} with a size of 0.

예제 입력 3

7
4 3 2 4 5 6 3

예제 출력 3

3

One example maximum odd GCD matching is {(1, 5),(2, 4),(3, 7)} which contains 3 pairs.

힌트

출처

ICPC > Regionals > Asia Pacific > Indonesia > Indonesia National Contest > INC 2019 K번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /