Python exercises 003: Total square number

Source: Internet
Author: User
Tags square root

"python Exercise 003" an integer, which plus 100 is a complete square number, plus 168 is a complete square number, how much is this number?


The so-called "total square number", that is, open the root of the root is still an integer.

The math slag is thinking this way: suppose the number i is within 10000. First step: x = sqrt (i+100). if x = = Floor (x), It proves that X is an integer. The second step is the same, but remember to restore the square root x**2, plus 168, and then open the square root, get y, and then determine whether it is an integer. After these two judgments, all can be passed, then the whole number is Asked.

1 ImportMath2 3  forIinchRange (10000):4x = math.sqrt (i + 100))5     ifx = =Math.floor (x):6y = math.sqrt (x**2 + 168)7         ify = =Math.floor (y):8             Print(i)9              break

The answer is 21, good small integer ah ...

Python exercise 003: Total square number

Contact Us

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: 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.