LINE Verda プログラミングコンテスト(AtCoder Beginner Contest 263)
G
Erasing Prime Pairs
AtCoder
⌀ 2261
原题
← Ex→
翻译中…

Problem Statement

翻译中…

There are integers with $N$ different values written on a blackboard. The $i$-th value is $A_i$ and is written $B_i$ times.

翻译中…

You may repeat the following operation as many times as possible:

翻译中…
  • Choose two integers $x$ and $y$ written on the blackboard such that $x+y$ is prime. Erase these two integers.
翻译中…

Find the maximum number of times the operation can be performed.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 100$
  • $1 \leq A_i \leq 10^7$
  • $1 \leq B_i \leq 10^9$
  • All $A_i$ are distinct.
  • All values in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
A_1 B_1
A_2 B_2
\vdots
A_N B_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
3
3 3
2 4
6 2
Output #1
3
We have $2 + 3 = 5$, and $5$ is prime, so you can choose $2$ and $3$ to erase them, but nothing else. Since there are four $2$s and three $3$s, you can do the operation three times.
Input #2
1
1 4
Output #2
2
We have $1 + 1 = 2$, and $2$ is prime, so you can choose $1$ and $1$ to erase them. Since there are four $1$s, you can do the operation twice.
题目信息
题号
abc263_g
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。