当前位置:网站首页>Example 003: a complete square is an integer. It is a complete square after adding 100, and it is a complete square after adding 168. What is the number?

Example 003: a complete square is an integer. It is a complete square after adding 100, and it is a complete square after adding 168. What is the number?

2022-07-05 08:21:00 Lazy smile

example 003: Complete square

subject : An integer , It adds 100 And then there's a complete square , Plus 168 It's a complete square again , What is the number ?

  Program analysis : because 168 It's too small for an exponential explosion , Therefore, mathematical analysis can be omitted directly , Use the simplest way to get the upper limit ,

n = 0
while (n + 1) ** 2 - n * n <= 168:
    n += 1

print('----n=', n)  #  It can be concluded that the range is (n+1)**2 Inside 

The train of thought is :

The worst result is n The sum of the squares of (n+1) The square of is just the difference 168, Because it's Square , There can be no greater gap than this .

Let this number be i (i+100)**0.5 (i+100+168)**0.5 Then the results are all integers .

As for judging whether it is a complete square number , The easiest way is : The value of the square root is decimal 0 that will do .

for i in range((n + 1) ** 2):
    if i ** 0.5 == int(i ** 0.5) and (i + 168) ** 0.5 == int((i + 168) ** 0.5):
        print(i - 100)

The combination is :

#  The worst result is n The sum of the squares of (n+1) The square of is just the difference 168, There can be no greater gap than this , Based on this, we come to the conclusion that n
n = 0
while (n + 1) ** 2 - n * n <= 168:
    n += 1

print('----n=', n)  #  It can be concluded that the range is (n+1)**2 Inside 

for i in range((n + 1) ** 2):
    if i ** 0.5 == int(i ** 0.5) and (i + 168) ** 0.5 == int((i + 168) ** 0.5):
        print(i - 100)
------n= 84
-99
21
261
1581

Therefore, the number can be :-99 21 61 1581

 

原网站

版权声明
本文为[Lazy smile]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050816109960.html