Python:每日一题 146
本帖最后由 冬雪雪冬 于 2018-2-5 20:53 编辑我们的玩法做了一下改变:
1. 楼主不再提供答案。
2. 请大家先独立思考”,再参考其他鱼油的解答,这样才有助于自己编程水平的提高。
3. 鼓励大家积极答题,奖励的期限为出题后24小时内。
4. 根据答案的质量给予1~3鱼币的奖励。
题目:
6个连续的奇数乘积为135135,给出这6个连续的奇数中最小的数。 def result(i):
return i*(i+2)*(i+4)*(i+6)*(i+8)*(i+10)
i = 1
while True:
k = 2 * i - 1 # k = 2i-1则k为奇数
if result(k) == 135135:
break
else:
i += 1
print('这几个数是%d %d %d %d %d %d' % (k, k+2, k+4, k+6, k+8, k+10))
答案是:7、9、11、13、15、17
代码是:
n = 0
while n >= 0:
if (2*n+1)*(2*n+3)*(2*n+5)*(2*n+7)*(2*n+9) == 135135:
print(2*n+1)
break
else:
n += 1
for i in range(135135):
if i % 2 == 1:
if i*(i+2)*(i+4)*(i+6)*(i+8)*(i+10) == 135135:
print(i)
勿喷...初学者... >>> def x(y):
a = 1
while True:
if a * (a+2) * (a+4) * (a+6) * (a+8) * (a+10) == y:
break
else:
a += 1
print(a)
>>> x(135135)
3 ii = list()
for i in range(-1111,10000,2):
if i*(i+2)*(i+4)*(i+6)*(i+8)*(i+10) == 135135:
ii.append(i)
print(ii)
int(pow(135135,1/6)) - 4 def qishu(n):
sun = 1
list1 = []
x = 135135
for i in range(2,n):
if i % 2 == 1:
sun = sun * i
list1.append(i)
if x == sun:
print(list1)
print(min(list1))
break
number = int(input('请输入数字:'))
qishu(number)
#奇数
product = 0
answer = 135135
a = -1
while product != answer:
a += 2
product = a * (a+2) * (a+4) * (a+6) * (a+8) * (a+10)
print(a)
def find(n = 135135):
i = 1
while i <= n:
if i * (i + 2) * (i + 4) * (i + 6) * (i + 8) * (i + 10) == n:
break
else:
i += 2
return i
print(find(135135))
3 本帖最后由 8306最硬 于 2018-2-2 14:50 编辑
from math import floor
def fun(n):
return floor(pow(n, 1/6)) - 4
list1 =
for i in range(2,1000,2):
list1 = list1 + i
list1 = list1 + i
list1 = list1 + i
list1 = list1 + i
list1 = list1 + i
list1 = list1 + i
if list1 * list1 * list1 * list1 * list1 * list1 == 135135:
print(list1)
break
n=135135
list1=[]
lsit2=[]
for i in range(2,n):
if n%(2*i-1)==0:
list1.append(2*i-1)
for j in range (len(list1)-6):
if list1*list1*list1*list1*list1*list1==n:
print(list1)
本帖最后由 solomonxian 于 2018-2-2 18:41 编辑
简单粗暴的循环就可以,得到正奇数的答案3
def fun(n):
for i in range(1, int(n**(1/6))+1, 2):
if i * (i+2) * (i+4) * (i+6) * (i+8) * (i+10) == n:
return i
写得更像个函数
def fun2(product, num=6):
for i in range(1, int(product**(1/num))+1, 2):
result = 1
for j in range(i, i+2*num, 2):
result *= j
if result == product:
return i
用numpy求高次方程取实数根,能得到-13和3,不知道题目算不算负奇数
import numpy as np
def fun3(n):
roots = np.roots()
return roots.real
顺带画一画图吧{:10_333:}
import matplotlib.pyplot as plt
def fun4(n):
x = np.arange(-int(n**(1/6))-12, int(n**(1/6))+1)
temp = np.arange(0, 12, 2).reshape(-1, 1)
y = np.multiply.reduce(x + temp, axis=0)
fig, ax = plt.subplots()
ax.grid(True)
ax.axhline(n, c='red', label='y = %s'%n)
ax.plot(x, y, label='y = x*(x+2)*(x+4)*(x+6)*(x*8)*(x+10)')
plt.legend()
plt.show() for num1 in range(0,100):
num1 / 2 != 0
num2 = num1 + 2
num3 = num2 + 2
num4 = num3 + 2
num5 = num4 + 2
num6 = num5 + 2
if num1 * num2 *num3 *num4 * num5 * num6 == 135135:
print (num1)
初学者 帮忙看看呀 版主。{:9_228:} 本帖最后由 inverseli 于 2018-2-2 20:40 编辑
a = 1
for i in range(100000):
if (a+2)*(a+4)*(a+6)*(a+8)*(a+10)*a == 135135:
print(a)
break
a+=2
for i in range(10000):
if i*(i+2)*(i+4)*(i+6)*(i+8)*(i+10)==135135 and i%2:
print(i)
break
答案:3 def main():
n = 3
while True:
product = 1
result = []
for i in range(n, n+12, 2):
product *= i
result.append(i)
if product == 135135:
print(result)
break
else:
n += 2
if __name__ == '__main__':
main()
result: 本帖最后由 ouyunfu 于 2018-2-3 06:05 编辑
i = 1
while True:
if i*(i+2)*(i+4)*(i+6)*(i+8)*(i+10)==135135:
print(i)
break
else:
i = i + 2 for i in range(1,20,2):
if i * (i+2) * (i+4) * (i+6) * (i+8) * (i+10) == 135135:
print(''%i)
break
else:
print('在限定的范围内找不到答案!')
#6个连续奇数中最小的是3