# Python Classic Exercise 1: An integer, which plus 100 is a complete square number, plus 168 is a complete square number, what is the number?

Source: Internet
Author: User

Python Classic Exercises

The answers that can be searched online are:

```

for i in range(1,85):
if 168 % i == 0:
j = 168 / i;
if  i > j and (i + j) % 2 == 0 and (i - j) % 2 == 0 :
m = (i + j) / 2
n = (i - j) / 2
x = n * n - 100
print(x)

```

```-99
21
261
1581

```

But in fact, four figures are not in accordance with the conditions of +100 and +168, which are still the full square number;

The correct code is as follows:

```

import math
n = 0
count = 0
while True:
first = n + 100
second = n + 168
first_sqrt = int(math.sqrt(first))
second_sqrt = int(math.sqrt(second))
if (first_sqrt*first_sqrt == first) and (second_sqrt*second_sqrt == second):
print(n)
break
n = n + 1

```

The correct answer is only one:

```156
```

Python Classic Exercise 1: An integer, plus 100 is a complete square number, plus 168 is a complete square number, what is the number?

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.