当前位置:网站首页>实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
2022-07-05 08:16:00 【懒笑翻】
实例003:完全平方数
题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
程序分析:因为168对于指数爆炸来说实在太小了,所以可以直接省略数学分析,用最朴素的方法来获取上限,
n = 0
while (n + 1) ** 2 - n * n <= 168:
n += 1
print('----n=', n) # 可以得出范围是在(n+1)**2内
思路是:
最坏的结果是n的平方与(n+1)的平方刚好差168,由于是平方的关系,不可能存在比这更大的间隙。
设这个数是i (i+100)**0.5 (i+100+168)**0.5 则结果都是整数。
至于判断是否是完全平方数,最简单的方法是:平方根的值小数为0即可。
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的平方与(n+1)的平方刚好差168,不可能存在比这更大的间隙,我们据此先得出n
n = 0
while (n + 1) ** 2 - n * n <= 168:
n += 1
print('----n=', n) # 可以得出范围是在(n+1)**2内
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
因此该数可以是:-99 21 61 1581
边栏推荐
- Connection mode - bridge and net
- Explication de la procédure stockée pour SQL Server
- VESC Benjamin test motor parameters
- Step motor generates S-curve upper computer
- STM32 tutorial triple ADC interleaved sampling
- C WinForm [change the position of the form after running] - Practical Exercise 4
- Development tools -- gcc compiler usage
- [trio basic tutorial 17 from getting started to mastering] set up and connect the trio motion controller and input the activation code
- Programming knowledge -- basis of C language
- Several important parameters of LDO circuit design and type selection
猜你喜欢
Measurement fitting based on Halcon learning [II] meaure_ pin. Hdev routine
Wifi-802.11 negotiation rate table
Arduino uses nrf24l01+ communication
Negative pressure generation of buck-boost circuit
Class of color image processing based on Halcon learning_ ndim_ norm. hdev
Network port usage
After installing the new version of keil5 or upgrading the JLINK firmware, you will always be prompted about the firmware update
[paper reading] the latest transfer ability in deep learning: a survey in 2022
STM32 single chip microcomputer -- volatile keyword
UE像素流,来颗“减肥药”吧!
随机推荐
Soem EtherCAT source code analysis I (data type definition)
动力电池UL2580测试项目包括哪些
Measurement fitting based on Halcon learning [III] PM_ measure_ board. Hdev routine
Communication standard -- communication protocol
Array integration initialization (C language)
go依赖注入--google开源库wire
Factors affecting the quality of slip rings in production
Fundamentals of C language
STM32 single chip microcomputer - bit band operation
STM32 tutorial triple ADC interleaved sampling
Imx6ull bare metal development learning 2- use C language to light LED indicator
实例010:给人看的时间
Class of color image processing based on Halcon learning_ ndim_ norm. hdev
Live555 push RTSP audio and video stream summary (I) cross compilation
C WinForm [view status bar -- statusstrip] - Practice 2
Adaptive filter
STM32---IIC
Some tips for using source insight (solve the problem of selecting all)
Measurement fitting based on Halcon learning [i] fuse Hdev routine
Some thoughts on extracting perspectives from ealfa and Ebeta