Fantasy Pair
Time limit1sMemory limit256 MB
For each pair of string lengths A and B, decide whether their sum can be written as a sum of two primes.
- Level
Medium4 of 10
- Topics
- Math, Number theory, Brute force, Implementation
- Solved
- No attempts yet
Problem
In Didiland, the land of fantasy, every resident carries one string as a token of fate. Whether two residents are a fantasy pair is decided in a very plain way. Join their two strings into one, and if that string can be cut exactly into two strings whose lengths are both prime, the two residents are a fantasy pair. Deciding whether such a cut exists is hard for them, so most of them walk past each other without ever knowing.
Write a program that decides whether two residents are a fantasy pair.
Assume that joining the strings and cutting them lose no length at all.
Input
The first line contains the number of test cases ().
Each of the next lines contains the lengths and of the two strings, separated by a space. ()
Output
Print one line per test case. Print YES if the joined string can be cut exactly into two strings of prime length, and NO otherwise.