#P12157. Magic Incantation Combination
Magic Incantation Combination
Magic Incantation Combination
In this problem, you are given two lists of integers representing two parts of a magical incantation. The first list contains the upper parts and the second list contains the lower parts . A complete incantation is formed by choosing one upper part and one lower part, and its value is defined as $$S = a_i + b_j.$$
A spell is considered valid if it satisfies both of the following conditions:
- $$S \leq n+m$$
- $$S$$ is a prime number
inputFormat
The first line contains two integers $$n$$ and $$m$$, representing the number of upper and lower incantations respectively.
The second line contains $$n$$ integers, the upper incantations: $$a_1, a_2, \dots, a_n$$.
The third line contains $$m$$ integers, the lower incantations: $$b_1, b_2, \dots, b_m$$.
outputFormat
Output a single integer, which is the number of distinct valid spells (i.e. distinct values of $$S$$ such that $$S \leq n+m$$ and $$S$$ is a prime number).
sample
3 3
1 2 3
1 2 3
3