892427369 发表于 2018-7-17 14:57:31

for x in range(100000):
    if (x+100)**0.5%1 == 0 and (x+268)**0.5%1 == 0:
      print(x)

DavidCowboy 发表于 2018-7-31 17:27:34

count = 100000
while (count + 100) ** 0.5 != int((count + 100) ** 0.5) or (count + 268) ** 0.5 != int((count + 268) ** 0.5):
    count -= 1
print(count)

uilUVUBWP 发表于 2018-8-5 09:37:30

import math

for i in range(1000):
    a = math.sqrt(i+100)
    b = math.sqrt(i+268)
    if a*a == (i+100) and b*b == (i +268):
      print(i)

songmenghua 发表于 2018-8-11 14:22:01

import math
for i in range(10000):
    a = (i+100)**0.5
    b = (i+268)**0.5
    if int(a)==a and int(b)==b:
      print '该数为:', i

d2nte 发表于 2018-8-23 10:10:35

强行骚……

import math
import itertools
numbers = itertools.count(-100)
for number in numbers:
    a = math.sqrt(number + 100)
    b = math.sqrt(number + 268)
    if a == int(a) and b == int(b):
      print(number)

acgods 发表于 2018-8-23 11:23:27

from math import *
list1 = []
for number in range(0,10000):
    x = int(sqrt(number + 100))
    y = int(sqrt(number + 268))
    if (number + 100 == pow(x,2)) and (number + 268 == pow(y,2)):
      list1.append(number)
print(list1)


修改后的代码
list1 = []
for number in range(0,10000):
    if(sqrt(number + 100)%1 ==0) and (sqrt(number + 268)%1 ==0):   
      list1.append(number)
print(list1)

爱城 发表于 2018-8-26 18:11:23

新手·ing 发表于 2017-3-25 10:00
我的解答!

import math
for i in range(10000):
    a=math.sqrt(i+100)
    b=math.sqrt(i+268)
    c=int(a)
    d=int(b)
    if a*a==c*c and b*b==d*d:
      print(i)



较之答案,有些冗余

god圣锋 发表于 2018-9-3 14:14:53

本帖最后由 god圣锋 于 2018-9-3 14:18 编辑

import math

count = 0

for i in range(-100,10001):

    if math.sqrt(i+100)% 1 == 0.0 and math.sqrt(i+268)% 1 == 0.0:

      print(i,'\t',end = ' ')

      count += 1
      
      if not count %5:
            print('\n')

print('\n\n总共有%d个数\n' % count)

程序员的救赎 发表于 2018-9-4 19:18:50

冬雪雪冬 发表于 2017-3-25 10:33
我也写一个

问个问题,把len(list1) 写在前面用个变量代替的话,会不会更节约时间?即每次循环会不会重复计算len(list1)?

sxzpf 发表于 2018-9-4 21:03:20

import math
for i in range(-100,10001):
    if math.sqrt(i+100)%1==0 and math.sqrt(i+268)%1==0:
      print(i)

sxzpf 发表于 2018-9-4 21:28:44

import math
for i in range(-100,10005,1):
    a = int(math.sqrt(i+100))
    b = int(math.sqrt(i+268))
    if a * a == (i+100) and b * b == (i+268):
      print(i)

_玛莎_ 发表于 2018-9-14 15:45:22

import math
for i in range(10000):
    x = int(math.sqrt(i+100))
    y = int(math.sqrt(i+268))
    if x * x == (i+100) and y * y == (i+268):
      print(i)

_玛莎_ 发表于 2018-9-14 17:09:59

import math
for i in range(10000):
    x = int(math.sqrt(i+100))
    y = int(math.sqrt(i+268))
    if x * x == (i+100) and y * y == (i+268):
      print(i)

liujian973 发表于 2018-10-8 13:38:41

    number=1
    import math
    while True:
      if not math.sqrt(number+100)%1 and not math.sqrt(number+268)%1:
            print(number)
            if number>10000:break
      number +=1

Roc乘风 发表于 2018-10-14 21:59:45

一行的那位大神,思路真六

Roc乘风 发表于 2018-10-14 22:05:39

本帖最后由 Roc乘风 于 2018-10-14 22:06 编辑

pizzapasta 发表于 2017-4-11 08:28
import math

for x in range(10000):


请教,这个is_integer()是用来判断一个数字是否是整数吗?

百度没有搜到详细的 相关

zhangjk19841984 发表于 2018-10-18 15:11:48

import math
for a in range(100000):
    b=int(math.sqrt(a+100))
    c=int(math.sqrt(a+268))
    if b*b==a+100 and c*c==a+268:
      print(a)

葑纆 发表于 2018-10-23 13:08:23

import math

for x in range(10001):
    y1 = math.sqrt(x + 100)
    y2 = math.sqrt(x + 268)
    if y1 % int(y1) == 0 and y2 % int(y2) == 0:
      print(x)

I_love_fishc_tj 发表于 2018-10-27 14:14:43

from math import sqrt
def number():
    for i in range(-100,10000):
      if sqrt(i + 101)%1 == 0 and sqrt(i + 269)%1 == 0:
            print(i)

I_love_fishc_tj 发表于 2018-10-27 14:16:02

solomonxian 发表于 2017-4-19 18:38
整数%1得0, 小数会带尾巴

看到这个余1,才知道自己编写的时候,判断条件少了什么~感谢。
页: 1 2 3 4 [5] 6 7
查看完整版本: Python:每日一题 3