PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000005. Số nguyên tố lớn nhất trong dãy (Largest Prime in an Array)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Số nguyên tố lớn nhất trong dãy (Largest Prime in an Array)

Largest Prime in an Array

Source: LQDOJ

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an array of nn integers a1,a2,…,ana_1,a_2,\ldots,a_n. A prime is an integer greater than 11 having exactly two positive divisors, 11 and itself. For example, 22, 33, 55, and 77 are prime, while −3-3, 00, 11, 44, and 99 are not.

Among all prime-valued entries in the array, find the largest value and list every position at which it occurs, in left-to-right order. Array positions are numbered from 11 to nn. Print original array positions, not ranks among prime entries.

Phuoc Hung OJ Extended clarification: If the array contains no prime, the answer is -1. The original statement does not specify this case; this convention is added so that every valid input has a well-defined output.

Input

  • The first line contains a positive integer nn, the array length.
  • The second line contains exactly nn space-separated integers a1,a2,…,ana_1,a_2,\ldots,a_n in array order.

Output

If at least one array entry is prime:

  • On the first line, output the largest prime value in the array.
  • On the second line, output all positions ii satisfying aia_i equals that largest prime, in ascending order, separated by single spaces.

If there is no prime entry, output only -1 on one line.

Subtasks

  • Subtask 1 (20 points): 1≤n≤1001\le n\le 100; −104≤ai≤104-10^4\le a_i\le 10^4 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; −106≤ai≤106-10^6\le a_i\le 10^6 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤100001\le n\le 10000; −108≤ai≤108-10^8\le a_i\le 10^8 for every 1≤i≤n1\le i\le n.

Examples

Example 1

Input

9
19 7 81 33 17 4 19 21 13

Output

19
1 7

Explanation

The array contains nine entries. Reading them from left to right:

  • a1=19a_1=19 is prime, so we record value 1919 at position 11.
  • a2=7a_2=7 is prime but smaller than 1919.
  • a3=81=9⋅9a_3=81=9\cdot9 and a4=33=3⋅11a_4=33=3\cdot11 are composite.
  • a5=17a_5=17 is prime but smaller than 1919.
  • a6=4=2⋅2a_6=4=2\cdot2 is composite.
  • a7=19a_7=19 is prime and equals the current largest prime value.
  • a8=21=3⋅7a_8=21=3\cdot7 is composite. a9=13a_9=13 is prime, but smaller than 1919.

The maximum prime value is therefore 1919, which occurs exactly at positions 11 and 77. Those values form the two output lines.

Example 2

Input

6
-7 0 1 4 9 100

Output

-1

Explanation

The values −7-7, 00, and 11 are not prime. The remaining values are composite: 4=224=2^2, 9=329=3^2, and 100=22⋅52100=2^2\cdot5^2. The array has no prime, so the added convention requires printing -1.