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:
- Check whether the sum of absolute difference of adjacent digits is Prime or not
- 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
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Check whether a number can be represented by sum of two squares
- Check if the sum of perfect squares in an array is divisible by x
- Check if factorial of N is divisible by the sum of squares of first N natural numbers
- Absolute difference between the XOR of Non-Prime numbers and Prime numbers of an Array
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Sum of Areas of Rectangles possible for an array
- Co-prime pair with given sum minimum difference
- Divide an isosceles triangle in two parts with ratio of areas as n:m
- Queries for maximum difference between prime numbers in given ranges
- Minimum absolute difference of a number and its closest prime
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