西北工业大学cpSkill平台Python作业NOJ(41-50)

仅供参考
前20传送门:https://blog.csdn.net/weixin_43520256/article/details/109137288
21-30传送门:https://blog.csdn.net/weixin_43520256/article/details/109137366
51-60传送门:
https://blog.csdn.net/weixin_43520256/article/details/109365933

61-70传送门:https://blog.csdn.net/weixin_43520256/article/details/109137461
71-80传送门:https://blog.csdn.net/weixin_43520256/article/details/109137497
81-90传送门:https://blog.csdn.net/weixin_43520256/article/details/109137524
在这里插入图片描述

# # 41
# # 因数分解
# def fun(a, t=2):
#     count = 0
#     if a < t:
#         return count
#     else:
#         for i in range(t, int(a / 2) + 1):
#             if a % i == 0:
#                 temp = a // i
#                 if temp >= i:
#                     count += 1
#                     count += fun(temp, i)
#         return count
#
#
# num = int(input())
# print(fun(num) + 1)

在这里插入图片描述

# # 42
# # 有效运动
# def fun1(x, y):
#     return x + y, y
#
#
# def fun2(x, y):
#     return x, x + y
#
#
# l = input()
# x1, y1, x2, y2 = map(int, l.split())
# m1 = x1
# n1 = y1
# isTrue1 = False
# isTrue2 = False
# while m1 < x2 and n1 < y2:
#     if y2 < x2:
#         m1, n1 = fun2(m1, n1)
#         if n1 == y2:
#             isTrue1 = True
#             if m1 == x2:
#                 isTrue2 = True
#             else:
#                 while m1 < x2:
#                     m1, n1 = fun1(m1, n1)
#                 if m1 == x2:
#                     isTrue2 = True
#     else:
#         m1, n1 = fun1(m1, n1)
#         if m1 == x2:
#             isTrue1 = True
#             if n1 == y2:
#                 isTrue2 = True
#             else:
#                 while n1 < y2:
#                     m1, n1 = fun2(m1, n1)
#                 if n1 == y2:
#                     isTrue2 = True
# if isTrue1 and isTrue2:
#     print("true")
# else:
#     print("false")

在这里插入图片描述

# # 43
# # 卡塔兰数
# def fac(n):
#     if n == 1:
#         return 1
#     else:
#         return n * fac(n - 1)
#
#
# def fun(n):
#     ret = fac(2 * n) / (fac(n + 1) * fac(n))
#     return ret
#
#
# num = int(input())
# print(int(fun(num)))

在这里插入图片描述

# # 44
# # 扩展欧几里得算法
# def gcd(x, y):
#     i = x
#     while i > 1:
#         if x % i == 0 and y % i == 0:
#             return i
#         i -= 1
#     else:
#         return 1
#
#
# def fun(x, y):
#     t = gcd(x, y)
#     i = 0
#     j = 0
#     while True:
#         j = (t - x * i) // y
#         if t == x * i + y * j:
#             return i, j
#         i += 1
#
#
# x = input()
# a, b = map(int, x.split())
# ret1, ret2 = fun(a, b)
# print(ret1, ret2, sep=" ")

在这里插入图片描述

# # 45
# # 考拉兹猜想:每一个正整数,如果它是奇数,则对它乘3再加1,如果它是偶数,则对它除以2,如此循环,最终都能够得到1
# def fun(n):
#     l1 = [n]
#     while True:
#         if n == 1:
#             break
#         if n % 2 == 0:
#             n = n // 2
#             l1.append(n)
#         else:
#             n = 3 * n + 1
#             l1.append(n)
#     return l1
#
#
# num = int(input())
# l0 = fun(num)
# for i in range(0, len(l0) - 1):
#     print(l0[i], ",", sep="", end="")
# print(l0[-1], end="")

在这里插入图片描述

# # 46
# # 非负累加(重写)
#  可以过作业系统,但是并不是一个好代码
# def fun(num, val):
#     count = 0
#     t = 0
#     if num == 0 and t == val:
#         count += 1
#     else:
#         for i in range(0, val):
#             t += fun(num - 1, val)
#     return t
#
#
# x = input()
# n, v = map(int, x.split())
# count = 0
# for i in range(0, v + 1):
#     for ii in range(0, v + 1):
#         for iii in range(0, v + 1):
#             for iiii in range(0, v + 1):
#                 for iiiii in range(0, v + 1):
#                     if (i + ii + iii + iiii + iiiii) == v:
#                         count += 1
# print(count)

在这里插入图片描述

# # 47
# # 霍夫斯塔德序列
# def F(n):
#     if n == 0:
#         return 1
#     else:
#         ret = n - M(F(n - 1))
#         return ret
#
#
# def M(n):
#     if n == 0:
#         return 0
#     else:
#         ret = n - F(M(n - 1))
#         return ret
#
#
# num = int(input())
# if num >= 0:
#     f = F(num)
#     m = M(num)
#     print(f, m, sep=" ")

在这里插入图片描述

# # 48
# # 分苹果
# def fun(m, n):
#     if m == 0 or n == 1:  # 碟子为 1 或苹果为 0 则只有一种方法
#         return 1
#     if n > m:  # 碟子数量大于苹果
#         return fun(m, m)
#     else:
#         return fun(m, n - 1) + fun(m - n, n)
#
#
# x = input()
# M, N = map(int, x.split())
# if M >= 1 and N <= 10:
#     print(fun(M, N))

在这里插入图片描述

# # 49
# # 佩尔数
# def fun(n):
#     if n == 0:
#         return 0
#     elif n == 1:
#         return 1
#     else:
#         return 2 * fun(n - 1) + fun(n - 2)
#
#
# num = int(input())
# print(fun(num))

在这里插入图片描述

# # 50
# # 倒序二进制
# num = int(input())
# s = str(bin(num))
# l = []
# for i in range(0, len(s) - 2):
#     l.append(s[i + 2])
# l.reverse()
# for i in range(0, len(l)):
#     print(l[i], end="")

  • 6
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

枳洛淮南✘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值