Determine all possible pairs (p, q) of base ten positive integers that satisfy this system of equations:
- arithmetic mean (p, q) = 10x+y
- geometric mean (p, q) = 10y+x
where, each of p and q is a nonzero base ten integer, with p≠q, and each of x and y is a base ten digit.
(p,q) is either (32,98) or (98,32)
the arithmetic mean is 65
the geometric mean is 56
Not surprisingly, given that there is a theoremm about it: AM > GM
----------------------
def isprime(n):
'''check if integer n is a prime'''
n = abs(int(n))
if n < 2:
return False
if n == 2:
return True
if not n & 1:
return False
for x in range(3, int(n**0.5)+1, 2):
if n % x == 0:
return False
return True
squares = [i*i for i in range(10,100) if not isprime(i)]
for s in squares:
gm = int(s**.5)
for i in range(1,gm):
if (s/i)%1 == 0:
p = i
q = int(s/i)
x = gm%10
y = gm//10
if (p+q)/2 == 10*x + y:
print('(p,q) is either ({},{}) or ({},{})'.format(p,q,q,p))
print('the arithmetic mean is {}'.format(int((p+q)/2)))
print('the geometric mean is {}'.format(int((p*q)**.5)))
------ #alternate method, same result
for a in range(1,201):
for b in range(1,201):
if a == b:
continue
am = (a+b)/2
if am%1 != 0:
continue
if am > 99:
continue
gm = (a*b)**.5
if gm%1 != 0:
continue
am = int(am)
gm = int(gm)
y = am%10
x = am//10
if gm == 10*y + x:
print(a,b,am,gm)
Output:
32 98 65 56
98 32 65 56
|
Posted by Larry
on 2023-03-19 08:36:57 |