#abc263g. G - Erasing Prime Pairs

G - Erasing Prime Pairs

Score : 600600 points

问题描述

在黑板上有 NN 个不同数值的整数。第 ii 个数值是 AiA_i,并且被写了 BiB_i 次。

你可以尽可能多地重复以下操作:

  • 选择黑板上两个整数 xxyy,要求满足 x+yx+y 是质数。擦除这两个整数。

找出该操作最多能执行多少次。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are integers with NN different values written on a blackboard. The ii-th value is AiA_i and is written BiB_i times.

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

  • Choose two integers xx and yy written on the blackboard such that x+yx+y is prime. Erase these two integers.

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

Constraints

  • 1N1001 \leq N \leq 100
  • 1Ai1071 \leq A_i \leq 10^7
  • 1Bi1091 \leq B_i \leq 10^9
  • All AiA_i are distinct.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 B1B_1

A2A_2 B2B_2

\vdots

ANA_N BNB_N

Output

Print the answer.

Sample Input 1

3
3 3
2 4
6 2

Sample Output 1

3

We have 2+3=52 + 3 = 5, and 55 is prime, so you can choose 22 and 33 to erase them, but nothing else. Since there are four 22s and three 33s, you can do the operation three times.

Sample Input 2

1
1 4

Sample Output 2

2

We have 1+1=21 + 1 = 2, and 22 is prime, so you can choose 11 and 11 to erase them. Since there are four 11s, you can do the operation twice.

update @ 2024/3/10 11:08:26