zltzlt
发表于 2020-2-3 15:47:50
fan1993423 发表于 2020-2-3 15:47
sympy是第三方库吗?我以为是自带的库
{:10_277:}
fan1993423
发表于 2020-2-3 15:48:29
zltzlt 发表于 2020-2-3 15:47
另外我316那个递归的答案效率咋样,能否帮我测一下
William4869
发表于 2020-2-3 15:48:35
def f321(x):
num=1
for i in range(2,x//2+2):
if i%2:
if (x%i==0)and(x/i>=i//2+1):
num+=1
else:
if (x%(i/2)==0)and(x%i!=0)and(x//i>=i-1):
num+=1
return num
print(f321(8500000))
我又来了
William4869
发表于 2020-2-3 16:07:46
William4869 发表于 2020-2-3 15:48
def f321(x):
num=1
for i in range(2,x//2+2):
import math
def f321(x):
num=1
for i in range(2,int(math.sqrt(x))*2+1):
#for i in range(2,x//2+2):
if i%2:
if (x%i==0)and(x/i>=i//2+1):
num+=1
else:
if (x%(i/2)==0)and(x%i!=0)and(x//i>=i/2):
num+=1
return num
上一个不用测了,有点问题,再来
这样快一点,,但只测了几个,,不知道能不能过
546623863
发表于 2020-2-3 20:13:27
def fun321(n):
count = 1
i = 2
if n == 1 or n == 2:
return 1
if n == 3:
return 2
while (n/i) >= 2:
if i%2 == 0 and (n/i) % 1 == 0.5 and n/i-i/2 > 0:
count += 1
elif i%2 != 0 and (n/i) % 1 == 0 and n/i-i/2 > 0:
count += 1
i += 1
return count
为啥我今天才看到这题
TJBEST
发表于 2020-2-3 20:43:17
zltzlt 发表于 2020-2-3 14:53
解答错误
输入:15
修改完成,之前犯了个错误
import math
def fun321(n):
def split(n):
oushu = 1
jishu = 1
while n > 1:
if n % 2 ==0:
oushu = oushu * 2
n = n // 2
else:
break
jishu = n
return (jishu,oushu)
def yueshu(n):
res = []
index = 1
gate =math.floor(n ** (1/2))
while index <= gate:
if n % index == 0:
res.append(index)
res.append(n//index)
else:
pass
index += 1
if n % gate==0 and n//gate ==gate:
res.pop()
return res
maxGate = (2*n)**(1/2)
jishu,oushu = split(2*n)
jiyueshu = yueshu(jishu)
result = 0
for each in jiyueshu:
if each < maxGate:
result += 1
if oushu * each < maxGate:
result += 1
else:
pass
else:
pass
return result
ouyunfu
发表于 2020-2-4 00:01:44
from math import sqrt
n=int(input('请输入整数:'))
def function321(n):
L=[]
while 1:
for i in range(2,int(sqrt(n)+1)):
if n%i==0:
L.append(i)
n=int(n/i)
break
else:
L.append(n)
break
C={}
for i in L:
if i not in C:
C=1
else:
C+=1
L=1
for i in C.keys():
if i!=2:
L*=C+1
return L
print(function321(n))
zltzlt
发表于 2020-2-5 16:41:45
546623863 发表于 2020-2-3 20:13
为啥我今天才看到这题
输入 8500000 超时
776667
发表于 2020-8-15 12:41:35
def fun321(x):
result = []
for i in range(2,x):
if sum() > x:
break
for j in range(1,x-i+1):
if j*i+sum() == x:
result.append()
break
if j*i+sum() > x:
break
return result