Question

In: Computer Science

Python We say that a pair of positive integers ?,? is special if ? − ?...

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.

Solutions

Expert Solution

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))


Related Solutions

Given an array A of n distinct real numbers, we say that a pair of numbers...
Given an array A of n distinct real numbers, we say that a pair of numbers i, j ∈ {0, . . . , n−1} form an inversion of A if i < j and A[i] > A[j]. Let inv(A) = {(i, j) | i < j and A[i] > A[j]}. Answer the following: (a) How small can the number of inversions be? Give an example of an array of length n with the smallest possible number of inversions. (b)...
Given an array A of n distinct numbers, we say that a pair of numbers i,...
Given an array A of n distinct numbers, we say that a pair of numbers i, j ∈ {0, . . . , n − 1} form an inversion of A if i < j and A[i] > A[j]. Let inv(A) = {(i, j) | i < j and A[i] > A[j]}. Define the Inversion problem as follows: • Input: an array A consisting of distinct numbers. • Output: the number of inversions of A, i.e. |inv(A)|. Answer the following:...
#Write a program in Python that given a list of positive integers, return another list where...
#Write a program in Python that given a list of positive integers, return another list where each element corresponds to the sum of the digits of the elements o#f the given list. #Example: # input # alist=[124, 5, 914, 21, 3421] # output # sum=[7, 5, 14, 3, 18]
We have an array A of size n. There are only positive integers in this array....
We have an array A of size n. There are only positive integers in this array. Note that the array may have integers that are not distinct, and it could be any array of positive integers in creation (I like the numbers found the decimal expansion of π for instance). When possible provide the exact complexity of the algorithm. If it’s not possible explain the O/Ω/Θ complexity. a. Design an efficient algorithm to find the maximum difference between any two...
We have an array A of size n. There are only positive integers in this array....
We have an array A of size n. There are only positive integers in this array. Note that the array may have integers that are not distinct, and it could be any array of positive integers in creation (I like the numbers found the decimal expansion of π for instance). When possible provide the exact complexity of the algorithm. If it’s not possible explain the O/Ω/Θ complexity. a. Design an efficient algorithm to find the maximum difference between any two...
1. We have an array A of size n. There are only positive integers in this...
1. We have an array A of size n. There are only positive integers in this array. Note that the array may have integers that are not distinct, and it could be any array of positive integers in creation (I like the numbers found the decimal expansion of π for instance). When possible provide the exact complexity of the algorithm. If it’s not possible explain the O/Ω/Θ complexity. Design an efficient algorithm to find the maximum difference between any two...
1. We have an array A of size n. There are only positive integers in this...
1. We have an array A of size n. There are only positive integers in this array. Note that the array may have integers that are not distinct, and it could be any array of positive integers in creation (I like the numbers found the decimal expansion of π for instance). When possible provide the exact complexity of the algorithm. If it’s not possible explain the O/Ω/Θ complexity. Design an efficient algorithm to find the maximum difference between any two...
Translate the following segment of Python into ARMv8 assembly. You may assume that two positive integers...
Translate the following segment of Python into ARMv8 assembly. You may assume that two positive integers a and b have already been stored in registers X0 and X1. , which should have the correct end values for a and b at the end of the code. while a != b: if a>b: a = a - b else: b = b - a Note: Labels must be on their own line, and all programs must start with the label main:...
Let a and b be integers. Recall that a pair of Bezout coefficients for a and...
Let a and b be integers. Recall that a pair of Bezout coefficients for a and b is a pair of integers m, n ∈ Z such that ma + nb = (a, b). Prove that, for any fixed pair of integers a and b, there are infinitely many pairs of Bezout coefficients.
Now we need to develop a recursive algorithm for multiplication operation with two positive integers without...
Now we need to develop a recursive algorithm for multiplication operation with two positive integers without using the multiplication operator. Your answer should be in pseudocode or Java code format. Then use the Three-Question Approach to verify your recursive algorithm. No coding is required for this assignment 1. The Base-Case Question Is   there   a   nonrecursive   way   out   of   the   algorithm,   and   does   the   algorithm   work   correctly   for   this   base   case? 2. The Smaller-Caller Question Does   each   recursive   call   to   the  ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT