斐波那契数列,质素

# 列表构建斐波那契数列
def foo(num):
    foo = []
    a = 0
    b = 1
    for i in range(num):
        foo.append(b)
        a, b = b, a + b
    return foo

res = foo(10)
# print(res)
# 递归方式获取斐波那契数列
lis = []
for i in range(10):
    if i == 0 or i == 1:
        lis.append(1)
    else:
        lis.append(lis[i-2]+lis[i-1])
# print(lis)
# 获取2到100的质素(3,5,7,11,13)质素能被1和本身相除的数
data = []
for i in range(2, 100):
    for j in range(2, i):
        if i % j == 0:
            break
    else:
        data.append(i)
print(data)
# 水仙花数
153 = 1**3 + 5**3 + 3**3
import math
for i in range(100, 1000):
    x = math.floor(i / 100)
    y = math.floor((i - x * 100)/10)
    z = math.floor(i - (x*100 + y*10))
    k = x**3 + y**3 + z**3
    if i == k:
        print(i)
import random

def red_package(total, num):
    total = float(total)
    num = int(num)
    min = 0.01
    if num < 1:
        return
    if num == 1:
        print("第%d个人拿到红包金额为:%.2f", (num, total))
        return
    i = 1
    while i < num:
        max = total - min*(num-i)
        k = int((num-i)/2)
        if num - i <= 2:
            k = num - i
        max = max/k
        money = random.randint(int(min*100), int(max*100))
        money = float(money)/100
        total = total - money
        print("第%d个人拿到的红包数为:%.2f,余额为:%.2f" % (i, money, total))
        i += 1
    print("第%d个人拿到的红包数为:%.2f,余额为:%.2f" % (i, total, 0.0))


if __name__ == '__main__':
    total = input("输入红包的总金额:")
    num = input("输入红包的数量: ")
    red_package(total, num)

 

上一篇:nlogn LIS CF1437E


下一篇:D - Lis on Circle Gym - 102441D (LIS + 线段树)