PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000119. Cặp chỉ số nguyên tố cùng nhau (Coprime)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Cặp chỉ số nguyên tố cùng nhau (Coprime)
Coprime
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array of positive integers , indexed from , maximize over all indices satisfying . The two indices may coincide. Print -1 if no such pair exists.
Input
The first line contains . The second contains integers .
Output
Print the maximum , or -1 if no valid pair exists.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
3
3 2 1
Output
6
Explanation
Choose : since and , the sum of indices is . Equal indices are allowed.