Code Golf Challenge P4 - Function Minimization

View as PDF

Submit solution

Points: 12 (partial)
Time limit: 2.0s
Memory limit: 512M

Author:
Problem types

You are given a function:

\displaystyle f(x) = \begin{cases} x & \text{if } (x-1)!+1 \equiv 0\pmod x \\ -x & \text{if } (x-1)!+1 \not\equiv 0\pmod x \end{cases}

where ! denotes the factorial operation. In other words, the function returns x if (x-1)!+1 is divisible by x, and -x otherwise.

Given an array a, print out the minimum value of f(x) for all elements in a.

Input Specification

The first line will contain the integer N (1 \le N \le 10^5).

The second line will contain N integers, a_1, a_2, \ldots, a_N (2 \le a_i \le 10^6).

Output Specification

Print the minimum value of f(x) for all elements in a.

Scoring

Let L represent the number of characters in your solution.

If L is less than 160, your score will be \min (1, 1-\frac{L-137}{40}) \times 100\%.

If L is greater than or equal to 160, and less than 1 000, your score is (\frac{150}{L})^2 \times 50\%.

Otherwise, your score is 0.

Sample Input

8
2 5 3 9 3 5 7 12

Sample Output

-12

Comments

There are no comments at the moment.