← All problemsSign in

Prime Sum

CodeChefRating 872Open on judge ↗

Chef has an integer array $A$ of length $N$ such that $1 \le A_i \le 3$. Chef is wondering how many pairs exist in his array, which have a prime sum. Formally, find the number of pairs $(i, j)$ such that - $1 \le i < j \le N$ - $A_i + A_j$ is prime. $X$ is a prime integer if it is not $1$, and has no other divisor except $1$ and $X$. For example, $2$, $13$ and $97$ are prime integers, while $1

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start