一、阶乘的和
#无法继续合成的阶乘和中最小的那个阶乘即为阶乘和的最大因数(提取公因式)
# Ai!的累加结果,A1! + A2! + ... + An!,A1 < A2 < ... < An,则A1!为最大公因数
# 考虑阶乘的合并情况:有(x+1) * y个x!,能合并为y个(x+1)!。即合成条件为x!的个数为x+1的倍数
# 使用map存储某个数x的阶乘出现的次数,若达到一定次数,则转换为x+1的阶乘
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
a.sort()
Map = defaultdict(int)
for x in a:
Map[x] += 1
x = a[0]
while True:
cnt = Map[x]
if cnt % (x + 1) == 0:
Map[x + 1] += cnt // (x + 1)
x += 1
else:
print(x)
break
二、确定字符串是否包含唯一字符
s = input()
s = s.lower()
a = []#创建列表,
for i in s:#通过遍历输入的字符串s,将每个字符添加到列表a中。如果遇到重复的字符,则输出"NO"并终止循环。
if i not in a:
a.append(i)# 将新字符追加到原字符串后面
else:
print("NO")
break
else:
print("YES")
三、确定字符串是否是另一个的排列
s1 = list(input())
s2 = list(input())
s1.sort()
s2.sort()
if s1 == s2:
print("YES")
else:
print("NO")
每天持续更新~
上一篇文章: 【一眼秒杀】三道蓝桥杯真题(三)-CSDN博客