当前位置:网站首页>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
边栏推荐
- STM32 single chip microcomputer - external interrupt
- MySQL之MHA高可用集群
- C WinForm [change the position of the form after running] - Practical Exercise 4
- [NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)
- 实例001:数字组合 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
- Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
- 实例006:斐波那契数列
- STM32---IIC
- Installation and use of libjpeg and ligpng
- Basic information commands and functions of kernel development
猜你喜欢
FIO测试硬盘性能参数和实例详细总结(附源码)
Circleq of linked list
Some thoughts on extracting perspectives from ealfa and Ebeta
[NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)
H264 (I) i/p/b frame gop/idr/ and other parameters
Briefly talk about the identification protocol of mobile port -bc1.2
C WinForm [change the position of the form after running] - Practical Exercise 4
PMSM dead time compensation
OC and OD gate circuit
Halcon's practice based on shape template matching [1]
随机推荐
MySQL之MHA高可用集群
[tutorial 15 of trio basic from introduction to proficiency] trio free serial communication
Circleq of linked list
实例004:这天第几天 输入某年某月某日,判断这一天是这一年的第几天?
On boost circuit
Imx6ull bare metal development learning 1-assembly lit LED
[paper reading] the latest transfer ability in deep learning: a survey in 2022
Detailed explanation of SQL server stored procedures
实例001:数字组合 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
Why is 1900 not a leap year
实例010:给人看的时间
剑指 Offer 09. 用两个栈实现队列
Solutions to compilation warnings in Quartus II
Take you to understand the working principle of lithium battery protection board
Stm32--- systick timer
Measurement fitting based on Halcon learning [II] meaure_ pin. Hdev routine
Process communication mode between different hosts -- socket
Live555 push RTSP audio and video stream summary (III) flower screen problem caused by pushing H264 real-time stream
My-basic application 1: introduction to my-basic parser
The firmware of the connected j-link does not support the following memory access