codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1033B.md (2236B)


      1 Source: https://codeforces.com/problemset/problem/1033/B
      2 
      3 B. Square Difference
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Alice has a lovely piece of cloth. It has the shape of a square with a side of length $a$ centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length $b$ centimeters (where $b \lt a$). Alice wanted to make Bob happy, so she cut the needed square out of the corner of her piece and gave it to Bob. Now she is left with an ugly L shaped cloth (see pictures below).
     22 
     23 Alice would like to know whether the area of her cloth expressed in square centimeters is [prime.](https://en.wikipedia.org/wiki/Prime_number) Could you help her to determine it?
     24 
     25 Input
     26 
     27 The first line contains a number $t$ ($1 \leq t \leq 5$) — the number of test cases.
     28 
     29 Each of the next $t$ lines describes the $i$-th test case. It contains two integers $a$ and $b~(1 \leq b \lt a \leq 10^{11})$ — the side length of Alice's square and the side length of the square that Bob wants.
     30 
     31 Output
     32 
     33 Print $t$ lines, where the $i$-th line is the answer to the $i$-th test case. Print "YES" (without quotes) if the area of the remaining piece of cloth is prime, otherwise print "NO".
     34 
     35 You can print each letter in an arbitrary case (upper or lower).
     36 
     37 Example
     38 
     39 Input
     40 
     41 ```
     42 4  
     43 6 5  
     44 16 13  
     45 61690850361 24777622630  
     46 34 33
     47 ```
     48 
     49 Output
     50 
     51 ```
     52 YES  
     53 NO  
     54 NO  
     55 YES
     56 ```
     57 
     58 Note
     59 
     60 The figure below depicts the first test case. The blue part corresponds to the piece which belongs to Bob, and the red part is the piece that Alice keeps for herself. The area of the red part is $6^2 - 5^2 = 36 - 25 = 11$, which is prime, so the answer is "YES".
     61 
     62  ![](https://espresso.codeforces.com/b29e42c626fc9d2580f4479dd82d3af14ed0e360.png) 
     63 
     64 In the second case, the area is $16^2 - 13^2 = 87$, which is divisible by $3$.
     65 
     66  ![](https://espresso.codeforces.com/8b50da81e605e010eb1d67e23d56313ef985538b.png) 
     67 
     68 In the third case, the area of the remaining piece is $61690850361^2 - 24777622630^2 = 3191830435068605713421$. This number is not prime because $3191830435068605713421 = 36913227731 \cdot 86468472991 $.
     69 
     70 In the last case, the area is $34^2 - 33^2 = 67$.