当前位置:网站首页>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
边栏推荐
- 如何写Cover Letter?
- MySQL MHA high availability cluster
- STM32 single chip microcomputer - bit band operation
- Stm32--- systick timer
- My-basic application 1: introduction to my-basic parser
- C WinForm [realize the previous and next selection pictures] - practice 7
- 实例006:斐波那契数列
- Ble encryption details
- Hardware 1 -- relationship between gain and magnification
- Google sitemap files for rails Projects - Google sitemap files for rails projects
猜你喜欢
QEMU STM32 vscode debugging environment configuration
Stablq of linked list
Ble encryption details
Matlab2018b problem solving when installing embedded coder support package for stmicroelectronic
Negative pressure generation of buck-boost circuit
【三层架构及JDBC总结】
实例005:三数排序 输入三个整数x,y,z,请把这三个数由小到大输出。
[trio basic from introduction to mastery tutorial 20] trio calculates the arc center and radius through three points of spatial arc
C WinForm [change the position of the form after running] - Practical Exercise 4
Talk about the function of magnetic beads in circuits
随机推荐
Working principle and type selection of common mode inductor
Hardware 1 -- relationship between gain and magnification
Design a clock frequency division circuit that can be switched arbitrarily
Soem EtherCAT source code analysis I (data type definition)
实例004:这天第几天 输入某年某月某日,判断这一天是这一年的第几天?
STM32 --- NVIC interrupt
Bluebridge cup internet of things basic graphic tutorial - GPIO output control LD5 on and off
Charge pump boost principle - this article will give you a simple understanding
STM32 single chip microcomputer - external interrupt
Classic application of MOS transistor circuit design (2) - switch circuit design
Soem EtherCAT source code analysis attachment 1 (establishment of communication operation environment)
List of linked lists
Buildroot system for making raspberry pie cm3
实例008:九九乘法表
My-basic application 1: introduction to my-basic parser
Measurement fitting based on Halcon learning [II] meaure_ pin. Hdev routine
[trio basic tutorial 16 from introduction to proficiency] UDP communication test supplement
Cinq détails de conception du régulateur de tension linéaire
go依赖注入--google开源库wire
Explain task scheduling based on Cortex-M3 in detail (Part 1)