Given two squares with side lengths and (a > b). The task is to check if difference of their areas is prime or not. Here side length could be large ( 1 < b < a < 1012).
Input : a = 6, b = 5 Output : Yes Input : a = 61690850361, b = 24777622630 Output : No
Approach: Since the sides are and . Therefore, difference of their areas = (a2 – b2), which can be expressed as (a – b)(a + b) . This is prime if and only if a – b = 1 and a + b is a prime . Since a+b is at most 2×1012, we can use trial division to check its primality.
Below is the implementation of the above idea:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Check whether a number can be represented as difference of two squares
- Check whether the sum of absolute difference of adjacent digits is Prime or not
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Quick ways to check for Prime and find next Prime in Java
- Check if a prime number can be expressed as sum of two Prime Numbers
- Check whether the sum of prime elements of the array is prime or not
- Count all subarrays whose sum can be split as difference of squares of two Integers
- Check whether a number can be represented by sum of two squares
- Check if N can be represented as sum of squares of two consecutive integers
- Check if the sum of perfect squares in an array is divisible by x
- Check whether a number can be represented by the product of two squares
- Check if factorial of N is divisible by the sum of squares of first N natural numbers
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Sum of Areas of Rectangles possible for an array
- Absolute difference between the XOR of Non-Prime numbers and Prime numbers of an Array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : ihritik