In: Computer Science
Python
We say that a pair of positive integers ?,? is special if ? − ? = 10 and both ? and ? can be represented as a sum of two squares. For example, the pair (18,8) is special since 18 − 8 = 10, 18 = 3^2 + 3^2, and 8 = 2^2 + 2^2. Write a program that prints all special pairs (?,?) with 1 ≤ ?,? ≤ 100.
import math def sum_of_square(n): a, b = 0, 0 for i in range(1,n): remainder = n - i ** 2 if remainder < 0: return False if remainder>0 and remainder ** 0.5 == math.ceil(remainder ** 0.5): return True for y in range(1, 101): x = y + 10 if sum_of_square(x) and sum_of_square(y): print('({},{})'.format(x, y))