A Square Problem

View as PDF

Submit solution

Points: 7
Time limit: 2.0s
Memory limit: 64M

Problem type

Given \(a\) and \(b\), determine whether \(a^2-b^2\) is prime. You must do this \(T\) times.

Input Specification

The first line will contain the integer \(T\ (1 \le T \le 5)\), the number of cases.

The next \(T\) lines will each contain two integers, \(a, b\ (1 \le b < a \le 10^{11})\).

Output Specification

For each case, print YES if \(a^2-b^2\) is prime, and NO otherwise on its own line.

Sample Input

6 5
16 13
61690850361 24777622630
34 33

Sample Output



  • -425
    Evil  commented on Nov. 12, 2018, 5:11 p.m. edited

    This comment is hidden due to too much negative feedback. Click here to view it.

    • 0
      MstrPikachu  commented on Nov. 27, 2018, 4:47 p.m.

      You don't even need BigInteger to solve it in Java.

    • 2
      Musmid  commented on Nov. 13, 2018, 7:59 p.m.

      Side note: Use python or ruby instead.