当前位置:网站首页>实例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

边栏推荐
- Verilog -- state machine coding method
- Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
- [tutorial 15 of trio basic from introduction to proficiency] trio free serial communication
- Arduino uses nrf24l01+ communication
- Nb-iot technical summary
- Improve lighting C program
- Tailq of linked list
- Gradle composite construction
- Class of color image processing based on Halcon learning_ ndim_ norm. hdev
- OC and OD gate circuit
猜你喜欢

Brief discussion on Buck buck circuit

Explain task scheduling based on Cortex-M3 in detail (Part 1)

Communication standard -- communication protocol
![[trio basic tutorial 16 from introduction to proficiency] UDP communication test supplement](/img/54/78e4e10724b2762274b06debb10877.jpg)
[trio basic tutorial 16 from introduction to proficiency] UDP communication test supplement

Development tools -- gcc compiler usage

Solutions to compilation warnings in Quartus II
![Measurement fitting based on Halcon learning [i] fuse Hdev routine](/img/91/34c92065e797c87d6ce5ea13903993.jpg)
Measurement fitting based on Halcon learning [i] fuse Hdev routine

Design a clock frequency division circuit that can be switched arbitrarily

PMSM dead time compensation

Soem EtherCAT source code analysis attachment 1 (establishment of communication operation environment)
随机推荐
Explication de la procédure stockée pour SQL Server
[tutorial 19 of trio basic from introduction to proficiency] detailed introduction of trio as a slave station connecting to the third-party bus (anybus PROFIBUS DP...)
Network communication process
H264 (I) i/p/b frame gop/idr/ and other parameters
More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!
Bluetooth hc-05 pairing process and precautions
Zero length array in GNU C
Compilation warning solution sorting in Quartus II
VESC Benjamin test motor parameters
Live555 push RTSP audio and video stream summary (I) cross compilation
Imx6ull bare metal development learning 2- use C language to light LED indicator
C#,数值计算(Numerical Recipes in C#),线性代数方程的求解,LU分解(LU Decomposition)源程序
Circleq of linked list
Buildroot system for making raspberry pie cm3
【云原生 | 从零开始学Kubernetes】三、Kubernetes集群管理工具kubectl
Class of color image processing based on Halcon learning_ ndim_ norm. hdev
Bootloader implementation of PIC MCU
STM32 outputs 1PPS with adjustable phase
Several implementation schemes of anti reverse connection protection of positive and negative poles of power supply!
C language enhancement -- pointer