
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Check if difference of areas of two squares is prime in Python
Suppose we have two numbers x and y. We have to check whether difference of their areas is prime or not.
So, if the input is like x = 7, y = 6, then the output will be True as the difference of their square is 49 - 36 = 13 which is prime.
To solve this, we will follow these steps −
- if (x + y) is prime number and (x - y) is 1, then
- return True
- otherwise,
- return False
Let us see the following implementation to get better understanding −
Example
def is_prime(num) : if num <= 1 : return False if num <= 3 : return True if num % 2 == 0 or num % 3 == 0 : return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i = i + 6 return True def solve(x, y): if is_prime(x + y) and x - y == 1: return True else: return False x, y = 7, 6 print(solve(x, y))
Input
7,6
Output
True
- Related Articles
- Sum of the areas of two squares is $400\ cm^2$. If the difference of their perimeters is 16 cm, find the sides of two squares.
- Sum of the areas of two squares is $640\ m^2$. If the difference of their perimeter is 64 m, find the sides of the two squares.
- Sum of the areas of two squares is 400 cm$^{2}$. If the difference of their perimeter is 16 cm, Find the sides of the two squares.
- Sum of the areas of two squares is $468\ m^2$. If the difference of their perimeters is 24 m, find the sides of the two squares.
- Check if a prime number can be expressed as sum of two Prime Numbers in Python
- Check if N is Strong Prime in Python
- Check if N is a Factorial Prime in Python
- Check if product of array containing prime numbers is a perfect square in Python
- Check whether the sum of absolute difference of adjacent digits is Prime or not in Python
- Check if a number is Primorial Prime or not in Python
- Check whether the sum of prime elements of the array is prime or not in Python
- Check if bitwise AND of any subset is power of two in Python
- Check if LCM of array elements is divisible by a prime number or not in Python
- Check if concatenation of two strings is balanced or not in Python
- Check if leaf traversal of two Binary Trees is same in Python

Advertisements