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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Divide an isosceles triangle in two parts with ratio of areas as n:m
- Sum of Areas of Rectangles possible for an array
- Check whether a number can be represented as difference of two squares
- Check if a prime number can be expressed as sum of two Prime Numbers
- Check whether a number can be represented by sum of two squares
- Check whether a number can be represented by the product of two squares
- Check if N can be represented as sum of squares of two consecutive integers
- Count all subarrays whose sum can be split as difference of squares of two Integers
- Count elements in an Array that can be represented as difference of two perfect squares
- Find two numbers such that difference of their squares equal to N
- Subsets of size K with product equal to difference of two perfect squares
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Quick ways to check for Prime and find next Prime in Java
- Check whether the sum of prime elements of the array is prime or not
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the XOR of Non-Prime numbers and Prime numbers of an Array
- Number of perfect squares between two given numbers
- Check if the sum of perfect squares in an array is divisible by x
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