We need to read two integers n and m, with 2 ≤ n < m ≤ 50, n is prime. We need to check if m is the next prime after n, i.e., m is prime and there is no prime between n and m (exclusive). Since m ≤ 50, we can simply generate primes up to 50 and check.
Simpler: Check if m is prime and if there is any prime p such that n < p < m. If no such prime, then YES else NO.
Edge: n and m are given, m > n. Since n is prime guaranteed. So we can just check m prime and check all numbers between n+1 and m-1 for primality. If any prime found, answer NO, else YES (provided m is prime). But careful: what if m is not prime? Then answer is NO, because the prophecy requires y to be prime and next prime after x. So if m is not prime, it cannot be the next prime. So we need to output YES only if m is prime and there is no prime between n and m.
Constraints small, so trivial.
Implement: function isPrime(x): if x<2 false; for i=2 to sqrt(x) (or x-1) check divisibility. Since x≤50, we can check up to x-1 or use small list.
List of primes up to 50: 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47. Next prime after 47 is 53 >50, so within range.
We can also precompute.
Given input, we output YES/NO.
Test examples: (3,5): primes: between 3 and 5 exclusive (4) none, m=5 prime, yes. (7,11): primes between 7 and 11 exclusive: 11? Actually exclusive: 8,9,10 none prime; but note 11 is prime, and no prime in between, yes. (7,9): m=9 not prime, so NO.
Edge: (2,3) -> YES? n=2 prime, m=3 prime, no prime between (none), so YES. (2,4) -> m=4 not prime -> NO. (3,4) -> m=4 not prime -> NO. (13,17) -> primes between: none? Actually primes: 13,17, check 15? not prime, 16 not prime, so YES. (13,15) -> m not prime -> NO. (23,29): primes between: none, since next prime after 23 is 29? Actually 29 is next? Wait, primes: 23,29. But 23, 29 skip 29? Check: 24,25,26,27,28 none prime, so yes 29 is next prime after 23. However, is 29 the next prime after 23? Actually 23's next prime is 29? Wait there is 23, then 29, but there is 24,25,26,27,28 all composite, yes. So answer YES. (23, 29) works.
Check: (7, 13): between 7 and 13 exclusive: 8,9,10,11,12 -> 11 is prime. So m=13 but there is prime 11, so 13 is not the next prime after 7; the next prime after 7 is 11. So answer NO.
So algorithm: if not isPrime(m): print NO. else: for i in range(n+1, m): if isPrime(i): print NO and return. Otherwise YES.
But note: if m is prime and n is prime, and there is no prime in between, then m is indeed the next prime after n? Check scenario: n=2, m=3. No prime in between? The primes between 2 and 3 exclusive are none, so yes. So works.
Thus solution.
Implementation: read n,m; define isPrime(x): if x<2: return False; for i in range(2, int(x**0.5)+1): if x%i==0: return False; return True. Since x≤50, simple.
Alternatively, can compute a set of primes up to 50.
Now complexity trivial.
We'll produce final answer.
But note that pretests are all cases with 2 ≤ n < m ≤ 4. That seems weird, but final test includes full range.
Thus answer.
I'll provide a python solution. ```python
import sys
def is_prime(x: int) -> bool:
if x < 2:
return False
for i in range(2, int(x**0.5) + 1):
if x % i == 0:
return False
return True
def main() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
n, m = map(int, data)
# Check if m is prime
if not is_prime(m):
print("NO")
return
# Check for any prime between n+1 and m-1
for i in range(n + 1, m):
if is_prime(i):
print("NO")
return
print("YES")
if name == "main":
main()